Report this

What is the reason for this report?

Error with mysqli_real_connect(): (HY000/1698): Access denied for user 'root'@'localhost'

Posted on April 3, 2022

I have followed all the steps of the LAMP installation tutorial in ubuntu 20.04 and even mysql is all enabled with flush privileges I don’t understand why I get this error mysqli_real_connect(): (HY000/1698): Access denied for user ‘root’@’ localhost’



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @DavidLuceroSigcho,

If you’ve used the mysql_secure_installation then you’ll need to use a password when connecting to your root user.

  1. mysql -u root -p

This will ask you for the root MySQL password. Once you give it, you’ll enter.

If you don’t want to use a password for MySQL when you are root, you can create a file in /root/.my.cnf and add the following:

  1. [mysql]
  2. user=root
  3. password=RootPasswordHere

where RootPasswordHere is your actual password.

Alternatively, if you still haven’t run mysql_secure_installation:

You need to change the authentication parameters, to do so just run this command first.

$ sudo mysql

Then run This ALTER Query to change the authentication parameters.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mynewpassword';

And now, you are able to run mysql_secure_installation command.

$ sudo mysql_secure_installation

Hope that solve your issue,

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.