5

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.

Community
  • 1
  • 1

3 Answers3

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
  • thanks a million, it worked! and sucks to mysql for not better describing this behaviour – Padvinder Jul 25 '21 at 09:53
  • 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 job – NathTech Aug 03 '21 at 16:04
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.

Toni
  • 1,555
  • 4
  • 15
  • 23
0

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

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

Jian Cui
  • 745
  • 1
  • 5
  • 10