3

After installing mysql using sudo apt-get install mysql-server, no question was asked to me to fill a specific password for root account. Logically, it means password is empty. It is confirmed when I have a look in the /var/log/mysql/error.log where I can find this information =>

2019-04-28T20:31:35.761063Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

But now, when I connect to PHPAdmin with root login and empty password, I have a message:

#1698 - Access denied for user 'root'@'localhost'

with a few more details:

mysqli_real_connect(): (HY000/1045): Access denied for user 'phpmyadmin'@'localhost' (using password: YES)

How do I solve this issue?

Kulfy
  • 17,416
  • 26
  • 64
  • 103
Yann B.
  • 31
  • 1
  • 1
  • 3

2 Answers2

20

With Ubuntu 18.04 and mysql-5.7, the default method for a mysql root login has changed, now you have to be the superuser (either by doing sudo mysql -u root or by calling a root shell sudo bash first). Since you are already authenticated as the root user, no password is needed any longer.

See also this question and its answers.

Sir Cornflakes
  • 504
  • 8
  • 31
-2

You can change the password and set a new root password by doing this :

sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
mysql -u root

FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

skip-grant-tables option enables anyone to connect without a password and with all privileges

VanVan
  • 12
  • 2
  • 1
    this did not work for me. mysqld would exit with no errors if I tried this. – Russell Fulton Jul 22 '19 at 01:11
  • this never works, with any version of MySQL (5.7, 8.0) When you try to connect you always get: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) – Gubatron Aug 05 '20 at 23:47
  • adding `--skip-grant-tables` as a command line argumnet doesn't seem to work, but it works when you add `skip-grant-tables` to the configuration files, e.g. after the `[mysqld]` line in `/etc/mysql/mysql.conf.d/mysqld.conf` – Dave Ankin Mar 25 '23 at 10:55