When you installed Mysql on the machine for the first time, you can access the database anonymously or enter the database as a root without a password. in addition, if you are an administrator, you need to establish and authorize some users, which also involves setting passwords. next we will discuss how to set a password:
First, we should know that password storage in the Mysql database must be encrypted using the password () function. because the user table stores passwords in encrypted form, rather than plain text. if you are not encrypted, execute the following statement in the database:
Copy codeThe Code is as follows: use mysql
Insert into user (host, user, password) values ('%', 'user _ name', 'Your password ');
Flush privileges;
I believe the results will not satisfy you. because the server compares the encrypted value, the server connection may fail. note that flush privileges is used to reload the authorization table. you can also use mysqladmin-u root reload or mysqladmin-u root flush-privileges in shell to implement the reload authorization table.
In the Mysql environment, you can use the following statement to set the password:Copy codeThe Code is as follows: 1. insert into user (host, user, password) values ('%', 'user _ name', password ("your password ");
2. set password for user_name = password ("your password ")
The above two methods must be used to reload the authorization table.
3. Of course, you can set a password when creating a user. The grant statement will automatically encrypt the password for you.
For example
Grant all on *. * to user_name @ % identified by "your password ";
In addition, you can use the mysqladmin program in the shell environment to set the password.
For example
Mysqladmin-u root password "your password"
Hurry up and have a try. No problem!
How to set a password for mysql
There are many methods:
1. After Entering mysql with root
Mysql> set password = password ('your password ');
Mysql> flush privileges;
2. Use the GRANT statement
Mysql> grant all on *. * to 'root' @ 'localhost' identified by 'your password' with grant option; www.2cto.com
Mysql> flush privileges;
3. Go to the mysql database to modify the user table
Mysql> use mysql;
Mysql> update user set password = password ('your password') where user = 'root ';
Mysql> flush privileges;
Author matthio