how to create sql database file in mysql?

Rate this post

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.

Read Also:  php remove non numeric - How to remove non-alphanumeric characters in PHP stirng?

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”

Read Also:  How to add custom jquery image validation?

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

Free Live Chat for Any Issue


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

MySQL command line

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


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.