MCPcopy Create free account
hub / github.com/Scalingo/cli / MySQLConsole

Function MySQLConsole

db/mysql_console.go:18–45  ·  view source on GitHub ↗
(ctx context.Context, opts MySQLConsoleOpts)

Source from the content-addressed store, hash-verified

16}
17
18func 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}

Callers 1

mysql.goFile · 0.92

Calls 2

RunFunction · 0.92
dbURLFunction · 0.85

Tested by

no test coverage detected