根用户以外的用户'test'@'localhost'的访问被拒绝(使用密码:是) [英] Access denied for user 'test'@'localhost' (using password: YES) except root user

查看:77
本文介绍了根用户以外的用户'test'@'localhost'的访问被拒绝(使用密码:是)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了mysql非root/admin用户的问题,我正在按照以下步骤创建用户及其特权,如果我做错了,请纠正我,

I am facing problem with mysql non root/admin user, I am following the below steps for creating user and its privileges, correct me if i am doing wrong,

我正在RHEL 5.7 64bit上安装mysql,下面提到了软件包,一旦完成rpm install,我们便是

i am installing mysql on RHEL 5.7 64bit, packages are mentioned below, once i done the rpm install we are

  1. 使用mysql_install_db创建mysql数据库,然后
  2. 然后启动mysql服务
  3. 也使用mysql_upgrade对服务器进行操作.
  1. creating mysql db using mysql_install_db, then
  2. starting the mysql service then
  3. using mysql_upgrade also we are doing to the server.

此过程之后,我可以以root身份登录,但使用非root用户身份后,我将无法登录服务器:

After this process i can login as root but with a non-root user I am not able to log into the server:

[root@clustertest3 ~]# rpm -qa | grep MySQL
MySQL-client-advanced-5.5.21-1.rhel5
MySQL-server-advanced-5.5.21-1.rhel5


[root@clustertest3 ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[root@clustertest3 ~]# ls -ld /var/lib/mysql/mysql.sock
srwxrwxrwx 1 mysql mysql 0 Nov  30 11:09 /var/lib/mysql/mysql.sock

mysql> CREATE USER 'golden'@'%' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON * . * TO 'golden'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT USER(),CURRENT_USER();
+----------------+----------------+
| USER()         | CURRENT_USER() |
+----------------+----------------+
| root@localhost | root@localhost |
+----------------+----------------+
1 row in set (0.00 sec)

[root@clustertest3 ~]# mysql -ugolden -p
Enter password:
ERROR 1045 (28000): Access denied for user 'golden'@'localhost' (using password: YES)

这是我面临的问题,对此有什么解决办法吗?

This is the problem I am facing, is there any solution to this?

推荐答案

不要将所有数据库的所有特权授予非root用户,这是不安全的(并且您已经具有该角色的"root"权限)

Do not grant all privileges over all databases to a non-root user, it is not safe (and you already have "root" with that role)

GRANT <privileges> ON database.* TO 'user'@'localhost' IDENTIFIED BY 'password';

此语句创建一个新用户并为其授予选择的特权. 即:

This statement creates a new user and grants selected privileges to it. I.E.:

GRANT INSERT, SELECT, DELETE, UPDATE ON database.* TO 'user'@'localhost' IDENTIFIED BY 'password';

看看文档查看所有特权的详细信息

Take a look at the docs to see all privileges detailed

您可以通过此查询查找更多信息(以"root"身份登录):

you can look for more info with this query (log in as "root"):

select Host, User from mysql.user;

看看发生了什么

这篇关于根用户以外的用户'test'@'localhost'的访问被拒绝(使用密码:是)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