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';

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM