views:

1438

answers:

3

I'm trying to move a MySQL database from a Linux machine to one running Windows Vista. (I know, that seems the wrong direction, never mind why I want to do this.) Using mysqldump, I've obtained an .sql file, which I have moved to the Windows machine. What next?

If I were moving to another Linux machine, one could do this sort of thing:

mysql -u username -p databasename < dumpfile.sql

Does anyone know of an analogous invocation that works from the Windows command line? Or are there tools to accomplish this?

Edit: When I try this type of command from the Windows command line, I get:

'mysql' is not recognized as an internal or external command . . .

Maybe I just don't know in which directory I should be, but I haven't found one that works.

Edit #2 I've also tried

mysql>  source C:\Stuff\dumpfile.sql

That gave:

Failed to open file 'C:\Stuff\dumpfile.sql', error: 2
+3  A: 

This same type of command should work in windows as well as Linux. Have you tried running this command? What type of error messages are you getting.

I just tested on my local machine with MySQL on Windows XP. The only reason I could see this not working, is that MySQL isn't on your path. If it isn't in your path, you need to specify the whole path of the MYSQL executable, or run it from the directory it's stored in. You could also add the executable to the path if you plan to use the MySQL executable on a regular basis.

Kibbee
I'm sure I seem like a real rube, but I can't find my MySQL executable. Any idea?
FarmBoy
+1  A: 

If you don't mind doing it interactively, you can use the source command in the mysql shell, followed by the file name. Otherwise, I believe that Kibbee is right about pipes working in cmd.exe.

Dana the Sane
A: 

If you get an 'error 2' is because the comand is been executed, so it's not because MysQL is not been found.

The error 2 is because you should use this path: 'C:/Stuff/dumpfile.sql' instead of 'C:\Stuff\dumpfile.sql'

You could also try 'C:\\Stuff\\dumpfile.sql', but the unix like path it's the way to go.

But the easiest way is this:

If the .sql file is in c:\temp, and the MySQL is installed in the default location:

C:\temp>"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe" -u root -p -h localhost myDatabase < myDatabaseDump.sql

Regards.

Alex Angelico