So... I'm setting up a new server and keep running into this problem.

When I try to login to the MySQL database with the root user, I get the "ERROR 1698 (28000): Access denied for user 'root'@'localhost'" error.

It doesn't matter if I connect through the terminal(SSH), through PHPMyAdmin or a MySQL Client, e.g. Navicat. They all fail.

I looked in the mysql.user table and get the following:

+------------------+-------------------+
| user             | host              |
+------------------+-------------------+
| root             | %                 |
| root             | 127.0.0.1         |
| amavisd          | localhost         |
| debian-sys-maint | localhost         |
| iredadmin        | localhost         |
| iredapd          | localhost         |
| mysql.sys        | localhost         |
| phpmyadmin       | localhost         |
| root             | localhost         |
| roundcube        | localhost         |
| vmail            | localhost         |
| vmailadmin       | localhost         |
| amavisd          | test4.folkmann.it |
| iredadmin        | test4.folkmann.it |
| iredapd          | test4.folkmann.it |
| roundcube        | test4.folkmann.it |
| vmail            | test4.folkmann.it |
| vmailadmin       | test4.folkmann.it |
+------------------+-------------------+

As you can see, root should have access.

The Server is quite simple, as I have tried to troubleshoot this for a while now..

It's running Ubuntu 16.04.1 LTS with Apache, MySQL and PHP, so that it can host websites, and iRedMail 0.9.5-1, so that it can host mail.

Login in to the MySQL database works fine before I install iRedMail. I also tried, just installing iRedMail, but then root, also doesn't work...

If someone could tell me how I fix my MySQL login problem or how I install iRedMail, on top of an existing MySQL install. And yes I tried the Installation Tips and I can't find those variables in the config files.

Any help is much appreciated :)

share|improve this question
2  
Thanks for listing all your user accounts and host names. If you could also provide some passwords, that'd be really helpful. – Martin Parkin Sep 1 '16 at 22:07
    
It's local domains, so good luck connecting to them ;) Nothing but standard users from installing iRedMail, so with minimal guesswork anyone would be able to know that those users exist om the system. – Folkmann Sep 2 '16 at 13:51
    
I followed this link and the first option worked for me: askubuntu.com/questions/763336/… – Mikael Arhelger Nov 28 '17 at 16:39
up vote 137 down vote accepted

The reason is that recent Ubuntu installation (maybe others also), mysql is using by default the UNIX auth_socket plugin.

Basically means that: db_users using it, will be "auth" by the system user credentias. You can see if your root user is set up like this by doing the following:

$ sudo mysql -u root # I had to use "sudo" since is new installation

mysql> USE mysql;
mysql> SELECT User, Host, plugin FROM mysql.user;

+------------------+-----------------------+
| User             | plugin                |
+------------------+-----------------------+
| root             | auth_socket           |
| mysql.sys        | mysql_native_password |
| debian-sys-maint | mysql_native_password |
+------------------+-----------------------+

As you can see in the query, the root user is using the auth_socket plugin

There are 2 ways to solve this:

  1. You can set the root user to use the mysql_native_password plugin
  2. You can create a new db_user with you system_user (recommended)

Option 1:

$ sudo mysql -u root # I had to use "sudo" since is new installation

mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;

$ service mysql restart

Option 2: (replace YOUR_SYSTEM_USER with the username you have)

$ sudo mysql -u root # I had to use "sudo" since is new installation

mysql> USE mysql;
mysql> CREATE USER 'YOUR_SYSTEM_USER'@'localhost' IDENTIFIED BY '';
mysql> GRANT ALL PRIVILEGES ON * . * TO 'YOUR_SYSTEM_USER'@'localhost';
mysql> UPDATE user SET plugin='auth_socket' WHERE User='YOUR_SYSTEM_USER';
mysql> FLUSH PRIVILEGES;
mysql> exit;

$ service mysql restart

Remember that if you use option #2 you'll have to connect to mysql as your system username (mysql -u YOUR_SYSTEM_USER)

share|improve this answer
1  
This solve the problem for me! Tnx! – Kiryl Lapchynski May 4 '17 at 14:45
    
yes this one solve my problem thanks – sangram Jun 12 '17 at 18:35
    
Thanks, problem solved. – sudoz Jul 5 '17 at 6:48
1  
Option 1 worked for me. But then I also needed to run sudo gedit /etc/phpmyadmin/config.inc.php. Then I did a search for AllowNoPassword and uncommented both lines that contained it. Then I was able to login as root with no password. – Joe Sep 27 '17 at 15:46
1  
This percona blog post helped me a bit. percona.com/blog/2016/03/16/… Sounds like this happens if you try to skip setting a password for root, which then causes the 'auth_plugin' to use the unix auth_socket, which apparently just compares users. – Josh Brown Dec 19 '17 at 2:42

If you could login with sudo but not without sudo then do:

$ sudo mysql -u root -p

[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q 

Once done, open a new shell, and then:

$ mysql -u root -p without sudo will work just fine.

share|improve this answer
    
this caused me some problems, such that I had to remove --purge mysql and restart with the answer below – Nevermore May 25 '17 at 13:28
    
This locked me out of the database – Maurice Elagu Jan 3 at 15:00

You want to access MySQL with root user but you're not providing root's correct password.

If you need to set a new password for root, MySQL's site has great documentation on how to do it: http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

I'll not show the process in here because MySql documentation on the above link it's clear and concise.

share|improve this answer
    
Thanks for the anwser, but I couldn't get it to work, so I have chosen to install iRedMail with a pgSQL database instead. – Folkmann Sep 2 '16 at 15:55
    
Roger Folkman! Good to know that you solved your problem any how. – Cristian Gonçalves Sep 2 '16 at 16:15

I would suggest to remove the Mysql connection -

UPDATE-This is for Mysql version 5.5,if your version is different ,please change the first line accordingly

sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.5 mysql-client-core-5.5
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get autoremove
sudo apt-get autoclean

And Install Again But this time set a root password yourself. This will save a lot of effort.

sudo apt-get update
sudo apt-get install mysql-server
share|improve this answer
    
@ingernet maybe thats because of some other issues which you neglected while installing again – Eminem347 Aug 4 '17 at 20:21
    
@PJBrunet maybe cause your version of Mysql is different – Eminem347 Sep 22 '17 at 7:01
    
Fair enough, but an all-purpose solution is best. – PJ Brunet Sep 22 '17 at 7:22

I was having this issue on an Debian 8 VM that I was interacting with through Putty on my Windows 10 desktop.

I tried the various suggestions on here but nothing quite worked and I am running MariaDB on the Debian host. In the end I found that I couldn't start the db server in safe mode but I didn't need to and the following commands actually worked for me i.e. allowing a newly created MySql user to log into the MySql/MariaDB server:

sudo service mysql stop
sudo mysql # logs in automatically into MariaDB
use mysql;
update user set plugin='' where user='your_user_name';
flush privileges;
exit;
sudo service mysql restart # restarts the mysql service

If the above doesn't quite work for you, follow the steps outlined in zetacu's post above (zetacu) then follow my steps.

Now you should be able to use a remote terminal client and securely log into mysql using the command:

mysql -u your_user_name -p

*type in the password when prompted

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.