0% found this document useful (0 votes)
28 views

How To Create and Manage Databases in MySQL and MariaDB On A Cloud Server - DigitalOcean

This document provides instructions on how to create and manage databases in MySQL and MariaDB on a cloud server. It covers how to sign in, create, view, change, and delete databases as well as manage the data within them.

Uploaded by

Dan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

How To Create and Manage Databases in MySQL and MariaDB On A Cloud Server - DigitalOcean

This document provides instructions on how to create and manage databases in MySQL and MariaDB on a cloud server. It covers how to sign in, create, view, change, and delete databases as well as manage the data within them.

Uploaded by

Dan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

6/25/23, 9:07 PM How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server | DigitalOcean

New! Premium CPU-Optimized Droplets are now available. We're Blog Docs Get Contact
Learn more -> hiring Support Sales

Tutorials Questions Learning Paths For Businesses Product Docs Social Impact

// Tutorial //

How To Create and Manage Databases in MySQL and

MariaDB on a Cloud Server

Published on July 29, 2013


MySQL MariaDB

By Justin Ellingwood

https://www.digitalocean.com/community/tutorials/how-to-create-and-manage-databases-in-mysql-and-mariadb-on-a-cloud-server 1/12
6/25/23, 9:07 PM How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server | DigitalOcean

What are MySQL and MariaDB?

MySQL and MariaDB are relational database management systems. These tools can be
used on your VPS server to manage the data from many different programs. Both
implement forms of the SQL querying language, and either can be used on a cloud server.
This guide will cover how to create a database using these tools. This is a fundamental skill
needed to manage your data in an SQL environment. We will also cover several other
aspects of database management.
For the purposes of this guide, we will be using an Ubuntu 12.04 server on a small droplet.
However, everything should translate directly to other distributions.
How to Create a Database in MySQL and MariaDB

To begin, sign into MySQL or MariaDB with the following command:


mysql -u root -p

Enter the administrator password you set up during installation. You will be given a
MySQL/MariaDB prompt.
We can now create a database by typing the following command:
CREATE DATABASE new_database;

Query OK, 1 row affected (0.00 sec)

To avoid errors in the event that the database name we've chosen already exists, use the
following command:
CREATE DATABASE IF NOT EXISTS new_database;

Query OK, 1 row affected, 1 warning (0.01 sec)

The warning indicates that the database already existed and no new database was
created.
https://www.digitalocean.com/community/tutorials/how-to-create-and-manage-databases-in-mysql-and-mariadb-on-a-cloud-server 2/12
6/25/23, 9:07 PM How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server | DigitalOcean

If we leave the "IF NOT EXISTS" option off, and the database already exists, we will receive
the following error:
ERROR 1007 (HY000): Can't create database 'other_database'; database exists

How to View Databases in MySQL and MariaDB

To view a list of the current databases that you have created, use the following command:
SHOW DATABASES;

+--------------------+ | Database | +--------------------+ | information_schema | |


mysql | | new_database | | other_database | | performance_schema | +------------------
--+ 5 rows in set (0.00 sec)

The "information_schema", "performance_schema", and "mysql" databases are set up by


default in most cases and should be left alone unless you know what you are doing.
How to Change Databases in MySQL and MariaDB

Any operations performed without explicitly specifying a database will be performed on the
currently selected database.
Find out which database is currently selected with the following command:
SELECT database();

+------------+ | database() | +------------+ | NULL | +------------+ 1 row in set


(0.01 sec)

We have received a result of "null". This means that no database is currently selected.
To select a database to use for subsequent operations, use the following command:
USE new_database;

Database changed

https://www.digitalocean.com/community/tutorials/how-to-create-and-manage-databases-in-mysql-and-mariadb-on-a-cloud-server 3/12
6/25/23, 9:07 PM How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server | DigitalOcean

We can see that the database has been selected by re-issuing the command we ran
previously:
SELECT database();

+--------------+ | database() | +--------------+ | new_database | +--------------+ 1


row in set (0.00 sec)

How to Delete a Database in MySQL and MariaDB

To delete a database in MySQL or MariaDB, use the following command:


DROP DATABASE new_database;

Query OK, 0 rows affected (0.00 sec)

This operation cannot be reversed! Make certain you wish to delete before pressing
enter!
If this command is executed on a database that does not exist, the following error message
will be given:
DROP DATABASE new_database;

ERROR 1008 (HY000): Can't drop database 'new_database'; database doesn't exist

To prevent this error, and ensure that the command executes successfully regardless of if
the database exists, call it with the following syntax:
DROP DATABASE IF EXISTS new_database;

Query OK, 0 rows affected, 1 warning (0.00 sec)

The warning indicates that the database did not exist, but the command executes
successfully anyways.

https://www.digitalocean.com/community/tutorials/how-to-create-and-manage-databases-in-mysql-and-mariadb-on-a-cloud-server 4/12
6/25/23, 9:07 PM How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server | DigitalOcean

Conclusion

