首先添加用戶(當然也可是使用root用戶)
格式:grant 權限 on 數據庫名.表名 用戶@登錄主機 identifIEd by "用戶密碼";
grant select,update,insert,delete on *.* to zhxia@'%' identifIEd by '123456';
或者所有權限
GRANT ALL PRIVILEGES ON *.* TO zhxia@'%' IDENTIFIED BY '123456';
接著執行
flush privileges; 使授權生效
最後我們還需要修改MySQL的配置文件
sudo vim /etc/MySQL/my. cnf
在舊版本中找到 skip-networking,把它注釋掉就可以了
#skip-networking
在新版本中:
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
找到 :bind-address = 127.0.0.1 這一行要注釋掉
#bind-address = 127.0.0.1
或者把允許訪問的 ip 填上
#bind-address = 192.168.1.122
然後重啟 MySQL
$> sudo /etc/init.d/MySQL restart