Hosting » DigitalOcean » How do I create a DigitalOcean MySQL database?

How do I create a DigitalOcean MySQL database?

Last updated on September 25, 2022 @ 2:33 pm

Setting up a MySQL database on DigitalOcean is a quick and easy process. To get started, create a new Droplet and enter the following command into your terminal:

sudo apt-get install mysql-server

Once the installation is complete, you will need to create a MySQL user and database. To do this, enter the following command into your terminal:

mysql -u root -p

You will then be prompted to enter the MySQL root password. Once you have entered the password, you will be presented with the following screen:

To create a new database, enter the following command:

CREATE DATABASE mydbname;

You will then be prompted to enter the database name and password. After you have entered the information, hit enter to create the database.

PRO TIP: Before proceeding with the steps below, please note that DigitalOcean recommends using a managed database service like MariaDB to avoid having to maintain your database server. Additionally, setting up a remote database server is beyond the scope of this article. If you would like to use a remote database server, please follow the link below for more information:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-remote-database

To connect to the newly created database, enter the following command:

mysql -u mydbname -p

You will then be prompted to enter the MySQL root password. After you have entered the password, you will be presented with the following screen:

To connect to the database, enter the following command:

SELECT * FROM mydbname;

You will then be able to issue commands such as SELECT * FROM table to access the contents of the database.

Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.