https://blog.csdn.net/u013216667/article/details/70158452
登錄MySQL
mysql -u root -p
添加新用戶
允許本地 IP 訪問 localhost, 127.0.0.1
create user 'test'@'localhost' identified by '123456';
允許外網 IP 訪問
create user 'test'@'%' identified by '123456';
flush privileges;
為用戶創建數據庫
create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
為新用戶分配權限
授予用戶通過外網IP對於該數據庫的全部權限
grant all privileges on `testdb`.* to 'test'@'%' identified by '123456';
grant all privileges on `testdb`.* to 'test'@'localhost' identified by '123456';
刷新權限
flush privileges;
exit
mysql -u test -h 115.28.203.224 -p
在Ubuntu服務器下,MySQL默認是只允許本地登錄,因此需要修改配置文件將地址綁定給注釋掉:
# 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 #注釋掉這一行就可以遠程登錄了
