GoAdmio

mysqlreset

Reset a lost MariaDB root password by restarting the database in safe mode, then update GoAdmio's config.php and /root/.my.cnf to match

On this page: Overview · Quick start · Syntax · Arguments · Output · Examples · Troubleshooting · Details · See also


Overview

/go/mysqlreset sets a new MariaDB root password without needing the old one. Use it when the current password is lost, or when the normal change with mysqlset does not work. It:

[!WARNING] All databases are unavailable while this runs, so every site that uses a database is affected for several seconds. Run it during a quiet period.

[!WARNING] The command does not check that the password change worked. It prints a success message and updates config.php and /root/.my.cnf either way, so a failed reset can leave GoAdmio with a password that MariaDB does not accept. Always run the check in Examples afterwards.


Quick start

# Set a new root password
/go/mysqlreset 'N3wRootPassw0rd'

Syntax

/go/mysqlreset <password>

Run the command as root. Running it with no argument exits silently with status 1.


Arguments

Position Name Required Notes
1 <password> Yes The new MariaDB root password. Use letters and digits only. See Special characters.

The command does not check the password's length or strength.


Output

On a normal run, one line is printed, whether or not the reset worked:

MySQL ROOT password has been changed successfully.

Everything else the safe-mode server prints is saved to a file named res in the folder you ran the command from.

Situation Exit code
No argument 1, no message
Any other run 0

Security

[!WARNING] The new password is stored in plain text in /usr/local/goadmio/include/config/config.php and in /root/.my.cnf. Passing it as an argument also leaves it in your shell history and briefly in the process list.

The command log, /var/log/go/mysqlreset.log, records only ******** instead of the password. While the safe-mode server is running, anyone with a local login on the server can use the databases without a password. Network connections are disabled during that time.


Examples

# Reset the root password
/go/mysqlreset 'N3wRootPassw0rd'
# Check that the new password works
mariadb -uroot -p'N3wRootPassw0rd' -e "SELECT 1;"
# Check what was written to GoAdmio's configuration
grep DBPass /usr/local/goadmio/include/config/config.php
# Remove the leftover safe-mode output file
rm -f res

Troubleshooting

Symptom Likely cause Fix
Nothing happens, exit code 1 No password was given. Pass the new password as the argument.
The success message appears but mariadb -uroot -p... says Access denied The password change did not run. The safe-mode server may not have been ready after the fixed 5-second wait, or the password contains special characters. Run the command again with a letters-and-digits password.
GoAdmio or sites show database connection errors afterwards config.php holds a password that MariaDB does not accept. Check with the commands in Examples, then run again, or correct the value with config.
MariaDB is not running afterwards The restart began before the safe-mode server had fully stopped. Run systemctl restart mariadb, then check systemctl status mariadb.
sed: unterminated 's' command, and config.php is not updated The password contains /, &, or \, or config.php has more than one line containing DBPass. Use a simpler password, and check the file by hand.
A file named res appeared It holds the safe-mode server's output. Delete it.
Sites were unavailable for a short time MariaDB is stopped during the reset. This is expected.

Details

Special characters

The password is placed inside a shell command, an SQL statement, and a sed replacement, and none of them escape it. A single quote ('), double quote, backtick, $, \, /, or & can break one of them. Use letters and digits only. Quote the argument on the command line, as in the examples.

What gets updated

What Change
MariaDB The password of root@localhost is replaced. Other root accounts, for other hosts, are not changed.
/usr/local/goadmio/include/config/config.php The line containing DBPass is replaced with $DBPass="<password>";.
/root/.my.cnf Recreated with user=root and the new password, so the mariadb client run as root logs in without asking.

/root/.my.cnf is created with default permissions, so check that only root can read it (chmod 600 /root/.my.cnf).

Difference from mysqlset

mysqlset changes the root password through a normal login. mysqlreset is the recovery option: it works without the old password, but it stops the database to do so.

What it does

flowchart TD
    A["mysqlreset password"] --> B{"Argument given?"}
    B -- "No" --> X["Exit 1"]
    B -- "Yes" --> C["Delete /root/.my.cnf"]
    C --> D["Stop MariaDB, kill leftover processes"]
    D --> E["Start in safe mode, wait 5 seconds"]
    E --> F["Set the root password"]
    F --> G["Stop the safe-mode server"]
    G --> H["Restart MariaDB normally"]
    H --> I["Print success message"]
    I --> J["Update config.php and /root/.my.cnf"]
  1. Appends the command to /var/log/go/mysqlreset.log, with the password hidden.
  2. Exits with status 1 if there is no argument.
  3. Deletes /root/.my.cnf.
  4. Stops the mariadb service, then force-kills any remaining mysqld and mariadbd processes.
  5. Starts mariadbd-safe with --skip-grant-tables --skip-networking in the background, with its output going to res, and waits 5 seconds.
  6. Sets the password of root@localhost.
  7. Stops the safe-mode server, using the process IDs in /var/run/mysqld/mysqld.pid, /var/run/mariadb/mariadb.pid, and any .pid file in /var/lib/mysql.
  8. Restarts the mariadb service.
  9. Prints the success message.
  10. Replaces the DBPass line in config.php.
  11. Recreates /root/.my.cnf.

See also

Command Description
mysqlset Change the MySQL root password
config Create GoAdmio's config.php, which stores the database and SSH login settings
mysql Create, edit, or delete a MySQL/MariaDB database and user for a hosting account
installmariadb Install or upgrade MariaDB from the official repositories
repair Repair the tables of one MySQL/MariaDB database, or of all databases
root Change the GoAdmio root password