MySQL where to find user credentials file?

Dear viewers,

I am struggling with this problem for a while now. And it is just taking too long. I am having this error: SQLSTATE[HY000] [1045] Access…root@…password: YES) whenever I get on my website’s main page. This doesn’t occur when entering my website’s phpmyadmin page though. Now, people have told me to f*ck off and learn everything about MySQL and then come back, but there were also people who told me that my MySQL credentials were not set right. So, my question now is: “Where can I find these MySQL Credentials and in which file do I need to adjust them?

Warmest regards,


Submit an answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Update: This is my current setup I am having right now:

I own a “VDC-4”, a virtual datacenter. This is hosted through a company’s website. I use Putty to connect to this datacenter and install packages on it. I use FileZilla to transfer files to this datacenter. I only have installed the LAMP-Pack yet and setup the phpMyAdmin yet. Also, I have created a virtual host file in etc/apache2/sites-available/virtualhost.conf, in this I have put this code: <VirtualHost *:80> ServerAdmin root@localhost ServerName ServerAlias DocumentRoot /var/www/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory>

Also, I have dragged a template website script (including .php, images, .js etc.) into the /var/www/ folder. Then I have changed the .htaccess file to this content: RewriteEngine on RewriteRule ^(\w+)$ index.php?page=$1 [L,NC,QSA] RewriteRule ^(\w+)+/$ index.php?page=$1 [L,NC,QSA]

order allow,deny deny from allow from all

This is all I have done sofar. I was following a tutorial of someone setting up this website script. But when I tried to open it in my browser the SQLSTATE[HY000] [1045] Access denied for user ‘root’@‘localhost’ (using password: YES) error showed up. And this did not occur when he did it.

So I am trying to figure out what I’ve done wrong, but I haven’t yet.

I hope this makes it easier to understand for you guys.

Kind regards,



The first and last part of my reply would be valid, even for those not using DigitalOcean :-). The only thing you wouldn’t have is this file:


The root password is stored internally within MySQL, so you won’t be able to open a file or randomly find it elsewhere.

Once it’s set, it’s encrypted and the only way to reset it is by starting MySQL in safe mode (as noted in the link I provided) and setting a new root password.

If you can run:

mysql -u root

from the CLI and get the MySQL prompt, then you don’t have a root password set (notice I am not using the -p flag, that will always prompt you for a password, even if you don’t have one set).

If you can access the MySQL CLI when running the command above, you need to run:


to set the password. From there, you can use:

mysql -u root -p

to login from the CLI, or use the root username and the password you just set to access other areas or software to manage your databases.


On some repositories, MySQL is not setup with a default root password, thus you’re able to login as root without a password. On others, you’re prompted to set a password during the initial install or when running the command:


If you can run the following from the CLI and gain instant access, a root password isn’t set:

mysql -u root

… and you would need to run mysql_secure_installation to set the root password.

On the other hand, if you are not able to gain instant access, then a root password is set and what it is depends on how you setup your installation.

If you installed a LAMP stack via a one-click image, your root password should be here:


If you didn’t install via a one-click image, the only way to reset the root password would be to use start MySQL in safe mode and do a reset on the password.