mysql – 访问被拒绝为用户’test’@’localhost'(使用密码:是)除了root用户

我面临问题与mysql非root / admin用户,我按照以下步骤创建用户及其权限,纠正我,如果我做错了,

我在RHEL 5.7 64位上安装mysql,下面提到的包,一旦我做了rpm安装我们是

>使用mysql_install_db创建mysql db,然后
>启动mysql服务
>使用mysql_upgrade也是我们做的对服务器。

在此过程后,我可以作为root登录,但是使用非root用户我无法登录到服务器:

[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)

这是我面临的问题,有什么解决方案吗?

最佳答案
不要将所有数据库的所有权限授予非root用户,它不安全(您已经具有该角色的“root”),

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

此语句创建一个新用户并向其授予所选特权。
I.E .:

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

看看docs看到的所有特权详细

编辑:您可以查找更多的信息与此查询(登录为“根”):

select Host, User from mysql.user;

看看发生了什么事

转载注明原文:mysql – 访问被拒绝为用户’test’@’localhost'(使用密码:是)除了root用户 - 代码日志