查询mysql表中的用户
mysql> select user, host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
+------+-----------+
3 rows in set (0.00 sec)
创建用户
mysql> create user 'time'@'localhost' identified by '111111';
Query OK, 0 rows affected (0.09 sec)
//下一步需要对该用户授权
修改密码
例如:修改roor用户登陆主机localhost
的密码:
mysql> set password for 'root'@'localhost'=password('*****');
授权用户登陆
授权用户登陆,没有该用户则创建,相对于使用create
方式创建用户要便捷,一步到位。
//授权用户查看的功能的权限
mysql> grant select on *.* to 'berry'@'localhost' identified by '*****';
Query OK, 0 rows affected (0.11 sec)
//授于用户所有的权限
mysql> grant all on *.* to 'berry'@'localhost' identified by '*****';
Query OK, 0 rows affected (0.02 sec)
//使修改立即生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
这里的localhost可以换成其他的ip地址,而这里的ip地址是限制客户机登陆的ip地址,即root@169.2xx.4x.4x的意思是限制root用户只可以在ip为169.2xx.4x.4x的主机上登陆到mysql数据库服务器