Skip to content

Import & Export

Before we move on to the next chapter, let's do a quick introduction on how you can import data into your database and export data out of your database.

SQL Files

When you or anyone else would export data out of your database, that data would be stored in a file that has an extension of .sql. For example: mygamestore.sql.

This SQL file contains normal sql statements and you can even open the file and view it. It creates the required tables and inserts data into the tables with reqular SQL commands.

Import

Before you import the database into your MariaDB, you need to first make sure that you have an empty database created for the database that you want to import:

MySQL
CREATE DATABASE databasename;

Importing data can be done outside of your mysql / mycli CLI interface, so if you are currently connected to your database, you need to exit from it first. Then, on the normal unix command line interface, this kind of command can be ran to import a sql file into your database:

MySQL
sudo mysql DATABASENAME < FILENAME.sql

If you need to pass in your mysql username, you can pass it with the -u command (in this example the user root is used):

MySQL
sudo mysql DATABASENAME < FILENAME.sql

Export

Like import, this needs to be again done outside of your mysql / mycli CLI interface, so if you are currently connected to your database, you need to exit from it first. Then, on the normal unix command line interface, this kind of command can be ran to export database into a SQL file:

MySQL
sudo mysqldump DATABASENAME > FILENAME.sql

If you need to pass in your mysql username, you can pass it with the -u command (this in example the user root is used):

MySQL
sudo mysqldump DATABASENAME > FILENAME.sql

Learn More