目的:
①创建mysql新用户test_user
②给新用户test_user授权,让他可以从外部登陆和本地登陆
一、创建用户
注意:@左边是用户名,右边是域名、IP和%,表示可以访问mysql的域名和IP,%表示外部任何地址都能访问。
mysql> create user 'test_user'@'%' identified by '密码';
Query OK, 0 rows affected (0.00 sec)
查看结果:
mysql> select user,host,password from mysql.user;
+----------+-----------+-------------------------------------------+
| user | host | password |
+----------+-----------+-------------------------------------------+
| root | localhost |
*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | bogon | |
| root | 127.0.0.1 | |
| | localhost | |
| | bogon | |
| test_user | % |
*3046CF87132BBD4FDDF06F321C6859074843B7D3 |
| test_user | localhost | *3046CF87132BBD4FDDF06F321C6859074843B7D3 |
+----------+-----------+-------------------------------------------+
7 rows in set (0.00 sec)
备注:
删除用户命令:drop user 用户名@'%';
二、授权
mysql> create database 数据库名; //创建数据库
mysql> grant all privileges on 数据库名.* to 用户; //此用户只能操作此数据库的权限设置
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
网友评论