Question

MySQL where to find user credentials file?

  • Posted June 20, 2017
  • MySQL

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,

iAmNew

Subscribe
Share

Submit an 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.

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 domainname.tk ServerAlias www.domainname.tk 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 xx.xxx.xxx.xxx 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,

iAmNew

@iAmNew

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:

/root/.digitalocean_password

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:

mysql_secure_installation

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.

@iAmNew

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:

mysql_secure_installation

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:

/root/.digitalocean_password

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.

https://www.digitalocean.com/community/tutorials/how-to-reset-your-mysql-or-mariadb-root-password

Dear SporkWitch,

Thank’s for the reply man. Could you maybe send me a link to the documentation I have to read? Appreciate it man.

Kind regards,

iAmNew

MySQL and MariaDB store their credentials internally, so far as I recall (e.g. it’s not a file you edit directly, it’s an internal database that it stores it in).

The error, however, is the result of improper credentials in your web application. You need to read the documentation for that web application, and provision an account and database for it to use.

So yes, the people telling you to read are right; read the documentation of the things you’re using, it’ll tell you what to do.