Skip to content

Instantly share code, notes, and snippets.

@clemlesne
Created December 19, 2017 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clemlesne/804e26c1ff06184dc04328b39b20cc87 to your computer and use it in GitHub Desktop.
Save clemlesne/804e26c1ff06184dc04328b39b20cc87 to your computer and use it in GitHub Desktop.
Change root password with MariaDB
To begin, stop the database service and check the service status:
------------- SystemD -------------
# systemctl stop mariadb
------------- SysVinit -------------
# /etc/init.d/mysqld stop
Next, start the service with --skip-grant-tables:
------------- SystemD -------------
# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
# systemctl start mariadb
# systemctl status mariadb
------------- SysVinit -------------
# mysqld_safe --skip-grant-tables &
This will allow you to connect to the database server as root without a password (you may need to switch to a different terminal to do so):
# mysql -u root
From then on, follow the steps outlined below.
MariaDB [(none)]> USE mysql;
MariaDB [(none)]> UPDATE user SET password=PASSWORD('YourNewPasswordHere') WHERE User='root' AND Host = 'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
Finally, stop the service, unset the environment variable and start the service once again:
------------- SystemD -------------
# systemctl stop mariadb
# systemctl unset-environment MYSQLD_OPTS
# systemctl start mariadb
------------- SysVinit -------------
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
This will cause the previous changes to take effect, allowing you to connect to the database server using the new password.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment