Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use MySQL's source command to import large files in windows

I have a large (~150mb) sql file that I am trying to import. It is too large to do it through PHPMyAdmin even splitting it into many pieces and it is too large to import through a php script as it times out after 30 seconds of processing the script. So I'm looking for how to directly import the file from MySQL command line.

Searching online shows that I want to either use database_name < file_name.sql or source file_name.sql but I can't get either of these to work.

Using < gives the generic MySQL syntax error while using source give a slightly more promising failed to open file 'file_name.sql', error: 2 so I am inclined to think that the source command is on the right track.

I am in windows and am using xampp as a localhost server (note I'm only trying to import this file on the localhost so that I can execute the sql). I've tried placing the file in xampp\mysql\bin and xampp\mysql\data\database_name.

Any suggestions of how to import this .sql file into MySQL either from the MySQL command line or by any other means would be greatly appreciated.

like image 951
Daniel Nill Avatar asked May 28 '11 18:05

Daniel Nill


People also ask

How do I import a large SQL file into administrator?

Ok you use PHPMyAdmin but sometimes the best way is through terminal: Connect to database: mysql -h localhost -u root -p (switch root and localhost for user and database location) Start import from dump: \. /path/to/your/file. sql.

What does source command do in MySQL?

SQL Data Source mode provides the commands to create or modify an SQL data source configuration. To enter the mode, use the Global sql-source command. To delete an SQL data source, use the Global no sql-source command.


2 Answers

On Windows this should work (note the forwardslash and that the whole path is not quoted and that spaces are allowed)

USE yourdb;

SOURCE D:/My Folder with spaces/Folder/filetoimport.sql;

like image 31
Valentin Despa Avatar answered Oct 07 '22 00:10

Valentin Despa


With xampp 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 
like image 186
Femi Avatar answered Oct 06 '22 23:10

Femi