You now have the basic skills necessary to manage databases using MySQL and MariaDB.
There are many things to learn, but you now have a good starting point to manage your
databases.
If you'd like to learn about creating users and managing permissions in MySQL, see our
guide on How To Create a New User and Grant Permissions in MySQL. Alternatively, to
learn about tables in MySQL and MariaDB, click here.
By Justin Ellingwood

Thanks for learning with the DigitalOcean Community. Check out our offerings for
compute, storage, networking, and managed databases.
Learn more about us ->

About the authors

Justin Ellingwood Author

Still looking for an answer? Ask a question


Search for more help

https://www.digitalocean.com/community/tutorials/how-to-create-and-manage-databases-in-mysql-and-mariadb-on-a-cloud-server 5/12
6/25/23, 9:07 PM How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server | DigitalOcean

Was this helpful? Yes No

Comments
5 Comments

Leave a comment...

This textbox defaults to using Markdown to format your answer.


You can type !ref in this text area to quickly search our full set of tutorials, documentation
& marketplace offerings and insert the link!
Sign In or Sign Up to Comment

ericdaadeb8a75406dd9bed08e • June 4, 2017


Great tutorials. I have managed to get mariadb installed and created a user and a
database, but when I try to enter that information into an owncloud setup, I get a
sql connection error. ???
Reply

Kamal Nasser • August 11, 2014


@everest.deth: Your MySQL root password can be found in /etc/motd.tail :
cat /etc/motd.tail Copy

https://www.digitalocean.com/community/tutorials/how-to-create-and-manage-databases-in-mysql-and-mariadb-on-a-cloud-server 6/12
6/25/23, 9:07 PM How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server | DigitalOcean

Show replies Reply

everestdeth • August 9, 2014


Hi There,
I actually didn’t set up MySql myself, as I built the droplet with LAMP already on it.
What would be my password?
Reply

Kamal Nasser • August 13, 2013


@subratmca85: Do you have an existing Wordpress site or do you want to create
one from scratch?
If it’s an already existing one:
https://www.digitalocean.com/community/articles/how-to-migrate-wordpress-
from-shared-hosting-to-a-cloud-server-with-zero-downtime
If it’s a new one:
https://www.digitalocean.com/community/articles/one-click-install-wordpress-on-
ubuntu-12-10-with-digitalocean
Reply

subratmca85 • August 13, 2013


I am new to cloud server…can anyone plz guide me how to upload my wordpress
site in cloud server and create a database by using MySQL?
also, I don’t have ubuntu…can i go with XP?
Plz help…
https://www.digitalocean.com/community/tutorials/how-to-create-and-manage-databases-in-mysql-and-mariadb-on-a-cloud-server 7/12
6/25/23, 9:07 PM How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server | DigitalOcean

Reply

This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0


International License.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!
Sign up

Popular Topics

Ubuntu
Linux Basics
JavaScript
Python
MySQL
Docker
Kubernetes
All tutorials ->

Free Managed Hosting ->

https://www.digitalocean.com/community/tutorials/how-to-create-and-manage-databases-in-mysql-and-mariadb-on-a-cloud-server 8/12
6/25/23, 9:07 PM How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server | DigitalOcean

Congratulations on unlocking the whale ambience easter egg! Click the whale button in
the bottom left of your screen to toggle some ambient whale noises while you read.
Thank you to the Glacier Bay National Park & Preserve and Merrick079 for the sounds
behind this easter egg.
Interested in whales, protecting them, and their connection to helping prevent climate
change? We recommend checking out the Whale and Dolphin Conservation.
Reset easter egg to be discovered again / Permanently dismiss and hide easter egg

Get our biweekly


newsletter

Sign up for Infrastructure as a


Newsletter.
Sign up ->

Hollie's Hub for Good

Working on improving health and


education, reducing inequality,
https://www.digitalocean.com/community/tutorials/how-to-create-and-manage-databases-in-mysql-and-mariadb-on-a-cloud-server 9/12
6/25/23, 9:07 PM How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server | DigitalOcean

and spurring economic growth?


We’d like to help.
Learn more ->

Become a
contributor

You get paid; we donate to tech


nonprofits.
Learn more ->

Featured on Community

Kubernetes Course Learn Python 3 Machine Learning in Python


Getting started with Go Intro to Kubernetes

DigitalOcean Products

Cloudways Virtual Machines Managed Databases Managed Kubernetes


Block Storage Object Storage Marketplace VPC Load Balancers
https://www.digitalocean.com/community/tutorials/how-to-create-and-manage-databases-in-mysql-and-mariadb-on-a-cloud-server 10/12
6/25/23, 9:07 PM How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server | DigitalOcean

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether
you’re running one virtual machine or ten thousand.
Learn more ->

Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
Email address
https://www.digitalocean.com/community/tutorials/how-to-create-and-manage-databases-in-mysql-and-mariadb-on-a-cloud-server 11/12
6/25/23, 9:07 PM How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server | DigitalOcean

Send My Promo
New accounts only. By submitting your email you agree to our Privacy Policy.

Company
Products
Community
Solutions
Contact

© 2023 DigitalOcean, LLC.

https://www.digitalocean.com/community/tutorials/how-to-create-and-manage-databases-in-mysql-and-mariadb-on-a-cloud-server 12/12

You might also like