20
votes

I have file.sql, and I want to restore it. I found this command:

mysql -u username -p database_name < file.sql

Where should I put 'file.sql' in file system? I'm using Windows and XAMPP. Thank you.

*) The dump file is 3GB++

9
For me worked this solution: stackoverflow.com/a/25724087/7809915.M14

9 Answers

22
votes

You can put it anywhere, where there is enough diskspace available of course.

A good place for this would be either /tmp (on linux or similar) or c:\temp (on windows or similar)

But assuming you use that exact line you need to change your working directory to that which holds the file.

cd /path/where/sql/file/is

And then

mysql -u username -p database_name < file.sql

If you don't have the mysql bin in your PATH you might want to run

/path/to/mysql/bin/mysql -u username -p database_name < file.sql

Or temporarily put the file.sql in the mysql bin directory (not recommended)

Another possible scenario is to point to the file in the filesystem like this

mysql -u username -p database_name < /path/where/sql/file/is/file.sql

PS. If you're on windows you might wanna change the forward slashes to backslashes.

5
votes

You can put anywhere in the system but consider to change the command also

mysql -u username -p database_name < /somepath/file.sql
5
votes

Type the following command to import sql data file:

$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql

In this example, import 'data.sql' file into 'blog' database using vivek as username:

$ mysql -u sat -p -h localhost blog < data.sql

If you have a dedicated database server, replace localhost hostname with with actual server name or IP address as follows:

$ mysql -u username -p -h 202.54.1.10 databasename < data.sql

OR use hostname such as mysql.cyberciti.biz

$ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql

If you do not know the database name or database name is included in sql dump you can try out something as follows:

$ mysql -u username -p -h 202.54.1.10 < data.sql

Refer: http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html

3
votes

The best option will be

1) open the command prompt by Start -> Run -> Command or anyway 2) change you directory where the file.sql is saved say C:\temp\file.sql so your command prompt should look like

C:\temp> 

3) now try these command

mysql -u root -p database_name < file.sql
3
votes
Import Database
1. Go to drive
command: d:
2. Mysql login
command: c:\xampp\mysql\bin\mysql -u root -p
3. Will ask for pwd: enter it
pwd
4. Select db
use DbName;
5. Provide file name
\. G:DbName.sql
2
votes

When I execute the answers of this thread, it returns 'mysql' is not recognized as an internal or external command, operable program or batch file..

Turned out that I have to execute mysql.exe first in xampp/mysql/bin folder, and the dump file path is relative to this bin folder. I put mine in there, and it worked.

Thanks all.

1
votes

you need to point to the location of your file using:

mysql -u username -p database_name < drive:\\path_to_your_file\file.sql
0
votes

As an alternate, try to restore the dump with a Restore or with an Execute Large Script Wizard Wizard.

There is a command-line support.

Backup or restore

-1
votes

You can restore the dump using phpmyadmin as well but you have to sure that it must be .sql file.

The second way is if you are linux user than use the command line to restore the dump file.

mysql> mysql -uuser_name -ppassword table_name < /path/to/dump_file.sql