Command Line MySQL import
Posted by: westdr (---.med.harvard.edu)
Date: March 21, 2008 03:31PM

Hey all,
Just downloaded WampServer 2. I'm familiar with how to import .sql databases on linux, but how does it work with Wamp?

I tried the MySQL console: switched databases and did "c:\source file_name.sql" but it couldn't seem to find the file (even though I got the directory structure correct).

Advice?

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: hambuler (---.cpe.net.cable.rogers.com)
Date: March 21, 2008 03:56PM

Dos file name is 8 charachers. You'll probably see the file as source~1.sql

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: westdr (---.med.harvard.edu)
Date: March 21, 2008 04:04PM

Thanks. I tried reducing the file name to less than 8 characters. Still no luck. Here's the exact command and the error I'm getting:

source c:\wamp\www\dru.sql

Error: Failed to open file 'c:\wamp\www\dru.sql', error 2

Any help welcome.

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: hambuler (---.cpe.net.cable.rogers.com)
Date: March 21, 2008 04:11PM

Try using DOS edit command, ex: edit dru.sql

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: westdr (---.med.harvard.edu)
Date: March 21, 2008 04:32PM

I'm sorry to be a pain, but I'm really not familiar with Wamp or XP. So...how would you like me to use the DOS edit command? I've run it and it seems to open a blank page.

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: toivo (---.nsw.bigpond.net.au)
Date: March 21, 2008 11:58PM

This may be useful: If you backed up the database using the Export - SQL options in phpMyAdmin, you can import the database using phpMyAdmin, but you can also do it from the DOS command prompt using the mysql command and the name of the .sql file as the input. Example:

mysql -h localhost -u username -p password -D database_name < c:\temp\backup_file.sql

Regards,

toivo
Sydney, Australia

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: westdr (---.med.harvard.edu)
Date: March 24, 2008 02:06PM

Toivo,
Thanks for the advice. I tried the command you suggested, and got 'mysql' is not recognized as an internal or external command, operable file, or batch program. I know mysql is installed and working because I can access it with phpMyAdmin. (FYI, the database is 5Mb and phpMyAdmin's import limit is 2Mb)

I'm still looking for a solution. any advice?

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: toivo (---.nsw.bigpond.net.au)
Date: March 24, 2008 02:38PM

Hi,

The import limit in phpMyAdmin comes from the default maximum upload size in php.ini. You can increase the limit by editing the file c:\wamp\bin\apache\apache2.2.8\bin\php.ini in Wordpad. Locate the lines:

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

Change the 2M to for example 10M, save the file and restart Apache.

You can run the mysql command by either specifying the full path, or by changing the current directory with the CD command to c:\wamp\bin\mysql\mysql5.0.51a\bin, or by adding that folder to the system environment variable PATH. Go to Control Panel - System - Advanced - Environment Variables - System Variables, click Path - Edit and add the following to the end of the Variable value (note the semicolon):

;c:\wamp\bin\mysql\mysql5.0.51a\bin

Click OK three times. You should now be able to run mysql without specifying the full path.

Regards,

toivo
Sydney, Australia

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: westdr (---.med.harvard.edu)
Date: March 24, 2008 02:45PM

Toivo,
Thanks very much for the well thought out reply. I've changed the php.ini, and I'll try that way yet again. The Variable instructions also look great. I'll give it a try if I can't get phpMyAdmin to work. Here's hoping this is my last cry for help.

Thanks!

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: paziek (217.153.4.---)
Date: March 28, 2008 12:43AM

Hello,

I've got problem similar to the one described by westdr.
Filesize is 5mb gziped and 33mb in .sql
In database it takes ~190mb

I changed upload limit to 10mb, and thats not a problem anymore, but after 300seconds script stops.
I would use set_time_limit(0) but this already didn't had any effect on a different script, so I guess I'll just let that one pass by.

I think that I modified php.ini
from phpinfo()
max_execution_time 3230 3230
max_input_time 6660 6660


On the other hand
mysql> -h localhost -u root -p -D sialala < c:\sialala.sql
gives me this: Unknown command '\n'.
So I though "perhaps I should end command with ; or \g" and then I've got this:
ERROR 1064 (42000): You have an error in your SQL syntax; c
corresponds to your MySQL server version for the right synt
calhost -u root -p -D sialala < c:\sialala.sql' at line 1


So heres no good either.



I would appreciate any advice on that one.

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: toivo (203.19.130.---)
Date: March 28, 2008 06:23AM

Hi,

According to the PHP reference manual [php.net], set_time_limit() has not effect if PHP is running in Safe mode. Does your PHP run in safe mode?

Also, the time spent in running database queries does not count towards the time the script has been running. Would 300 seconds be the maximum the script is allowed to run, on the top of database activity?

If you are uploading a 33MB file in phpMyAdmin, the upload limit should be more than the file size.

Your entries for the max times in php.ini look a bit odd, only one numeric figure is expected on each line.

Regarding the mysql command to import the backup file, you need to run it from the DOS command prompt, not from the mysql> prompt. Therefore you do not need semicolon at the end.

Regards,

toivo
Sydney, Australia

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: westdr (---.med.harvard.edu)
Date: March 28, 2008 02:04PM

I solved my problem by creating a database in phpMyAdmin, then running the mysql console, changing to the correct database -- use database_name -- then doing source c:\filepath\databasename

Just make sure that you've fully uncompressed the database before trying to import it.

westdr

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: clearchannel (---.sip.bct.bellsouth.net)
Date: March 29, 2008 10:42PM

The best way I found to backup and restore databases is by using mysqldumper [www.mysqldumper.de]

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: pling (---.236.208.218.klj02-home.tm.net.my)
Date: July 22, 2008 01:49PM

I follow instruction here, but i keep getting this error

Show warnings disabled.
Error:
Unknown command '\A'.



I am new on this, if localhost, username: root and password is empty, how to i enter?

this was what i type

mysql -h localhost -u root -p -D database_name -use database_name < D:\wamp\AF.sql

thanks for any help

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: rj_steinert (---.cidr.lightship.net)
Date: August 25, 2008 11:11PM

I don't have time to read this whole thread but I followed the instructions provided by the \h command. In other words this worked for me from the MySQL console (found with a left click in your icon tray menu):



\. c:\some_file.sql



Ya, it's that easy.



Edited 1 time(s). Last edit at 08/25/2008 11:12PM by rj_steinert.

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: rmleon07 (---.hfc.comcastbusiness.net)
Date: November 16, 2010 09:36PM

Hi everybody,

I'm trying to import a file.sql file using the MySQL console, I have a copy of a file.sql file in the same directory of mysql.exe, I was able to create a new database with the command create database and after that use command USE <database name> then when I run SOURCE file.sql; it gave me an error like this:
Failed to open file 'file.sql', error 2

Does anybody run in to this problem?

Thaks for any help

Options: ReplyQuote
Re: Command Line MySQL import
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: November 16, 2010 10:01PM

cant you just use phpmyadmin?

anyway source is used to run sql script file for example sql queries

its not used for importing

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote


Sorry, only registered users may post in this forum.