MySQL Access for root and any other user

I just set up a new droplet. After configuring mysql for root and any other user with passwords, I just can´t seem to be able to access it correctly. 1. the root user logs in even without the password (unfortunately not usable in my PhP scripts). 2. On the other user (e.g. userX, the password does not allow me to log into the mysql even when I have used the correct one and I have rechecked a number of times. What could be the problem?

Submit an answer
Answer a question...

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!

Sign In or Sign Up to Answer

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.

Site Moderator
Site Moderator badge
March 9, 2022

Hi @MabeleL,

The root user for your MySQL most probably has a .my.cnf file which it uses to login without having to use the password.

Regarding the other user, have you given the user any permission to access a database? The best way to check is no use it in a PHP script but in the CLI directly. Basically, SSH to your Droplet and type in

  1. mysql -u UserHere -p DatabaseHere

or if you just need to connect to MySQL:

  1. mysql -u UserHere -p

Where UserHere is your actual DB user and DatabaseHere is your actual DB.

The above commands will prompt you for your password after which has been provided you should log in MYSQL. What you can do then is type

show databases;

to see the database that you have access to with the said user.