通常本機的數據庫只允許本地用戶登錄,此時想要遠程用戶可登錄,步驟:
Linux系統下
首先確定3306端口是對外開放的。
1、netstat -an|grep 3306
2、打開MySQL配置文件 vi /etc/mysql/mysql.conf.d/mysqld.cnf,將bind-address = 127.0.0.1註銷
3、重啓ubuntu,再次查看端口是否打開 :netstat -an | grep 3306
4、進入MySQL 進行授權:sudo mysql -u root -p
5、將root用戶授權給所有連接: grant all privileges on *.* to 'root'@'%' identified by 'xxxxxx';
6、讓權限立即生效:flush privileges;
到此所以操作完成,可以在任何主機連接此mysql數據庫服務器了。
記得要重啓mysql
eg:/etc/init.d/mysql restart
具體步驟看:https://www.cnblogs.com/austinspark-jessylu/p/6899279.html
1、用root用戶登錄數據庫:mysql -uroot -p;
2、成功登錄root用戶後,輸入:
grant all priviliges on 數據庫名.* to 數據庫登錄用戶名@IP indetified by '數據庫登錄密碼' with grant option;
例子:允許遠程以root身份登錄並全部授權:grant all privileges on *.* to root@'%' identified by '123' with grant option;
3、輸入:flush privileges;
複製:
mysql> grant 權限1,權限2,…權限n on 數據庫名稱.表名稱 to 用戶名@用戶地址 identified by ‘連接口令’;
權限1,權限2,…權限n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14個權限。
當權限1,權限2,…權限n被all privileges或者all代替,表示賦予用戶全部權限。
當數據庫名稱.表名稱被*.*代替,表示賦予用戶操作服務器上所有數據庫所有表的權限。
用戶地址可以是localhost,也可以是ip地址、機器名字、域名。也可以用’%'表示從任何地址連接。
‘連接口令’不能爲空,否則創建失敗。
mysql>grant select,insert,update,delete,create,drop on vtdc.employee to [email protected] identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對數據庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的權限,並設定口令爲123。
mysql>grant all privileges on vtdc.* to [email protected] identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對數據庫vtdc所有表進行所有操作的權限,並設定口令爲123。
mysql>grant all privileges on *.* to [email protected] identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對所有數據庫的所有表進行所有操作的權限,並設定口令爲123。
mysql>grant all privileges on *.* to joe@localhost identified by ‘123′;
給本機用戶joe分配可對所有數據庫的所有表進行所有操作的權限,並設定口令爲123。