Terminal: MySQL password saved in directory but received an error that it doesn't exist?

April 25, 2017 785 views
PHP MySQL LAMP Stack Networking Ubuntu

In Terminal, I run the code: mysql_secure_installation, then it asks me for this:

Enter current password for root (enter for none):

It said earlier: The passwords for MySQL have been saved to: /root/.digitalocean_password

So I typed this in: cat /root/.digitalocean_password to retrieve that password.

But then I got this: cat: /root/.digitalocean_password: No such file or directory

I'm really lost. How do I get the MySQL password if I get the error of "No such file or directory?" All help is appreciated, thanks

1 Answer

Hi @confused5000

I've just tried to spin up a LAMP 16.04 (on NYC2), and it shows the password in that file.
If you run this:

ls -la /root/

You should get a list of 4 files and 2 directories:

.bashrc
.cache
.cloud-locale-test.skip
.digitalocean_password
.profile
.ssh

Otherwise you can reset the MySQL root password by following this tutorial:
https://www.digitalocean.com/community/tutorials/how-to-reset-your-mysql-or-mariadb-root-password

Forgetting passwords happens to the best of us. If you forget or lose the root password to your MySQL or MariaDB database, you can still gain access and reset the password if you have access to the server and a sudo-enabled user account. This tutorial will cover how to...
  • @hansen Sorry for the ignorance, but I'm a little confused. I ran the code ls -la /root/ on Terminal but I still get the error of No such file or directory. Also, I didn't read the last line of the code but it says that I should leave the password blank if it's never been set, and I never set a password.

    In order to log into MySQL to secure it, we'll need the current
    password for the root user.  If you've just installed MySQL, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.
    

    Then it asks me for that password:

    Enter current password for root (enter for none): 
    

    So since I didn't set a password I just hit the "enter" button, but then I get this error:

    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
    
    

    I'm still lost, this is confusing

    • @confused5000
      Then you are not logged in as root in SSH. When you write Terminal, I'm guessing you're using OSX, but are you connecting to the server via SSH before running the commands?
      If you are connected to the server, then try:

      sudo cat /root/.digitalocean_password
      
      • @hansen The issue is I can't connect to the server. This is how I connect to the server right?:

        MACs-MBP:~ MAC$ ssh root@107.170.60.7
        

        But I'm getting this instead:

        Permission denied (publickey).
        

        I've been following online tutorials on what to do, so I've had to reset my public and private keys many times over. That's probably why I'm getting the "Permission denied" error because it doesn't recognize the key. So now I have to change the key on my DigitalOcean Droplet but there is no explanation on how to do that online. I appreciate you helping, I'm still stuck.

      • @hansen Sorry forgot to mention but that IP address 107.170.60.7 I mentioned is the IP address that was given to me on my DigitalOcean Droplet for Ubuntu LAMP on 14.04.

        • @confused5000 Okay, if you have never used this droplet I would recommend doing a rebuild and starting over completely.
          Which tutorials have you been following? The ones on this site or random places on the internet?

Have another answer? Share your knowledge.