This article brings you an introduction to the method of resetting passwords and assigning new user permissions in MySQL. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Reset the root password
1. Modify the configuration file and log in without a password
Enter the command to edit the file sudo vi etc/mysql/my.cnf ( The root user can do without sudo)
Edit the file and write the configuration:
[mysqld] skip-grant-tables
:wq save and exit and then restart mysql:
sudo service mysql restart
Log in to mysql
Change password:
UPDATE mysql.user SET authentication_string=PASSWORD("123") WHERE user="root"; flush privileges;
Finally, exit and delete the code added by my.cnf, then restart mysql and you’re done~
2. Create a user and assign table permissions
Create user
CREATE USER 'user2'@'localhost' IDENTIFIED BY '123';
Create table
create database test;
Assign permissions
grant all privileges on test.* to user2@'%' identified by '123';
Refresh system permission table
flush privileges;
View permissions:
show grants for 'user2'@'%';
Exit and restart mysql
The above is the detailed content of Introduction to methods of resetting passwords and assigning new user permissions in mysql. For more information, please follow other related articles on the PHP Chinese website!