mysql_secure_installation problem: access denied for user 'root'@'localhost'
Asked Answered
Y

3

6

I am using fresh installed Ubuntu 19.10 and trying to install LAMP, so I ran the following:

sudo apt-get install lamp-server^

After that, I had to configure mysql by running the command:

sudo mysql_secure_installation

Only to get the following message:

Securing the MySQL server deployment.

Enter password for user root:

Error: Access denied for user 'root'@'localhost' (using password: NO)

I've tried several solutions from Stack Overflow and other websites, but none worked for me.

Tried creating a .sql file setting a password to use it with --init-file and also tried skip-grant-tables as suggested here: Initial authorization issue in mysql. No results.

Furthermore, there is no /var/log/mysqld.log only /var/log/mysql/error.log so I also tried what JGlass suggested here: Setting root password in fresh mysql 5.7 installation. No results also.

Yu answered 25/12, 2019 at 21:30 Comment(0)
C
4

I had this same exact problem and then realized that to login as root in mysql I had to run the command as root:

sudo mysql -u root -p
Carcinogen answered 22/7, 2020 at 6:8 Comment(2)
thanks a million, it worked! and sucks to mysql for not better describing this behaviourLegislatorial
was setting up LAMP on a new machine, and hit this. Spot on solution, although when using sudo, you don't seem to need any user or password at all sudo mysql will also do the jobKryska
P
0

Did you install the MySQL as root? If no, try run the mysql_secure_installation without sudo.

If you was install the MySQL as root in terminal(in my case), I solved this issue using like this sudo mysql_secure_installation.

Primogeniture answered 4/10, 2021 at 13:50 Comment(0)
G
0

try rm -rf /usr/local/var/mysql before reinstall mysql;

or rm -rf /opt/homebrew/var/mysql if in macos with homebrew;

Gaullist answered 1/9, 2022 at 2:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.