Multiple ways to set a user's password in mysql

  • 2020-05-13 03:40:17
  • OfStack

When you first install Mysql on the machine, you can access the database anonymously or enter the database as root without password.
First of all, we should know that the password store in Mysql database must be encrypted with the password() function, because the password is stored in the user table in encrypted form, not as plain text.
 
use mysql 
insert into user (host,user,password) values('%','user_name','your password'); 
flush privileges; 

I'm sure you won't be satisfied with the result. Because the server is comparing encrypted values, the server connection 1 must have failed. This command reloads the authorization table. You can also reload the authorization table using mysqladmin-u root reload or mysqladmin-u root flush-privileges directly under shell.
In the Mysql environment, you can use the following statement to set the password:
 
1.insert into user(host,user,password) values('%','user_name',password("your password"); 
2.set password for user_name = password("your password") 

Both methods must override the authorization table.
3. Of course, you can also set the password directly when creating a user. grant will automatically encrypt the password for you.
Such as
grant all on *.* to user_name@% identified by "your password";
You can also use the mysqladmin program to set your password in the shell environment
Such as
mysqladmin -u root password "your password"
Go ahead and give it a try, ok?

How do I set a password for mysql

There are many ways:
1. Enter 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. ofstack. com
mysql > flush privileges;

3. Enter the mysql library to modify the user table
mysql > use mysql;
mysql > update user set password=password(' your password ') where user='root';
mysql > flush privileges;

The author matthio

Related articles: