一、創建用戶
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';