Linux allows thesql login from root but not from another linux user account

apache-2.4linuxMySQLredhat

So, I have two user accounts on a BlueHost owned webserver. Let's call them "root" and "user1". When I login to my root linux account, I then try to login to mysql on the "root" mysql account. I then am able to login to mysql. Everything is good there.

The problem is, when I try to login to the mysql "root" user from the "user1" linux account using the exact same creds (none. There is no password on that mysql account), I get an error message that says:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Is there some user permissions in linux that I need to change on the "user1" user?

Best Answer

Recent mysql/mariadb servers have a plugin-based authentication system, exemple:

MariaDB [(none)]> select user,host,password,plugin from mysql.user limit 1;
+------+-----------+-------------------------------------------+-------------+
| user | host      | password                                  | plugin      |
+------+-----------+-------------------------------------------+-------------+
| root | localhost |                                           | unix_socket |
+------+-----------+-------------------------------------------+-------------+

In this configuration access for root@localhost is ONLY granted to unix user "root", your real user id is sent to the mysql server and login is granted only if it matches the requested mysql user.

For "user1" to be able to log into the mysql server you will need to either:

  • Change root authentication back to 'normal' login/password auth (carefull, it will break most of the automated script, logrotate, service start/stop and the like). ALTER USER root@localhost identified with 'mysql_native_password'; SET PASSWORD = password('foo');

  • Create a mysql user1 with unix_socket auth: CREATE USER user1 IDENTIFIED VIA unix_socket; and give him some root access right GRANT ALL WITH GRANT OPTION ON *.* TO user1@localhost;

Related Topic