任意主機以用戶root和密碼mypwd連接到mysql服務器
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypwd' WITH GRANT OPTION;
mysql> flush privileges;
IP為192.168.1.102的主機以用戶myuser和密碼mypwd連接到mysql服務器
mysql> GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.102' IDENTIFIED BY 'mypwd' WITH GRANT OPTION;
mysql> flush privileges;
mysql的root賬戶,我在連接時通常用的是localhost或127.0.0.1,公司的測試服務器上的mysql也是localhost所以我想訪問無法訪問,測試暫停.
解決方法:
1,修改表,登錄mysql數據庫,切換到mysql數據庫,使用sql語句查看"select host,user from user ;"
mysql -u root -pvmwaremysqluse mysql;
mysqlupdate user set host = '%' where user ='root';
mysqlselect host, user from user;
mysqlflush privileges;注意:最後一句很重要,目的是使修改生效.如果沒有寫,則還是不能進行遠程連接.
2,授權用戶,你想root使用密碼從任何主機連接到mysql服務器
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'admin123' WITH GRANT OPTION;
flush privileges;
如果你想允許用戶root從ip為192.168.1.104的主機連接到mysql服務器
可以外鏈