登陆MySQLmysql
mysql -u root -p
添加新用户
容许本地 IP 访问 localhost, 127.0.0.1sql
create user 'test'@'localhost' identified with 加密方式(mysql_native_password) by '123456';数据库
容许外网 IP 访问服务器
create user 'tst'@'%' identified by '123456';less
刷新受权
flush privileges;ide
为用户建立数据库
create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;加密
为新用户分配权限
授予用户经过外网IP对于该数据库的所有权限.net
grant all privileges on `testdb`.* to 'test'@'%' identified by '123456';
授予用户在本地服务器对该数据库的所有权限
grant all privileges on `testdb`.* to 'test'@'localhost' identified by '123456';
刷新权限
flush privileges;
退出 root 从新登陆
exit
用新账号 test 从新登陆,因为使用的是 % 任意IP链接,因此须要指定外部访问IP
mysql -u test -h 115.28.203.224 -pcode
在Ubuntu服务器下,MySQL默认是只容许本地登陆,所以须要修改配置文件将地址绑定给注释掉:server
# 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 #注释掉这一行就能够远程登陆了否则会报以下错误: