How to create a database from an SQL file in MariaDB

In this MariaDB tutorial, we will discuss, how to create a database from an SQL file in MariaDB.

  • MariaDB create database from sql file Windows
  • MariaDB create database from SQL file Ubuntu and Linux

MariaDB create database from sql file windows

In MariaDB, we can create the database from the SQL file, this SQL file contains the command to create the database. The SQL file is saved with extension (xyz.sql).

Let’s write the SQL command to create the database in the file, open Notepad text editor.

CREATE DATABASE sqldatabase;
create database from SQL file in mariadb
MariaDB sql file

Open the HeidiSQL application and Load the SQL file by clicking on the Folder icon below the menu section.

MariaDB create database from sql file
MariaDB HeidiSQL sql file loading

After performing the above steps, a MariaDB: Confirm dialogue will appear to select the encoding method. Then select Yes.

MariaDB create database from sql file
MariaDB MariaDB confirm

Then click on the play icon below the menu section to execute the command in the SQL file.

How to create database from sql file in MariaDB
MariaDB create database from sql file windows

After clicking on Execute button, it will create the database in the current session.

This is how to create a database from an SQL file in MariaDB in Windows.

Read MariaDB Insert Into

MariaDB create database from SQL file Ubuntu and Linux

Ubuntu users follow this section to create a database in MariaDB from sql file using the below steps.

Now open the gedit editor on Ubuntu and write the below line in that file. Save the file with the name us.sql.

MariaDB create database from SQL file Ubuntu and Linux
MariaDB united state database

Open the MariaDB prompt in the terminal using the below command and enter the password if it asks.

mysql -u root -p

After login into the MariaDB shell prompt, Create the new database as us_database.

CREATE DATABASE us_database;

Then exit from the MariaDB shell or return to the Ubuntu terminal.

create database from SQL file in mariadb
MariaDB us database

In the Ubuntu terminal, write the below command to create a database from an SQL file.

mysql -u root -p us_database < us.sql

Now again log into the MariaDB shell prompt and run the below command to show the created database that is united_states.

SHOW DATABASES;
MariaDB create database from SQL file ubuntu
MariaDB create database from SQL file ubuntu

The output shows that created database as united_states in the pink color.

This is how to create a database from SQL file Ubuntu and Linux in MariaDB.

You may like the following MariaDB tutorials:

So in this MariaDB tutorial, we have learned about the “MariaDB create a database from sql file” and covered the following topics.

  • MariaDB create database from sql file Windows
  • MariaDB create database from SQL file Ubuntu and Linux