Home >Database >Mysql Tutorial >Introduction to knowledge related to Mysql user management
Currently used user and host:
mysql> select USER(); +----------------+ | USER() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec)
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'
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)
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;
Delete user
mysql> drop user 'test_user'@'localhost';
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 | +----------------------------------------------------------------------------------------------------------------------------------------+
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 | +------------------------------------------------------------------------------------------------------------+
Rename the account
mysql> rename user 'test_user'@'localhost' to 'bb'@'localhost';
Change password
1. Use the set password command
mysql> SET PASSWORD FOR 'test_user'@'localhost' = PASSWORD('123456');
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'
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
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!