mysql数据库授权操作
1、查看数据库权限:
1、查看数据库是否有授权的权限:select *from mysql.user where User='root' and Host='%'\G;
2、在列出的内容中查看Grant_priv:是否为Y
3、当Grant_priv:不为Y时:update mysql.user set Grant_priv='Y' where User='root' and Host='%';
4、刷新权限设置:flush privileges;
5、退出当前账户:quit
2、数据库授权:
1、用root登陆数据库:mysql -h 数据库ip -uroot -p数据库密码
2、创建用户:create user '新建的用户名'@'192.168.42.67' identified by '密码';
3、授权:GRANT ALL PRIVILEGES ON *.* TO '新建的用户名'@'%/主机内网' IDENTIFIED BY '密码' WITH GRANT OPTION;
4、授权成功后刷新权限设置:flush privileges;
5、之后就可以用新授权的用户登陆了:mysql -h 数据库ip -u 新建的用户名 -p密码
3、授权过程可能遇到的小问题:
发现无密码条件下,没有授权的写权限:
The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
解决方法:
mysql> set global read_only=0;//(关掉新主库的只读属性)
mysql>flush privileges;
mysql>set global read_only=1;//(读写属性)
mysql>flush privileges;
重启数据库