Home >Database >Mysql Tutorial >mysql password after installation
MySQL is an open source relational database management system that is widely used in application development, data analysis, business intelligence and other fields. After installing MySQL, set a secure password to protect the security of the database.
In this article, we will introduce how to install MySQL and how to set a password after installation.
Step one: Download and install MySQL
Step 2: Set the root password of MySQL
Open the terminal (command line under Windows) and log in to MySQL with root privileges. Enter the following command to enter MySQL:
$ mysql -u root -p
You need to enter an empty password when logging in for the first time, just press Enter.
Set the password for the root user
In the MySQL command line, enter the following command:
mysql> SET PASSWORD FOR 'root'@'localhost ' = PASSWORD('new_password_here');
Among them, "new_password_here" is the password you want to set. Note that the password must contain numbers, uppercase and lowercase letters, and special characters, and be no less than 8 characters in length.
If you cannot change the password due to permission issues, you can enter the following command first:
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('new_password_here') WHERE user = 'root' AND host = 'localhost';
mysql> FLUSH PRIVILEGES;
Then enter the previous command to successfully change the password.
Exit MySQL
Enter the following command to exit the MySQL command line:
mysql> exit
If you need to enter MySQL later, you can Use the following command:
$ mysql -u root -p
Then enter the password you set.
Summary:
After installing MySQL, we need to set a secure root user password to ensure the security of the database. This password can be changed from the MySQL command line. Please ensure that the password you set is secure enough and do not leak it to others.
The above is the detailed content of mysql password after installation. For more information, please follow other related articles on the PHP Chinese website!