权限管理
我们知道我们的最高权限管理者是root用户,它拥有着最高的权限操作。包括select
、update
、delete
、update
、grant
等操作。
那么一般情况在公司之后DBA工程师会创建一个用户和密码,让你去连接数据库的操作,并给当前的用户设置某个操作的权限(或者所有权限)。那么这时就需要我们来简单了解一下:
- 如何创建用户和密码
- 给当前的用户授权
- 移除当前用户的权限
进入到 MySQL 数据库下
1 2
| mysql> use mysql Database changed
|
对新用户增删改
创建用户
1
| CREATE USER "username"@"host" IDENTIFIED WITH mysql_native_password BY "password";
|
eg:1 2 3 4 5 6
| CREATE USER "curatorc"@"47.99.161.35" IDENTIFIED WITH mysql_native_password by "password";
CREATE USER "curatorc"@"47.99.161.%" IDENTIFIED WITH mysql_native_password by "password";
CREATE USER "curatorc"@"%" IDENTIFIED WITH mysql_native_password by "password";
|
删除用户
1
| DROP USER "username"@"host";
|
修改用户
1
| RENAME USER "username"@"host" TO "newusn"@"host";
|
修改密码
1
| ALTER USER 'username'@'host' IDENTIFIED WITH mysql_native_password BY "password";
|
对当前的用户授权管理
授权
1
| GRANT all privileges ON database.table TO "username"@"host";
|
eg:1 2 3 4 5 6 7 8 9
| GRANT select, insert, update ON db1.t1 TO "curatorc"@"%";
GRANT all privileges ON db1.t1 TO "curatorc"@"%";
GRANT all privileges ON db1.* TO "curatorc"@"%";
GRANT all privileges ON *.* TO "curatorc"@"%";
|
查看授权
1
| SHOW GRANTS FOR "username"@"host"
|
取消权限
1
| REVOKE ALL ON database.table FROM "username"@"host";
|
刷新授权
备份操作
1 2 3 4 5 6 7 8 9 10 11
| MYSQDUMP -u root db1 > db1.sql -p
MYSQDUMP -u root -d db1 > db1.sql -p
CREATE DATABASE db10;
MYSQDUMP -u root -d db10 < db1.sql -p
|
转载链接