GoAdmio

mysqlreset

Reset the MariaDB root password when the current one is lost, by restarting the database without password checks, setting a new password, and updating GoAdmio's config.php and /root/.my.cnf

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


Overview

Use /go/mysqlreset when you have lost the MariaDB root password and need to set a new one. It stops the database, starts it again in a special mode that skips the password check, sets the new password, and then starts it normally again. It also saves the new password where GoAdmio and the root user expect to find it.

If you still know the current root password, use mysqlset, which does not stop the database.

[!WARNING] All databases are offline while this runs, so every website that uses a database shows an error until it finishes. Expect it to take at least 10 to 20 seconds, and longer for big databases. The database server is also stopped with kill -9.

[!WARNING] For a few seconds, any user on the server can log in to MariaDB as root without a password. The database is not reachable from the network in this mode, but it is reachable from the server itself. Run this when you can accept that.


Quick start

/go/mysqlreset 'NewStr0ngPassw0rd'

Use a password made of letters and numbers only. See Arguments.


Syntax

/go/mysqlreset <new-password>

Run the command as root. The call is written to /var/log/go/mysqlreset.log, but the password is replaced by ******** in that log.


Arguments

Position Argument Required Notes
1 <new-password> Yes The new MariaDB root password. Without it, the command stops with exit status 1 and prints nothing.

The password goes unchanged into a SQL command, a sed command, a PHP file, and a settings file. Characters such as ', ", \, $, /, and & can break one of these steps, which can leave GoAdmio with a password that doesn't match the database. Use letters and numbers.

The password is part of the command line, so it can appear in the process list and in your shell history for a short time.


Output

MySQL ROOT password has been changed successfully.

This line is printed every time, even if the password was not changed. Test it yourself:

mariadb -u root -p -e "select 1"

Examples

# Reset the root password
/go/mysqlreset 'NewStr0ngPassw0rd'
# Check that the new password works
mariadb -u root -p -e "select 1"
# Check that GoAdmio's configuration has the same password
sudo grep DBPass /usr/local/goadmio/include/config/config.php
# Check that MariaDB is running normally
systemctl status mariadb

Troubleshooting

Symptom Likely cause Fix
Nothing happens and nothing is printed No password was given. Pass the new password.
The success message is shown, but the password did not change MariaDB was not ready within the fixed 5-second wait, for example after a hard stop on a big database. Run the command again.
Websites show a database error afterwards The password in config.php doesn't match the database, because of a special character, or because the file edit failed. Run it again with a letters-and-numbers password, and check the DBPass line.
MariaDB does not start after the command The temporary instance was still shutting down when the normal start began. Wait a minute, then run systemctl restart mariadb. Check systemctl status mariadb.
mariadbd-safe: command not found An older MariaDB version, where the program has another name. Install a current MariaDB, or run the steps by hand with mysqld_safe.
A file named res appeared in the folder you ran it from The startup messages of the temporary instance are saved there. Delete it.
sudo mariadb now asks for a password, or fails Root now logs in with a password and not through the operating system. Use /root/.my.cnf, which the command rewrites, or mariadb -u root -p.

Details

What it does

  1. Records the call in /var/log/go/mysqlreset.log, with the password hidden. With no password, it stops with status 1.
  2. Deletes the old /root/.my.cnf.
  3. Stops MariaDB, then force-kills any mysqld or mariadbd process with kill -9.
  4. Starts mariadbd-safe --skip-grant-tables --skip-networking in the background, with its output going to a file named res in the current folder, and waits 5 seconds.
  5. Sets the root password for root@localhost.
  6. Stops the temporary instance: it kills the process IDs found in the MariaDB pid files and in /var/lib/mysql/*.pid.
  7. Starts MariaDB normally with systemctl restart mariadb.
  8. Prints the confirmation.
  9. Replaces the DBPass line in /usr/local/goadmio/include/config/config.php with the new password.
  10. Writes a new /root/.my.cnf with the user root and the new password.
flowchart TD
    A["mysqlreset password"] --> B["Delete /root/.my.cnf"]
    B --> C["Stop MariaDB, kill -9 leftovers"]
    C --> D["Start with --skip-grant-tables --skip-networking, wait 5 s"]
    D --> E["Set root password"]
    E --> F["Stop the temporary instance"]
    F --> G["Start MariaDB normally"]
    G --> H["Update config.php and /root/.my.cnf"]

What changes

Item Change
MariaDB root password (root@localhost) Set to the new password. Root then signs in with a password.
/root/.my.cnf Replaced. It holds the new password in plain text. Other GoAdmio commands that run mariadb as root, such as roundcube and speedtest, use it to sign in.
config.php The DBPass line holds the new password.
Running databases Stopped, then started again.
res A new file in the folder you ran it from.

Risks


See also

Command Description
mysqlset Change the MySQL root password
mysqlbackup Back up MariaDB/MySQL to a remote server via rsync
my Regenerate the MariaDB configuration file with settings tuned to the server
repair Repair the tables of one MySQL/MariaDB database, or of all databases
installmariadb Install or upgrade MariaDB
mysql Create, edit, or delete a MySQL/MariaDB database and user for a hosting account
heal Monitor key services, memory, load, and disk, and automatically fix problems