共计 2612 个字符,预计需要花费 7 分钟才能阅读完成。
1. 通过 MySQL 数据库的 user 表查看用户相关信息
mysql> use mysql
Reading table informationfor completion of table and column names
You can turn offthis feature to get a quicker startup with –A
Database changed
mysql> select host,user,password from user ;
+———–+——+——————————————-+
| host | user | password |
+———–+——+——————————————-+
| localhost | root | *87F2746835A04895BB77E12AA5054A767******* |
| qxyw | root | |
| 127.0.0.1 | root | |
| localhost | | |
| qxyw | | |
+———–+——+——————————————-+
5 rows in set (0.00 sec)
2. 创建数据库
mysql> create database [databasename] default character set utf8 collate utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
3. 创建用户
mysql> create user 'dba'@'%' identified by '*******';
Query OK, 0 rows affected (0.00 sec)
user 表中 host 列的值的意义
% 匹配所有主机
localhost localhost 不会被解析成 IP 地址,直接通过 UNIXsocket 连接
127.0.0.1 会通过 TCP/IP 协议连接,并且只能在本机访问;
::1 ::1 就是兼容支持 ipv6 的,表示同 ipv4 的 127.0.0.1
4. 对 dba 用户给予针对指定数据库进行增删改查的权限
mysql> grant select,insert,update,delete,create on [databasename].* to dba;
Query OK, 0 rows affected (0.00 sec)
注意:修改完权限以后 一定要刷新服务,或者重启服务,刷新服务用:FLUSH PRIVILEGES
5. 可以通过 show grants 命令查看权限,若想要在原来的基础上增加权限则继续执行 grant
mysql> grant drop on [databasename].* to dba;
Query OK,0 rows affected (0.00 sec)
mysql> show grants for dba;
+—————————————————————————————————-+
| Grants for dba@% |
+—————————————————————————————————-+
| GRANT USAGE ON *.* TO ‘dba’@’%’ IDENTIFIED BY PASSWORD ‘*****************************************’ |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON `[databasename]`.* TO ‘dba’@’%’ |
+—————————————————————————————————-+
2 rows in set (0.00 sec)
6. 通过 revoke 命令可以移除用户的相关权限
mysql> revoke drop on [databasename].* from dba;
Query OK,0 rows affected (0.00 sec)
mysql> show grants for dba;
+—————————————————————————————————-+
| Grants for dba@% |
+—————————————————————————————————-+
| GRANT USAGE ON *.* TO ‘dba’@’%’ IDENTIFIED BY PASSWORD ‘*****************************************’ |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `[databasename]`.* TO ‘dba’@’%’ |
+—————————————————————————————————-+
2 rows in set (0.00 sec)
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-06/145067.htm