how to create sql database file in mysql?

Today, We want to share with you mysql create database from sql file.In this post we will show you How to Import an SQL File Into MySQL Database?, hear for import an SQL file using the command line in MySQL we will give you demo and example for implement.In this post, we will learn about Connecting to MySQL from the command line steps with an example.

Create MySQL Database with .SQL File

mysql -u username -p database_name < file.sql

1) Create a file "domain_name_file_v1.sql"

2) Create a database in your DB in which you want to import this file.

3) From command-prompt/terminal, move to the directory where you have created a "domain_name_file_v1.sql".

4) Run the command:

mysql -u username -p password database_name < domain_name_file_v1.sql.

(You can also give the proper path of your file and run this command from anywhere). It might be the case that you don't have a password set for MySQL. If so,

mysql -u username database_name < domain_name_file_v1.sql

will also work.

In your case if you have created a database with name pakainfo and also created a file with name pakainfo.sql in C: drive then run the bellow simple MySQL terminal command:

mysql -u username -p password pakainfo < "C:\pakainfo.sql"

There is another way of importing tables in mysql. You can do it this way as well:

1) Connect your database

2) Type command "use pakainfo;"

3)Type command "source C:/pakainfo.sql"

Creaditd source code:

Import & Export a MySQL database into SQLfile

mysqldump -u DatabaseUser -p DatabaseName > BackupDatabase.sql

A common use of mysqldump is for creating a backup of an entire types of the database:

Create MySQL database with sql file import in a single line

shell> mysqldump DatabaseName > BackupDatabase.sql


shell> mysql DatabaseName < BackupDatabase.sql

Windows command prompt:

mysql -p -u [user] [database] < BackupDatabase.sql


C:\> cmd.exe /c "mysql -u root -p DatabaseName < BackupDatabase.sql"

MySQL command line

mysql> use DatabaseName;
mysql> source backup-file.sql;

Create MySQL Database with .SQL File

To create a MySQL database with a .sql file, you can follow these steps:

Log in to your MySQL server using the command line or a tool like phpMyAdmin.

Create a new database using the CREATE DATABASE statement. For example:


Switch to the new database using the USE statement. For example:

USE mydatabase;

Import the .sql file into the database using the source command. For example:

source /path/to/your/file.sql;

Make sure to replace /path/to/your/file.sql with the actual path to your .sql file.

Wait for the import process to finish. Depending on the size of the .sql file and the performance of your server, this may take some time.

Once the import process is complete, your MySQL database should contain all the tables, data, and other objects defined in the .sql file.

Note: Before importing the .sql file, make sure that it does not contain any syntax errors or other issues that could cause problems during the import process. You can use a tool like MySQL Workbench to check the syntax of your .sql file before importing it.

I hope you get an idea about Import SQL file into mysql.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment