Home  >  Article  >  Database  >  Introduction to methods of resetting passwords and assigning new user permissions in mysql

Introduction to methods of resetting passwords and assigning new user permissions in mysql

不言
不言forward
2018-10-18 14:24:243179browse

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)

Introduction to methods of resetting passwords and assigning new user permissions in mysql

Edit the file and write the configuration:

[mysqld] 
skip-grant-tables

Introduction to methods of resetting passwords and assigning new user permissions in mysql

:wq save and exit and then restart mysql:

sudo service mysql restart

Log in to mysql

Introduction to methods of resetting passwords and assigning new user permissions in mysql

Change password:

UPDATE mysql.user SET authentication_string=PASSWORD("123") WHERE user="root";
flush privileges;

Introduction to methods of resetting passwords and assigning new user permissions in mysql

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!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete