Article directory
Column catalog please click
User Management
create user
CREATE USER zhangsan IDENTIFIED BY '123456';
The execution results are as follows
view users
SELECT * FROM mysql.user;
field explanation
host
Indicates the type of connection
- % means all remote connections via TCP
- IP address such as (192.168.1.2, 127.0.0.1) TCP connection through specifying ip address
- The machine name is a TCP connection made by specifying the machine name in the i network
- ::1 The local ip address of IPv6 is equivalent to 127.0.0.1 of IPv4
- localhost local connection via command line, such as mysql -u xxx -p 123xxx connection
User
Indicates username
The permissions linked by the same user through different methods are different.
select_priv , insert_priv etc
Permissions owned by this user.
change Password
Modify the current user password
SET PASSWORD =PASSWORD('123456')
Change a user's password
UPDATE mysql.user SET PASSWORD=PASSWORD('123123') WHERE USER='zhangsan';
FLUSH PRIVILEGES; #所有通过user表的修改,必须用该命令才能生效。
modify user
UPDATE mysql.user SET USER='zhangsan' WHERE USER='zhangsi';
FLUSH PRIVILEGES; #所有通过user表的修改,必须用该命令才能生效。
delete users
DROP USER zhangsan ;
pass
DELETE FROM USER WHERE USER='zhangsan'
User data will remain
authority management
View permissions
View current user permissions
SHOW GRANTS;
View a user's global permissions
select * from user ;
View the permissions of a library for a user
select * from db;
View the permissions of a table for a user
select * from tables_priv;
Granted permission
GRANT 权限1,权限2,…权限n ON 数据库名称.表名称 TO 用户名@用户地址 IDENTIFIED BY ‘连接口令’;
- If it is found that the user does not have this permission, a new user will be created directly
example one
GRANT SELECT,INSERT,DELETE,DROP ON hello.* TO zhangsan@localhost ;
- Grant permission to insert, delete, modify and check all tables under the hello library
Example 2
GRANT ALL PRIVILEGES ON *.* TO joe@'%' IDENTIFIED BY '123';
- Grant the joe user who logs in through the network, all permissions to all tables in all libraries, and the password is set to 123
- Even if all privileges have all permissions, grant_priv permissions can only be owned by root
Example three
Assign the link command to the root user
GRANT ALL PRIVILEGES ON *.* TO root@'%';
- The newly created connection does not have a password, and a password needs to be set to connect remotely.
UPDATE USER SET PASSWORD=PASSWORD('root') WHERE USER='root' AND HOST='%';
Withdraw authority
The user must log in again to take effect
REVOKE 权限1,权限2,…权限n ON 数据库名称.表名称 FROM 用户名@用户地址 ;
example one
REVOKE ALL PRIVILEGES ON mysql.* FROM joe@localhost;
Take back all permissions of the whole database and tables
Example 2
REVOKE select,insert,update,delete ON mysql.* FROM joe@localhost;
- Take back the permission to insert, delete, modify and query all tables under the mysql library