Home > Database > Mysql Tutorial > 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

不言
Release: 2018-10-18 14:30:35
forward
3217 people have browsed it

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
Copy after login

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
Copy after login

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;
Copy after login

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';
Copy after login

Create table

create database test;
Copy after login

Assign permissions

grant all privileges on test.* to user2@'%' identified by '123';
Copy after login

Refresh system permission table

flush privileges;
Copy after login

View permissions:

show grants for 'user2'@'%';
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template