MySQL的用户权限设置问题(如何解决Access denied)
2008-10-20 21:00
701 查看
有一次使用MySQL的时候,莫名其妙地出现root用户Access denied,后来查了相关资料,是用户权限的问题,所以顺便就熟悉了一下SQL的grant语法。
环境:
Server: ser1(with MySQL Server)
Client: cli1(with MySQL Client)
问题:
cli1#mysql -h ser1 -u root -p
Enter password:
ERROR 1045: Access denied for user: 'root@ser1' (Using password: NO)
原因:
在cli1上的用户usr没有连接ser1上MySQL的权限,可以通过如下的方式确认:
cli1#mysql -h ser1 -u root -p (默认的root用户没有设置密码)
Enter password: (直接Enter)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.0.20a-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use mysql; (此DB存放MySQL的各种配置信息)
Database changed
mysql> select host,user from user; (查看用户的权限情况)
+-------------+-------+
| host | user |
+-------------+-------+
| build | |
| build | root |
| localhost | |
| localhost | root |
+-------------+-------+
6 rows in set (0.02 sec)
由此可以看出,ser1上的root用户只能从localhost(ser1)上连接,而对于cli1,只能增加cli1上的root访问权限。
解决方法:
mysql> Grant all privileges on *.* to 'root'@'%' identified by '' with grant option;
Query OK, 0 rows affected (0.02 sec) (%表示是所有的外部机器,如果指定某一台机,就将%改为相应的机器名)
mysql> flush privileges; (运行为句才生效,或者重启MySQL)
Query OK, 0 rows affected (0.03 sec)
mysql>exit
现在再试试:
cli1#mysql -h ser1 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9 to server version: 4.0.20a-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
就成功连接上了。
补充:
若删除用户的权限,用如下的语法:
mysql> show grants for 'user_name';
mysql> revoke all privileges on *.* from 'user_name';
mysql> revoke grant option on *.* from 'user_name';
(4.1版本后的可以用drop user语句,更方便。)
环境:
Server: ser1(with MySQL Server)
Client: cli1(with MySQL Client)
问题:
cli1#mysql -h ser1 -u root -p
Enter password:
ERROR 1045: Access denied for user: 'root@ser1' (Using password: NO)
原因:
在cli1上的用户usr没有连接ser1上MySQL的权限,可以通过如下的方式确认:
cli1#mysql -h ser1 -u root -p (默认的root用户没有设置密码)
Enter password: (直接Enter)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.0.20a-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use mysql; (此DB存放MySQL的各种配置信息)
Database changed
mysql> select host,user from user; (查看用户的权限情况)
+-------------+-------+
| host | user |
+-------------+-------+
| build | |
| build | root |
| localhost | |
| localhost | root |
+-------------+-------+
6 rows in set (0.02 sec)
由此可以看出,ser1上的root用户只能从localhost(ser1)上连接,而对于cli1,只能增加cli1上的root访问权限。
解决方法:
mysql> Grant all privileges on *.* to 'root'@'%' identified by '' with grant option;
Query OK, 0 rows affected (0.02 sec) (%表示是所有的外部机器,如果指定某一台机,就将%改为相应的机器名)
mysql> flush privileges; (运行为句才生效,或者重启MySQL)
Query OK, 0 rows affected (0.03 sec)
mysql>exit
现在再试试:
cli1#mysql -h ser1 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9 to server version: 4.0.20a-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
就成功连接上了。
补充:
若删除用户的权限,用如下的语法:
mysql> show grants for 'user_name';
mysql> revoke all privileges on *.* from 'user_name';
mysql> revoke grant option on *.* from 'user_name';
(4.1版本后的可以用drop user语句,更方便。)
相关文章推荐
- MySQL如何解决赋予/收回用户权限时发生Access Denied的情况
- 以用户模拟方式解决手动设置权限问题
- XP中如何解决备份文件夹拒绝访问问题(也可解决普通用户访问管理员用户的文件的权限问题)
- win7管理员账户被禁用或者设置不显示后如何用标准用户解除_win7用户权限问题_administraotr账户问题
- win2003 iis6 Rewrite权限设置问题 解决了 大家共享 2003NTFS用户 你不看肯定开不开
- MYSQL设置触发器权限问题的解决方法
- IPv6设置后如何解决MySQL无法连接localhost的问题
- IPv6设置后如何解决MySQL无法连接localhost的问题
- MYSQL设置触发器权限问题的解决方法
- 如何解决iOS中更改系统定位权限时候系统设置崩溃的问题
- mysql 从库设置read-only 对super权限的用户无效的问题
- MySql安装root用户密码设置失败问题解决
- JIRA6.3.6中设置用户的解决问题和关闭问题权限
- IPv6设置后如何解决MySQL无法连接localhost的问题
- mysql用户设置%后不能本地连接的问题解决
- MySQL的用户权限设置问题
- 如何解决使用远程工具登陆mysql,缺乏权限的问题
- MYSQL设置触发器权限问题的解决方法
- 关于hive里安装mysql出现错误,如何删除指定的主机或用户?(解决Access denied)
- XP中如何解决备份文件夹拒绝访问问题(也可解决普通用户访问管理员用户的文件的权限问题)