Home >Database >Mysql Tutorial >How to change the Root password of MySQL/MariaDB under Linux

How to change the Root password of MySQL/MariaDB under Linux

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBforward
2023-06-03 11:32:12934browse

Change the root password of MySQL or MariaDB

You know the root password, but want to reset it. For such a situation, let us first make sure MariaDB is running:

------------- CentOS/RHEL 7 and Fedora 22+ -------------# systemctl is-active mariadb------------- CentOS/RHEL 6 and Fedora -------------# /etc/init.d/mysqld status
How to change the Root password of MySQL/MariaDB under Linux

Check MysQL status

If there is no active keyword in the above command return, then the service is stopped and you need to proceed to the next step Start the database service before:

------------- CentOS/RHEL 7 and Fedora 22+ -------------# systemctl start mariadb------------- CentOS/RHEL 6 and Fedora -------------# /etc/init.d/mysqld start

Next, we will log in to the database server as root:

# mysql -u root -p

To ensure compatibility, we will use the following statement to update the user table of the MySQL database. Please replace "YourPasswordHere" with your new password for the root account.

MariaDB [(none)]> USE mysql;
MariaDB [(none)]> UPDATE user SET password=PASSWORD('YourPasswordHere') WHERE User='root' AND Host = 'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;

To verify that the operation was successful, enter the following command to exit the current MariaDB session.

MariaDB [(none)]> exit;

Then hit Enter. You should now be able to connect to the server using your new password.

How to change the Root password of MySQL/MariaDB under Linux

The above is the detailed content of How to change the Root password of MySQL/MariaDB under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete