Mysql新增用户并授权(通过命令行新增数据库账号)
1)进入mysql终端
http://istester.com/mysql/176.html
2、创建账号 zlq,密码 zlq123456
create user zlq identified by 'zlq123456';
3、新建两个数据库 idoxu 和 istester
mysql> create database idoxu;
Query OK, 1 row affected (0.00 sec)
mysql> create database istester;
Query OK, 1 row affected (0.00 sec)
4、把这两个数据库,授予zlq 用户
授权命令格式:grant privilegesCode on dbName.tableName to username@host identified by "password";
比如 ,
把这两个数据库的所有权限,都授予给istester用户,并允许远程登录;
mysql> grant all privileges on istester.* to zlq@'%' identified by 'zlq123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant select,update on idoxu.* to zlq@'%' identified by 'zlq123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
5、查看权限授予的情况
mysql> show grants for zlq;
+--------------------------------------------------------+
| Grants for zlq@% |
+--------------------------------------------------------+
| GRANT USAGE ON *.* TO 'zlq'@'%' |
| GRANT ALL PRIVILEGES ON `istester`.* TO 'zlq'@'%' |
| GRANT SELECT, UPDATE ON `idoxu`.* TO 'zlq'@'%' |
+--------------------------------------------------------+
3 rows in set (0.00 sec)
6、用客户端,连接看看
参考文章 http://istester.com/mysql/401.html
7、搞定