mysql with the /go/mysql Command

/go/mysql manages the MariaDB databases that belong to GoAdmio hosting accounts. It has four modes: The index lists this command as "Create a MySQL database". The command also edits and deletes databases. Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.

Quick start

# Create the database shop_db with user shop_user for the account example.com
/go/mysql example.com shop_db shop_user 'S3cureP4ssw0rd'

Arguments

# Argument Used by Notes
1 domain All modes An existing GoAdmio account. The literal word system selects System mode.
2 database All modes The database name. Not root, go, mysql, horde, or roundcube.
3 user Create, edit The database user. Not root, go, mysql, horde, or roundcube.
4 password Create, edit The user’s password. See Security.
5 remote Create, edit 1 lets the user connect from any host. Anything else, or empty, means local-only.
6 action All modes delete or edit. Empty, or any other value, means create.

Use plain names (letters, numbers, and underscores) for the database and user. The command does not add the account name as a prefix and does not validate names beyond the reserved list. The values are inserted into SQL and shell commands without quoting, so avoid quotes, spaces, and shell special characters, including in the password.

Examples

# Create a database with local-only access
/go/mysql example.com shop_db shop_user 'S3cureP4ssw0rd'

# Create a database whose user can connect from any host
/go/mysql example.com shop_db shop_user 'S3cureP4ssw0rd' 1

# Change the password only (pass the existing user name)
/go/mysql example.com shop_db shop_user 'N3wP4ssw0rd' "" edit

# Switch the user to remote access
/go/mysql example.com shop_db shop_user 'N3wP4ssw0rd' 1 edit

# Delete a database (user and password arguments are ignored)
/go/mysql example.com shop_db "" "" "" delete

# Set up GoAdmio's internal MariaDB instance
/go/mysql system

# Verify the result
mariadb -e 'SHOW DATABASES;'
mariadb -e "SHOW GRANTS FOR 'shop_user'@'localhost';"

Output

Mode Outcome Message
Create Success Database '<name>' created successfully., then the connection details.
Edit Success Database '<name>' was successfully modified.
Delete Success Database <name> deleted successfully...
Delete No match Nothing is printed.
Any Validation failure A MYSQL: ... message and exit status 1. See Validation.
Any No arguments No output, exit status 1.
system Finished mariadb --port=3307 and exit status 1.

The connection details printed after a create look like this:

Database 'shop_db' created successfully.

MySQL Hostname: localhost
MySQL Database Name: shop_db
MySQL Database Username: shop_user
MySQL Database Password: S3cureP4ssw0rd

With remote set to 1, the hostname is the server’s public IPv4 address, taken from checkip.amazonaws.com. If that lookup fails, the hostname is blank. The address may differ from the one clients use, for example behind NAT.

[!WARNING]
The success messages are printed whether or not the MariaDB commands worked. The command does not check the result of the SQL it runs, so a success message does not prove the database or user exists. Check with mariadb -e 'SHOW DATABASES;'.

Security

[!WARNING]

  • The password appears in plain text in the command’s output, and is stored in plain text in GoAdmio’s database records (/var/lib/sqlite/mysql.db).
  • The password is passed as a command-line argument, so it can be visible in the process list and saved in your shell history.
  • The MariaDB root password is passed on the command line to mariadb, so it is briefly visible in the process list while each SQL command runs.
  • The log hides the password.

See the full reference at /go/mysql and the GoAdmio command index.

GoAdmio is free and open source, with no license fees and no account limits. Read the GoAdmio docs, or see why it is a free cPanel alternative at goadmio.com.

By:

Posted in:


Leave a Reply

Your email address will not be published. Required fields are marked *