Shubham S Nimje logo
Shubham Nimje
Database

How to Import MySQL Database or SQL File

How to Import MySQL Database or SQL File
1 min read
#Database

How to Import MySQL Database or SQL File

This guide equips you with the essential commands to manage your MySQL databases. Learn how to import an existing SQL file or create a backup by exporting your database as an SQL file.

Access MySQL with Root User

To access MySQL with the root user, use:

mysql -u root -p

Create a New Database

To create a new database, use:

CREATE DATABASE Database_name;

For example:

CREATE DATABASE osmsdb;

Access the Newly Created Database

To switch to the newly created database, use:

USE Database_name;

For example:

USE osmsdb;

Import a Database or SQL File

To import a database from an SQL file, use:

source sql_file_path

For example:

source /var/myimporteddb/osmsdb.sql

Export MySQL Database as SQL File

To export a MySQL database to an SQL file, use:

mysqldump -u db_user_name -p Database_Name > File_Path/File_Name.sql

For example:

mysqldump -u root -p dps > /var/myexporteddb/dps.sql