Home > Database > Mysql Tutorial > Introduction to knowledge related to Mysql user management

Introduction to knowledge related to Mysql user management

藏色散人
Release: 2020-05-12 16:24:25
forward
1926 people have browsed it

Currently used user and host:

mysql> select USER();
+----------------+
| USER()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
Copy after login

Add user

Previous versions of mysql5 directly used INSERT to insert mysql users into the mysql table. This operation cannot be done after mysql5

mysql> insert into mysql.user(Host,User,Password) values('localhost','test_user',password('123123'));
ERROR 1062 (23000): Duplicate entry 'localhost-test_user' for key 'PRIMARY'
Copy after login

Add a user {Grant the user the permission to specify the data table [Use the GRANT command to authorize the user accordingly]}

mysql> GRANT all privileges ON table1.* TO 
'test_user'@'localhost' IDENTIFIED BY '123123' WITH GRANT OPTION;
Query OK, 0 rows affected (0.02 sec)
Copy after login

IDENTIFIED BY Specify the user's login password

ALL PRIVILEGES means all permissions, You can also use select, update and other permissions

*.\ The first * sign is used to specify the database name, and the following * sign is used to specify the table name

TO means granting permissions to a certain User

ON is used to specify which libraries and tables the permissions are for

'test_user'@'localhost' represents the test_user user, @ is followed by the restricted host, which can be IP, IP segment, domain name and %, % means anywhere

WITH GRANT OPTION This option means that the user can authorize his own permissions to others

Need to refresh the system permission table [flush privilege] Only this user can log in effectively

mysql> flush privileges;
Copy after login

Delete user

mysql> drop user 'test_user'@'localhost';
Copy after login

View the permissions of the current user

mysql> SHOW GRANTS;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '\*E56A114692FE0DE073F9A1DD68A00EEB9703F3F1' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION                                                                           |
+----------------------------------------------------------------------------------------------------------------------------------------+
Copy after login

View the permissions of a user

mysql> show grants for 'test_user'@'localhost'
+------------------------------------------------------------------------------------------------------------+
| Grants for test_user@localhost                                                                                   |
+------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test_user'@'localhost' IDENTIFIED BY PASSWORD '\*E56A114692FE0DE073F9A1DD68A00EEB9703F3F1' |
| GRANT ALL PRIVILEGES ON table1.* TO 'test_user'@'localhost' WITH GRANT OPTION                                 |
+------------------------------------------------------------------------------------------------------------+
Copy after login

Rename the account

mysql> rename user 'test_user'@'localhost' to 'bb'@'localhost';
Copy after login

Change password

1. Use the set password command

mysql> SET PASSWORD FOR 'test_user'@'localhost' = PASSWORD('123456');
Copy after login

2. Use mysqladmin [enter the bin directory]

Remarks: {Format: mysqladmin - uUsername -p old password password new password]

/usr/bin$ mysqladmin -utest_user -p123456 password 123123
mysqladmin: Can't turn off logging; error: 'Access denied; you need (at least one of) the SUPER privilege(s) for this operation'
Copy after login

3. Use update to directly edit the user table

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set PASSWORD = PASSWORD('123123') where user = 'test_user';
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0
Copy after login

Recommended tutorial: "MySQL Tutorial"

The above is the detailed content of Introduction to knowledge related to Mysql user management. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.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