To create a database in MySQL or MariaDB using a Linux terminal, the MySQL or MariaDB application must be installed on the user’s server.
The author here uses MariaDB using the Debian operating system. The usage for the command is the same as in MySQL.
Install MySQL
apt-get updateapt-get install mysql-server
or if you want to install MariaDB the first step is to add the MariaDB repository to sources.list
apt-get install python-software-propertiesapt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943dbadd-apt-repository 'deb http://download.nus.edu.sg/mirror/mariadb/repo/5.5/debian wheezy main'
How to install MariaDB
apt-get updateapt-get install mariadb-server
Follow the next instructions to enter the MySQL / MariaDB username and password
The following command creates a database with the terminal:
1. First log into MySQL / MariaDB.
mysl -u root -p
Enter user password.
2. To create a database, enter the command:
CREATE DATABASE inwepo_tv;
inwepo_tv is the name of the database, this name can be changed as desired.
3. If the error message “ERROR 1007 (HY000): Can’t create database ‘tutorial_database’; Database exists ”means that the same database name was previously created.
The solution can use the command:
CREATE DATABASE IF NOT EXISTS inwepo_tv;
Database created successfully.
4. Enter the following command to view the database that you created:
SHOW DATABASES;
5. To exit MySQL / MariaDB, enter the command:
q
