importing database.sql

Newb here. I'm slowly getting the hang of the terminal interface. I'm stuck, though. I have a 70mb sql file (databaseBU.sql) that I need to import into MySql. The database has been created (MyDatabase).

I've uploaded the file to:

/srv/www/mydomain.com/public_html/databaseBU.sql

questions:

1) what is the command I should run once inside mysql/terminal

2) how long should 70mb take to import?

Running Ubuntu Hardy.

Thanks

13 Replies

cat /srv/www/mydomain.com/public_html/databaseBU.sql | mysql

> how long should 70mb take to import?

It depends.

This is a message from the SOCIETY FOR THE PREVENTION OF CAT PIPING.

Stop piping cats:

mysql < /srv/www/mydomain.com/public_html/databaseBU.sql

See this link for more information.

… we now return you to your regular programming :-) (note: you might need to add --user=username, --password, and the database name to the mysql command as required.)

That link is about the performance profile of grep, which has nothing to do with what's going on here. There won't be any speed difference for this operation. But certainly use whatever CLI style you like!

@hoopycat:

mysql < /srv/www/mydomain.com/public_html/databaseBU.sql

OK, thanks. so i'm at the mysql cursor and this is what i enter:

 mysql -u username -p password MyDatabase < /srv/www/mydomain.com/public_html/databaseBU.sql;

you have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '< /srv/www/…

That new cursor means that you have entered an incomplete SQL command, so MySQL is waiting for you to complete it.

The problem might have to do with the contents of the file, or it might have to do with the syntax you're using. Try this: Don't specify the password on the command line. Just skip the password, and MySQL will ask you for it.

mysql -u username -p MyDatabase < /srv/www/mydomain.com/public_html/databaseBU.sql

The above command would look as if it's supplying "MyDatabase" as the password, but in fact it's not. Crazy MySQL command line ;)

@hybinet:

That new cursor means that you have entered an incomplete SQL command, so MySQL is waiting for you to complete it.

The problem might have to do with the contents of the file, or it might have to do with the syntax you're using. Try this: Don't specify the password on the command line. Just skip the password, and MySQL will ask you for it.

mysql -u username -p MyDatabase < /srv/www/mydomain.com/public_html/databaseBU.sql

The above command would look as if it's supplying "MyDatabase" as the password, but in fact it's not. Crazy MySQL command line ;)

thanks for the reply, now I'm getting an error in my SQL syntax. hmmm… I wonder if something happened when I FTP'd the *.sql file.

Still not working. I tried installing phpmyadmin, thinking that might make it easier. Alas, no. Now that it is installed, I can't seem to access it. argh. keeping the faith.

Wait, did you say you're running that command from the mysql prompt? It needs to be run from the shell.

Maybe double check a few things.

mysql -u root -p

Do you successfully log in?

show databases;

Does MyDataBase show up?

If the above works, try cd'ing to the directory your .sql file is in, then run the import command without the path.

mysql -u username -p database_name < FILE.sql

@embarkadero:

OK, thanks. so i'm at the mysql cursor and this is what i enter:

 mysql -u username -p password MyDatabase < /srv/www/mydomain.com/public_html/databaseBU.sql;

You should type that at the shell command line not at the mysql command line.

@Xan:

Wait, did you say you're running that command from the mysql prompt? It needs to be run from the shell.

YES! This worked. Thank you to everyone who took the time to respond.

@atourino:

You should type that at the shell command line not at the mysql command line.

Thank the lord!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct