MySQL创建用户、授权、撤销权限、删除用户
一、创建用户
mysql -u root -p
1.mysql->create user 'test'@'localhost' identified by '123';
2.mysql->create user 'test'@'192.168.7.22' identified by '123';
3.mysql->create user 'test'@'%' identified by '123';
注意:此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录。
如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录。也可以指定某台机器可以远程登录。
如果报错:出现ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
解决方法:
打开my.ini,查找
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
修改为
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
然后重启MYSQL
二、授权
mysql -u root -p
使用命令:grant privileges on databasename.tablename to 'username'@'host' identified by 'pwd';
mysql->grant all on quant.* to 'test'@'localhost' identified by '123';
mysql>flush privileges;
如果授权报错:ERROR 1045 (28000): Access denied for user 'username'@'host' (using password: YES)
参见:http://www.cnblogs.com/SZxiaochun/p/6962910.html
三、撤销权限
mysql -u root -p
使用命令:revoke privileges on databasename.tablename from 'username'@'host';
mysql>flush privileges;
四、删除用户
mysql -u root -p
使用命令:drop user 'test'@'host';