默认安装的mysql数据中存在数据库
mysql,其中有表
user,主要是进行权限控制,查询user表,内容如下:
mysql> select host,user from mysql.user;
+---------------------------------+------+
| host | user |
+---------------------------------+------+
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| cp01-rdqa-dev419.cp01 | |
| cp01-rdqa-dev419.cp01 | root |
| localhost | |
| localhost | root |
+---------------------------------+------+
7 rows in set (0.00 sec)
机器的域名为
cp01-rdqa-dev419.cp01
mysql中权限的控制是通过user表进行的,其中host,user两个字段来确定一种权限,例如 root@localhost和root@cp01-rdqa-dev419.cp01代表不同的权限
默认存在一个匿名用户,user为空,查询该匿名用户的权限信息,命令如下:
mysql> show grants for ''@'localhost';
+--------------------------------------+
| Grants for @localhost |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
1 row in set (0.00 sec)
USAGE权限是表示“无权限”,就是一个没有任何权限的用户
通过下面的命令进行授权
grant all privileges on *.* to ''@'localhost' identified by 'root' with grant option;
或者
grant all privileges on *.* to ''@'localhost';
mysql> grant all privileges on *.* to ''@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for ''@'localhost';
+-----------------------------------------------+
| Grants for @localhost |
+-----------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO ''@'localhost' |
+-----------------------------------------------+
1 row in set (0.00 sec)
//查询用户:root,host:localhost 的授权信息
mysql>
SHOW GRANTS FOR 'root'@'localhost';
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
参考
mysql 用户管理和权限设置