Access denied for user 'test'@'localho

2019-01-03 09:22发布

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,

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

  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.

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?

12条回答
Explosion°爆炸
2楼-- · 2019-01-03 09:58

For anyone else who did all the advice but the problem still persists.

Check for stored procedure and view DEFINERS. Those definers may no longer exists.

My problem showed up when we changed the wildcard host (%) to IP specific, making the database more secure. Unfortunately there are some views that are still using 'user'@'%' even though 'user'@'172....' is technically correct.

查看更多
萌系小妹纸
3楼-- · 2019-01-03 10:00

It looks like you're trying to make a user 'golden'@'%' but a different user by the name of 'golden'@'localhost' is getting in the way/has precedence.

Do this command to see the users:

SELECT user,host FROM mysql.user;

You should see two entries:

1) user= golden, host=%

2) user= golden, host=localhost

Do these Command:

DROP User 'golden'@'localhost';
DROP User 'golden'@'%';

Restart MySQL Workbench.

Then do your original commands again:

CREATE USER 'golden'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'golden'@'%';

Then when you go to try to sign in to MySQL, type it in like this:

enter image description here

Hit 'Test Connection' and enter your password 'password'.

查看更多
放荡不羁爱自由
4楼-- · 2019-01-03 10:00

First i created the user using :

CREATE user user@localhost IDENTIFIED BY 'password_txt';

After googling and seeing this, i updated user's password using :

SET PASSWORD FOR 'user'@'localhost' = PASSWORD('password_txt');

and i could connect afterward.

查看更多
我命由我不由天
5楼-- · 2019-01-03 10:00

In my case the same error happen because I was trying to use mysql by just typing "mysql" instead of "mysql -u root -p"

查看更多
Melony?
6楼-- · 2019-01-03 10:01

According way you create your user, MySQL interprets a different manner. For instance, if you create a user like this:

create user user01 identified by 'test01';

MySQL expects you give some privilege using grant all on <your_db>.* to user01;

Don't forget to flush privileges;

But, if you create user like that (by passing an IP address), you have to change it to:

create user 'user02'@'localhost' identified by 'teste02';

so, to give some privileges you have to do that:

grant all on <your_db>.* to user02@localhost;
flush privileges;
查看更多
爷的心禁止访问
7楼-- · 2019-01-03 10:03

Try:

CREATE USER 'golden'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'golden'@'localhost';
FLUSH PRIVILEGES;

Or even better use: mysql_setpermission to create the user

查看更多
登录 后发表回答