| 16 | } |
| 17 | |
| 18 | func MySQLConsole(ctx context.Context, opts MySQLConsoleOpts) error { |
| 19 | if opts.VariableName == "" { |
| 20 | opts.VariableName = "SCALINGO_MYSQL" |
| 21 | } |
| 22 | mySQLURL, user, password, err := dbURL(ctx, opts.App, opts.VariableName, []string{"mysql", "mysql2"}) |
| 23 | if err != nil { |
| 24 | return errors.Wrapf(ctx, err, "resolve MySQL URL from %s", opts.VariableName) |
| 25 | } |
| 26 | |
| 27 | host, port, err := net.SplitHostPort(mySQLURL.Host) |
| 28 | if err != nil { |
| 29 | return errors.Newf(ctx, "%v has an invalid host", mySQLURL) |
| 30 | } |
| 31 | |
| 32 | runOpts := apps.RunOpts{ |
| 33 | DisplayCmd: "mysql-console " + user, |
| 34 | App: opts.App, |
| 35 | Cmd: []string{"dbclient-fetcher", "mysql", "&&", "mysql", "-h", host, "-P", port, fmt.Sprintf("--password=%v", password), "-u", user, user}, |
| 36 | Size: opts.Size, |
| 37 | } |
| 38 | |
| 39 | err = apps.Run(ctx, runOpts) |
| 40 | if err != nil { |
| 41 | return errors.Newf(ctx, "fail to run MySQL console: %v", err) |
| 42 | } |
| 43 | |
| 44 | return nil |
| 45 | } |