How do I access MySQL instance created by LAMP image when creating droplet?

September 30, 2014 3.8k views

I can't figure out how would I access my MySQL instance that has been created as a part of one-click LAMP installation when creating droplet.

Specifically, where will I find the hostname, username, password, port for connecting to MySQL?

Can I connect to it using MySQL Workbench client installed on my local machine? Or will I have to connect through command line? If yes, how?

1 Answer

By default, MySql is only accessible on the local host as it's bound to You can see this in it's configuration file:

# cat  /etc/mysql/my.cnf | grep bind
bind-address        =

If you comment out that line and restart MySql (sudo service mysql restart), it will become available remotely.

When you first log on to the server, the root MySql password is displayed:

Thank you for using DigitalOcean's LAMP Application.
Your web root is located at /var/www/html and can be seen from
The details of your PHP installation can be seen at
Your MySQL root user's password is 68aKdJVbQx
You are encouraged to run mysql_secure_installation to ready your server for production.

Especially if you plan on allowing remote access to the database, run mysql_secure_installation in order to disable remote access via the root account. After you've done this, you can create a user with remote access.

CREATE USER 'your_user'@'your_local_IP' IDENTIFIED BY 'new_password';
GRANT ALL PRIVILEGES ON 'your_database'.* TO 'your_user'@'your_local_IP';

Replace the highlighted values with the ones you need.

So to answer your question, if you want to allow remote access you must set the username and password yourself. The "host" is the IP address of your server and the port is 3306.

  • Hi. Thanks for the answer.

    When you say, 'yourlocalip', you don't mean the IP address of my digital ocean host right?
    Do I have to create separate users for all local ips I am going to access this database from? Can't I write a command so that I can use an username-password to access the database from any machine?

Have another answer? Share your knowledge.