Rafael Machado
Rafael Machado

Reputation: 61

mysql_secure_installation problem: access denied for user 'root'@'localhost'

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.

Upvotes: 6

Views: 5577

Answers (3)

Jian Cui
Jian Cui

Reputation: 805

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

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

Upvotes: 0

Wellington Brito
Wellington Brito

Reputation: 31

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.

Upvotes: 0

Bryce Weller
Bryce Weller

Reputation: 49

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

Upvotes: 4

Related Questions