Import SQL file by command line in Windows 7
Asked Answered
R

19

39

I want to import an SQL file (size > 500MB) into a database. I have wamp on my PC. Phpmyadmin does not work well with this size. I changed all parameters in php.ini (max_upload_size etc.). But it does not work for me. So I want to import it by command line.

I used these commands for import the file:

mysql -u root -p sysdat < D:\Nisarg\ISPC\Database\sysdat.sql 
mysql -u root -p -D sysdat < D:\Nisarg\ISPC\Database\sysdat.sql
mysql -u root sysdat < D:\Nisarg\ISPC\Database\sysdat.sql -p 

These all are not working.

Retrogressive answered 13/2, 2013 at 5:20 Comment(0)
R
104

Try like this:

I think you need to use the full path at the command line, something like this, perhaps:

C:\xampp\mysql\bin\mysql -u {username} -p {databasename} < file_name.sql

Refer this link also:

http://www.ryantetek.com/2011/09/importing-large-sql-files-through-command-line-when-using-phpmyadminxampp/

Rowboat answered 13/2, 2013 at 5:27 Comment(2)
Tried this and it looks like it's working but I'm not getting any feedback in the command prompt. Are there any flags you can use to recieve feedback about the progress of the operation?Vachill
link page not foundAnnelleannemarie
G
12

If you are using Windows PowerShell you may get the error:

The '<' operator is reserved for future use.

In that case just type the command:

cmd

To switch to the cmd shell and then retype the command and it will work.

c:\xampp\mysql\bin\mysql -u root -p my_database < my_database_dump.sql

To get back to PowerShell type:

exit
Glennisglennon answered 24/7, 2015 at 10:39 Comment(2)
Sir you saved a life in 2022!Louannlouanna
Your are a life saver. ThanksGenipap
S
8

To import database from dump file use:

mysql -u UserName -p Password DatabaseName < FileName.sql 

In wamp

C:\wamp\bin\mysql\mysql5.0.51b\bin>mysql mysql -uroot -p DatabaseName < FileName.sql 
Sacaton answered 24/9, 2013 at 10:25 Comment(0)
O
7

If you have wamp installed then go to command prompt , go to the path where mysql.exe exists , like for me it was : C:\wamp\bin\mysql\mysql5.0.51b\bin , then paste the sql file in the same location and then run this command in cmd :

C:\wamp\bin\mysql\mysql5.0.51b\bin>mysql -u root -p YourDatabaseName < YourFileName.sql
Occur answered 19/1, 2014 at 18:52 Comment(0)
S
3

----------------WARM server.

step 1: go to cmd go to directory C:\wamp\bin\mysql\mysql5.6.17 hold Shift + right click (choose "open command window here")

step 2: C:\wamp\bin\mysql\mysql5.6.17\bin>mysql -u root -p SellProduct < D:\file.sql

in this case
+ Root is username database  
+ SellProduct is name database.
+ D:\file.sql is file you want to import

---------------It's work with me -------------------

Stovepipe answered 4/12, 2014 at 8:43 Comment(0)
B
2

To import database from dump file (in this case called filename.sql)

    use: mysql -u username -p password database_name < filename.sql 

you are on Windows you will need to open CMD and go to directory where mysql.exe is installed. you are using WAMP server then this is usually located in: C:\wamp\bin\mysql\mysql5.5.8\bin (*note the version of mysql might be different)

So you will: cd C:\wamp\bin\mysql\mysql5.5.8\bin

and then execute one of the above commands. Final command like this

    C:\wamp\bin\mysql\mysql5.5.8\bin>mysql -u rootss -p pwdroot testdatabasename < D:\test\Projects\test_demo_db.sql
Bemis answered 12/7, 2014 at 7:19 Comment(1)
This is wrong syntax. You should not use space between -p and password.Pear
S
2

TRY THIS

  C:\xampp\mysql\bin\mysql -u {username} -p {databasename} < {filepath}

if username=root ,filepath='C:/test.sql', databasename='test' ,password ='' then command will be

  C:\xampp\mysql\bin\mysql -u root  test < C:/test.sql
Squeal answered 19/5, 2015 at 13:48 Comment(0)
L
2

I use mysql -u root -ppassword databasename < filename.sql in batch process. For an individual file, I like to use source more because it shows the progress and any errors like

Query OK, 6717 rows affected (0.18 sec)
Records: 6717  Duplicates: 0  Warnings: 0
  1. Log in to MySQL using mysql -u root -ppassword
  2. In MySQL, change the database you want to import in: mysql>use databasename;

    • This is very important otherwise it will import to the default database
  3. Import the SQL file using source command: mysql>source path\to\the\file\filename.sql;

Laliberte answered 23/4, 2018 at 23:35 Comment(0)
R
1

Try this it will work. Do not enter password it will ask one you execute the following cmd

C:\xampp\mysql\bin\mysql -u xxxxx -p -h localhost your_database_name < c:\yourfile.sql
Rand answered 16/4, 2014 at 11:32 Comment(0)
Z
1

To import SQL file what works for me

For Wamp-Server

  1. Find mysql in wamp. In my computer it's location is "C:\wamp64\bin\mysql\mysql5.7.21\bin"

