Mysql database is a popular relational database management system that provides a complete SQL support and can be integrated with many programming languages and tools. When developing and managing databases, it is often necessary to change the password of the root user. This article will introduce you to some simple steps to change the Mysql database root password on Linux and Windows systems.
1. Change the Mysql database root password on Linux system
Step 1: Connect to your server via SSH. You can use your favorite terminal tools. Enter the following command in the terminal to connect to your server:
ssh username@server_ip_address
Note: The "username" above should be the username of your server, and "server_ip_address" should be the IP address of your server.
Step 2: Connect to Mysql database. Enter the following command in the terminal to connect to the Mysql database:
mysql -u root -p
Note: After entering the command, you will be asked to enter the Mysql root user password. If you haven't set a password yet, skip this step and just press Enter.
Step 3: Use the following command to change the root password of the Mysql database:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Note: Please replace "new_password" with the new password you need to change.
After the above steps are completed, you should receive an output indicating that you have successfully changed your password.
2. Change the Mysql database root password on Windows system
Step 1: Open the Mysql command line interface. Click on the Windows button and start typing "CMD" to open a command prompt window on Windows operating system. In the window, enter the following command to open the command line interface of Mysql:
mysql -u root -p
Note: After entering the command, you will be asked to enter the Mysql root user password. If you haven't set a password yet, skip this step and just press Enter.
Step 2: Use the following command to change the root password of the Mysql database:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Note: Please replace "new_password" with the new password you need to change.
After the above steps are completed, you should receive an output indicating that you have successfully changed your password.
Summary
Changing the Mysql database root password on Linux and Windows systems is very simple. If you have forgotten the current user's password, or want to add more users to access your database, please visit Mysql's official documentation website for more information and explore more knowledge about Mysql database. I wish you success!
The above is the detailed content of How to change root password in mysql. For more information, please follow other related articles on the PHP Chinese website!