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
Release: 2023-06-03 11:32:12
forward
938 people have browsed it

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
Copy after login
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
Copy after login

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

# mysql -u root -p
Copy after login

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;
Copy after login

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

MariaDB [(none)]> exit;
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template