Open cmd and once you get inside bin you have to write " mysql -uroot -p database_name < filename.sql"

remember to put sql file under bin.

in nutshell you have to do this:-

C:\wamp64\bin\mysql\mysql5.7.21\bin>mysql -uroot -p database_name < filename.sql

After this, it will ask for the password, mine password was nothing(BLANK).

hope it helps someone.

Zahn answered 10/7, 2018 at 17:2 Comment(0)
M
1

If you are using XAMPP SERVER on your local machine, follow the below steps to import the table inside your database

  1. Create a database where you want to import those tables using cmd (either through PhpMyAdmin or using the command line)

  2. Go to the command line by going to Start -> Run and typing in cmd. Change the directory to the MySQL bin directory. It will be like if you have used C drive to install this application C:\Windows\System32\cmd.exe OR Go to your MySQL bin directory inside XAMPP/WAMP/LAMP & there in the address bar just type cmd and press ENTER

  3. In cmd the directory will be displayed like this C:\xampp\mysql\bin> Then type the below command:

mysql -u {user_name} -p {user_password} {database_name} < file_path.sql

OR If you do not have set the password then use below command:

mysql -u {user_name} {database_name} < file_path.sql

ANOTHER METHOD: Follow up to above point 2 & followed by given steps below:

Step 01:

mysql -u {user_name} -p {user_password}

example: C:\xampp\mysql\bin>mysql -u root -p password

Step 02:

use {database_name}

example: MariaDB [(none)]> use database_name

Step 03:

Provide the source from where the file will be imported

source file_path.sql

example: MariaDB [database_name]> source sql_file.sql

The output will be as attached image:

enter image description here

Hope it will work, Enjoy!!

Mcswain answered 29/7, 2021 at 12:23 Comment(0)
M
0

Related to importing, if you are having issues importing a file with bulk inserts and you're getting MYSQL GONE AWAY, lost connection or similar error, open your my.cnf / my.ini and temporarily set your max_allowed_packet to something large like 400M

Remember to set it back again after your import!

Menticide answered 3/4, 2014 at 17:23 Comment(0)
P
0

mysql : < (for import) > (for export)

in windows, you want to take backup or import the sql file, then goto cmd prompt type the address were the mysql is installed eg:C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin> after this

C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin> mysql -u UserName -p Password DatabaseName < FileName.sql (import)

C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin> mysql -u UserName -p Password DatabaseName > FileName.sql (export)

Periosteum answered 16/5, 2015 at 12:17 Comment(0)
F
0

If those commands don't seems to work -- I assure you they do --, check the top of your sql dump file for the use of :

CREATE DATABASE {mydbname}

and

USE {mydbname}

The last parameter {mydbname} of the mysql command can be misleading : if CREATE DATABASE an USE are in your dump file, the import will in fact be done in this database, not in the one in the mysql command.

The mysqldump command that will prompt CREATE DATABASE and USE is :

mysqldump.exe -h localhost -u root --databases xxx > xxx.sql

Use mysqldump without --databases to leave out CREATE DATABASE and USE :

mysqldump.exe -h localhost -u root xxx > xxx.sql
Freshen answered 21/5, 2015 at 19:5 Comment(0)
B
0

If you don't have password you can use the command without

-u

Like this

C:\wamp>bin\mysql\mysql5.7.11\bin\mysql.exe -u {User Name} {Database Name} < C:\File.sql

Or on the SQL console

mysql -u {User Name} -p {Database Name} < C:/File.sql
Bramblett answered 25/7, 2016 at 12:51 Comment(0)
M
0

First open Your cmd pannel And enter mysql -u root -p (And Hit Enter) After cmd ask's for mysql password (if you have mysql password so enter now and hit enter again) now type source mysqldata.sql(Hit Enter) Your database will import without any error

Mordvin answered 24/4, 2017 at 10:49 Comment(1)
Welcome to SO! Please read this how-to-answer. Format codes would definitely help.Metropolis
A
0

If you are running WampServer on your local machine, import means restoring the dump file that you have (in sql format)

Here are the steps

  1. Go to command line by going to Start -> Run and typing in cmd.
  2. Change the directory to Mysql bin directory. It will be like

    c:\wamp\bin\mysql\mysql5.7.14\bin

  3. It would be better to keep the dump file in the above directory( we can delete, after restoration)

  4. Hope you have created the database (either through phpMyadmin or using command line)

  5. Then type the command mysql.exe -u root -p databasename < filename.sql

Please note the difference, it is 'mysql.exe' not 'mysql'

Aldarcie answered 12/2, 2018 at 10:32 Comment(0)
P
0

Just remove space between -p and your password. like this:

C:\xampp\mysql\bin\mysql -u {username} -p{databasename} < file_name.sql

Procyon answered 29/3, 2022 at 8:23 Comment(0)
J
0

Follow below steps for importing database with getting feedback in the command prompt.

  • Step 1: go to your mysql bin path C:\xampp\mysql\bin

  • Step 2:

    mysql -u {username} -p -v {databasename} < "file_name.sql"
    

Note: -v will show you insert logs in cmd

Jumbo answered 24/7, 2022 at 14:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.