Currently used user and host:
mysql> select USER();
+----------------+
| USER() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
Add user
Before mysql 5, you can directly use INSERT to INSERT mysql users into mysql tables. You can't do this after mysql 5
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 the user {GRANT the user the specified data table permission [use 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 specifies the user's login password
ALL PRIVILEGES refers to all permissions. You can also use select, update and other permissions
*The * sign in front of the. \ is used to specify the database name, and the * sign in the back is used to specify the table name
TO means TO give permission TO a user
ON is used to specify which libraries and tables permissions are targeted
'test Uuser' @'localhost 'means test Uuser, followed by @ by 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
You need to refresh the system permission table [flush privilege] for the user to 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 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 bin directory]
Note: {format: mysqladmin -u user name - p old 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. Directly edit the user table with update
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