Home > System Tutorial > LINUX > body text

Easily change the Root password of MySQL/MariaDB under Linux

PHPz
Release: 2024-02-05 16:24:03
forward
1195 people have browsed it

If you are installing MySQL or MariaDB for the first time, you can run the mysql_secure_installation script to perform basic security settings. One of the settings is about the root password of the database. This password must be kept secret and only used when necessary. If you need to modify it (for example, when the database administrator changes, or gets fired!), you can do so via this script as well.

Please execute the script mysql_secure_installation to implement these security settings.

Easily change the Root password of MySQL/MariaDB under Linux

Change the root password of MySQL or MariaDB

You know the root password, but want to reset it, for this case, let's 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
Easily 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 in a stopped state, and you need to start the database service before proceeding to the next step:

------------- 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

In order to be compatible with different versions, we will use the following statement to update the user table of the mysql database. Note that you need to replace YourPasswordHere with the new password you choose for root.

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.

Easily change the Root password of MySQL/MariaDB under Linux

Modify MysQL/MariaDB Root password

summary

In this article, we explain how to change the root password of MariaDB / MySQL - maybe you know the method we are talking about, or maybe you don't.

As usual, if you have any questions or feedback, please feel free to use the comment box below to leave your valuable comments or suggestions. We look forward to your messages.

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

source:lxlinux.net
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!