Import SQL dump into MySQL

Posted by BryanWheelock on Stack Overflow See other posts from Stack Overflow or by BryanWheelock
Published on 2009-05-13T17:33:31Z Indexed on 2010/06/14 0:02 UTC
Read the original article Hit count: 399

Filed under:
|
|

I'm confused how to import a SQL dump file.

I can't seem to import the database without creating the database first in MySQL. This is the error displayed when database_name has not yet been created:

username = username of someone with access to the database on the original server.
database_name = name of database from the original server

$ mysql -u username -p -h localhost database_name < dumpfile.sql   
Enter password:  
ERROR 1049 (42000): Unknown database 'database_name'

If I log into MySQL as root and create the database, database_name

mysql -u root  
create database database_name;  
create user username;# same username as the user from the database I got the dump from.  
grant all privileges on database_name.* to username@"localhost" identified by 'password';  
exit mysql

then attempt to import the sql dump again:

$ mysql -u username -p database_name < dumpfile.sql  
Enter password:  
ERROR 1007 (HY000) at line 21: Can't create database 'database_name'; database exists

How am I supposed to import the SQL dumpfile?

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql