mysql授权,远程访问权限
使用root登录mysql,选择mysql库
use mysql; update user set host = '%' where user = 'root'; select host, user from user;
1、在mysql命令行下执行一下语句(开启所有权限):
GRANT ALL PRIVILEGES ON *.* TO 'username'@'123.13.12.12'IDENTIFIED BY 'password' WITH GRANT OPTION;
其中:
username:登录用户名 password:登录密码 123.13.12.12:授权的主机IP
根据需要只开对某个数据库的所有表有增删改查权限:
GRANT Select,Insert,Delete,Update ON ops_db.* TO 'username'@'123.13.12.12' IDENTIFIED BY "password";
GRANT ALL PRIVILEGES ON `test`.* TO 'user1'@'192.168.%' IDENTIFIED BY '123' show grants for 'user1'@'172.31.%';
2、最后需要清理下权限控制:
FLUSH PRIVILEGES
被授权的主机测试登录命令:
mysql -h 主机IP -P 3306 -uusername -ppassword -D数据库名