How to import, export, and create a database in MySQL or MariaDB
Create a new database in MySQL or MariaDB
First login to MySQL shell or MariaDB in putty using the below command.
mysql -u root -p
Create new database
mysql> create database new_website;
Check your database create or not use
mysql> show databases;
List of all databases will show in tables format.
Export MySQL or MariaDB database
mysqldump -u username -p database_name > data-dump.sql;
for example
mysqldump -u root -p new_website > ~/backup-database.sql;
~/ its use for export SQL file in root directory.
Import MySQL or MariaDB database
Create new database
mysql> create database new_website;
import your database.sql file database into newly create database
mysql -u [username] -p newdatabase < [database name].sql
mysql -u root -p new_website < ~/backup-database.sql;
SQL script for import SQL file for import SQL data into database
mysql> use db_name; mysql> source ~/file_name.sql;