How to Create New Database in MySQL/MariaDB Server

MySQL/MariaDB is a popular database management system that is widely used by businesses and organizations to store and manage critical data. Creating a new database in MSQL/MariaDB server is a fundamental task that every database administrator should know how to perform. In this article, i will share a step-by-step guide on how to create a new database in MSQL/MariaDB server. We’ll cover essential topics such as choosing a database name, setting character sets, and granting user privileges. By following this guide, you’ll be able to create a new database in MSQL/MariaDB server quickly and efficiently. Whether you’re a seasoned database administrator or new to MSQL/MariaDB, this article will provide you with the necessary knowledge to create a new database and get started with your data management.

Create New Database in MySQL/MariaDB Server

Prerequisites

  • A server running CentOS or Oracle Linux
  • MySQL/MariaDB root access.

Create New Database in MySQL/MariaDB Server via command line

1. Login to MySQL database using root:

# mysql -u root -p

Example with output :

# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1234567
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

2. To create a database, use the “create database” or “CREATE DATABASE command as follows:

mysql> CREATE DATABASE DATABASE_NAME;

Example below will create a database with the name testdb :

mysql> CREATE DATABASE testdb;
Query OK, 1 row affected (0.15 sec)

Error you will received if a database of the same name already exists, the system will not create a new database.

ERROR 1007 (HY000): Can't create database 'testdb'; database exists

You can avoid this error by using the following command. It only creates the database testdb if a database of that name does not already exist.

mysql> CREATE DATABASE IF NOT EXISTS testdb;

3. Display the databases;

mysql> SHOW DATABASES;

Example output :

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
+--------------------+
5 rows in set (0.00 sec)

Conclusion

Creating a new database in MSQL/MariaDB server is a fundamental task that every database administrator should know how to perform. By following the step-by-step guide provided in this article, you can create a new database quickly and efficiently. Remember to choose a unique database name, set the appropriate character sets, and grant user privileges to ensure that your database is secure and accessible.

See also  How to Delete Database in MySQL/MariaDB

Having a robust database management system is critical for businesses and organizations to store and manage critical information. By creating a new database in MSQL/MariaDB server, you can begin to manage your data effectively and efficiently. We hope this article has provided you with valuable insights and knowledge to create a new database in MSQL/MariaDB server, helping you to get started with your data management.

Leave a Comment