Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Find MySQL Credentials on One Click LAMP Server

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to locate the MySQL/MariaDB credentials on a server set up with a one-click LAMP stack (for example, from DigitalOcean, Vultr, Linode, or your hosting provider). You’ll learn where the default credentials are stored, how to reset them if needed, and how to connect to the database from the command line. You need SSH access to your server and a user account with sudo privileges.

What You'll Need

  • SSH client (like Terminal on macOS/Linux, or PuTTY on Windows)
  • Server IP address and root or sudo user credentials
  • Basic familiarity with the command line

Step-by-Step

  1. Connect to your server via SSH. Open your terminal and run: ssh root@your_server_ip or ssh user@your_server_ip if you use a non-root user. Enter your password or use your SSH key.
  2. Check for the default credentials file. Many one-click LAMP images store the MySQL root password in a file. Look for these common locations:
    cat /root/.my.cnf
    cat /etc/mysql/debian.cnf
    cat /root/.digitalocean_password (if using DigitalOcean)
    cat /root/.mysql_secret (some older images)
    If you find a file, it will usually contain a line like password="your_password".
  3. Try the default credentials. If no file exists, try common defaults for one-click images: username root and password root, or username root and no password. Run mysql -u root -p and enter the password when prompted.
  4. Access MySQL using sudo. On many LAMP stacks, the root MySQL user can authenticate via the system’s root user. Run sudo mysql (or sudo mariadb for MariaDB). This should log you into the MySQL prompt without a password.
  5. If you are in, reset the root password. Once logged in, run the following SQL commands to set a new, known password:
    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_strong_password';
    FLUSH PRIVILEGES;
    Replace new_strong_password with your own. If you’re using MariaDB, the syntax is the same.
  6. If you can’t get in, skip MySQL authentication. Stop MySQL with sudo systemctl stop mysql (or mariadb). Then start it in safe mode with sudo mysqld_safe --skip-grant-tables &. Connect with mysql -u root, then run the ALTER USER command from step 5. Finally, restart MySQL normally: sudo systemctl restart mysql.
  7. Find credentials for other database users. If you need credentials for a specific application, check the application’s configuration file. For WordPress, look at /var/www/html/wp-config.php; for other apps, search in /var/www/ or /opt/ for files like .env or config.php. Use grep -r "DB_PASSWORD" /var/www/ to search.
  8. Create a dedicated user (optional). For security, create a new MySQL user for your application instead of using root. From the MySQL prompt: CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'securepass'; then GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost'; and FLUSH PRIVILEGES;.

Common Mistakes

  • Looking for a file that doesn’t exist. Not all one-click images store credentials in a file; some use socket authentication.
  • Assuming the MySQL root password is the same as the server root password. They are often different.
  • Using mysql instead of sudo mysql when socket authentication is enabled.
  • Forgetting to flush privileges after changing a password.
  • Editing configuration files without backing them up first.

Tips

  • Always use a strong, unique password for database users. Combine uppercase, lowercase, numbers, and symbols.
  • Store credentials in a password manager or a secure vault, not in plain text files.
  • If you use a control panel (like cPanel or Plesk), the database credentials are usually found under “MySQL Databases” in the panel.
  • Use mysql --help to see all connection options.
  • For security, consider disabling remote root access to MySQL by ensuring only localhost can connect.

Troubleshooting

  • “Access denied for user ‘root’@‘localhost’”: This means your password is wrong or the user uses a different auth plugin. Try sudo mysql first. If that fails, follow the skip-grant-tables method.
  • “Can’t connect to local MySQL server through socket”: MySQL may not be running. Start it with sudo systemctl start mysql (or mariadb).
  • “File not found” for .my.cnf: It’s normal if the file doesn’t exist. Use the sudo method instead.
  • After resetting, apps can’t connect: Update the application’s config file with the new password. Also, ensure you flushed privileges.
  • MySQL won’t start after using skip-grant-tables: Kill the safe process and start normally: sudo pkill mysqld_safe; sudo systemctl start mysql.

Frequently Asked Questions

Where does the one-click LAMP installer store the MySQL password?

It varies. Common locations are /root/.my.cnf, /etc/mysql/debian.cnf, or a file like /root/.digitalocean_password. If none exist, the installer may have set a random password that you can reset via sudo.

Can I reset the MySQL root password without knowing the old one?

Yes. If you have sudo access, you can use sudo mysql to enter the MySQL prompt and run an ALTER USER command. If that doesn’t work, use the skip-grant-tables method to bypass authentication.

Is the MySQL root password the same as the server root password?

No, they are independent. The server root password is for SSH/system login; the MySQL root password is for database access. They are set separately.

What if I’m using MariaDB instead of MySQL?

Most commands are identical. Use sudo mariadb instead of sudo mysql, and the service name is mariadb instead of mysql.

How do I find the database credentials for my WordPress site?

Look in /var/www/html/wp-config.php. The lines define DB_USER, DB_PASSWORD, and DB_HOST. You can view them with cat /var/www/html/wp-config.php.

Can I change the MySQL root password remotely?

It’s possible, but not recommended. You must connect via SSH first, then use the MySQL client locally. Remote root access is often disabled for security.