Not sure what to do when in the console to access the database.

Posted December 1, 2015 12.7k views
UbuntuWordPressDigitalOcean 1-Click Apps Marketplace

New to this, I’m trying to set up a wordpress site, I have the droplet made, and I think everything set up for it, but on the wordpress installation when everything was done I think I changed the site address url, causing an issue of the page not existing anymore.

I know how to change it, (I think) but I need to access the database. I’m actually not exactly sure what to do when I get there.

I was also told to use phpmyadmin, but again not exactly sure how to use that in conjuction with this droplet.

1 comment
  • Hi!

    To access the database via command line (you’re using MySQL, right?), just type the following:

    mysql -h localhost -u YOUR_USER YOUR_DATABASE -p

    -h: your host (if you are not using localhost, just replace it with the address/IP of your MySQL server)
    -u: your database username
    -p: tells MySQL that you want to log in using a password

    And press enter, so you’ll be prompted to input your database password.

    If everything is ok, you’ll see something like:

    mysql >

    Here you can input your queries (SELECT, INSERT, SHOW TABLES, etc) normally.

    To install/use PHPMyAdmin, you can simply follow this cool tutorial:

    by Justin Ellingwood
    While many users require access to a database management system like MySQL, not all users feel comfortable interacting with the MySQL prompt on a daily basis. In this guide, we'll discuss how to install and secure phpMyAdmin, a web management interface for MySQL, on an Ubuntu 14.04 server.

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.

Submit an Answer
2 answers

You’ve got a couple options…

First, make a note of your MySQL root password. If you’re using the WordPress one-click image this is displayed in the MOTD when you log in via ssh.

1.) Using the CLI
The command line MySQL client will allow you to update the web address info for WordPress by doing the following:

mysql -uroot -p

You will now be prompted for your MySQL root password.

Once you enter it you will be in the MySQL client shell (NOTE: All commands in the MySQL CLI must end with a semicolon “;”).

use wordpress;

This tells mysql that you want to work with the database named “wordpress” (this is the default on the one-click image)

UPDATE wp_options set option_value = "" where option_name = "siteurl" OR option_name = "home";

This query will update the siteurl and home fields in the wp configuration in MySQL to the URL you provide.

Once you’re done you can exit the MySQL client by typing:


2.) Installing PHPMyAdmin (This assumes WordPress is running on Apache and not nginx or another web server)

apt-get update
apt-get install phpmyadmin

During the process you’ll be prompted for the MySQL root password and to select a web server (Apache) to auto-configure. Once this has completed you can access phpmyadmin on your droplet at /phpmyadmin

I’ve tested both these options against a fresh WordPress One-Click droplet so you should be all set. Personally I would recommend going with the CLI option over installing phpmyadmin unless you will be working directly with the DB a lot.


Another option would be to use Adminer. It’s free, like phpMyAdmin, though instead of a thousand files (nothing against phpMyAdmin, it works, it’s just bulky!), it’s a single file and you’d upload it to your server just like you would a normal PHP file (to a web accessible directory).

Once you’ve uploaded it, browse over to the URI where it’s located and enter in your MySQL database credentials (for your WordPress installation). Once authenticated, you’ll be able to access your database and make the changes needed.

Note: It’s a good idea to rename the file (to something that doesn’t resemble adminer.php) and once your done, delete it (for security) or setup another layer of authentication so that you’re not hit with scanners/bots trying to find it (I see them scanning IP’s and domains often). There’s also a WordPress plugin available for it here, so once you’re back up and running, you can install that plugin and administer your database from the WordPress admin.

  • I have it installed here, but I’m not exactly sure what to do with it. I have a feeling there is a step I’m missing.

    -I downloaded / purchased a droplet on Digital Ocean
    -Selected the one-click wordpress option
    -downloaded wordpress
    -installed wordpress via Digital Ocean

    • @Yuriohs

      You would need to use SFTP to login to the server and upload your content to your web directory (such as Adminer). I’m not 100% sure how DigitalOcean has their one-click images setup, though if a root password was e-mailed to you, then you would use this password, your Droplet’s public IP Address and the username root to login. From there, you would navigate to your web root directory (/var/www/, /var/www/html or a directory in /home are the most common directories, though it could be another. I would check these first).

      You would use a program such as FileZilla to login via SFTP (making sure you choose SFTP instead of FTP as FTP won’t be enabled as it’s actually a less secure option for logging in).


      • Would FTP Core work with this? I’ve had problems with FileZIlla in the past but I will try your steps.

      • Ok, so I tried this, and it says Connection attempt failed with “EAI_NONAME - Neither nodename nor servname provided, or not known”. then could not connect to the server.

        I tried this with the IP from my email, as well as the root and the password (which I changed)

        This was the same result for FTP Core.