Connecting Tech Pros Worldwide Forums | Help | Site Map

Importing a database

Member
 
Join Date: Sep 2007
Posts: 55
#1: Sep 28 '08
I just managed to use mysqldump to dump a database into a text file. Now I uploaded it into my server where i want to import it.

I tried looking up in google and came up with this command:

Quote:
mysql -p --user=web16u1 < workready.txt
where web16u1 is my databse username and workready.txt is the file that contains all the CREATE TABLE stuff as output of mysqldump command.

I got the following error:
Quote:
-bash-3.2$ mysql -p --user=web16u1 < workready.txt
Enter password:
ERROR 1046 (3D000) at line 22: No database selected
I can easily see the problem but how do I modify the command to make it include the database name?

Needs Regular Fix
 
Join Date: Mar 2008
Posts: 311
#2: Sep 29 '08

re: Importing a database


Quote:

Originally Posted by Alien

I just managed to use mysqldump to dump a database into a text file. Now I uploaded it into my server where i want to import it.

I tried looking up in google and came up with this command:



where web16u1 is my databse username and workready.txt is the file that contains all the CREATE TABLE stuff as output of mysqldump command.

I got the following error:


I can easily see the problem but how do I modify the command to make it include the database name?

You could do this two ways.

One is just to add the database name to the command line mysql command:
Expand|Select|Wrap|Line Numbers
  1. mysql -p --user=web16u1 databasename < workready.txt
  2.  
Of course, substitute the word "databasename" with the name of the database.

What I usually do is to edit the mysqldump file, in your case workready.txt, and add the following line just before the first statement that tries to do anything to your database:

Expand|Select|Wrap|Line Numbers
  1. use databasename;
  2.  
Again substitute your database name with the word "databasename". This is just a simple statement to change the current database.
Newbie
 
Join Date: Nov 2006
Location: Delhi
Posts: 10
#3: Oct 6 '08

re: Importing a database


u can use source workready.txt /*(if your file is in the same directory otherwise give path before workready.txt)*/

It will drop database and create a new one, if u don't want to drop and create a database simply open ur .txt file and remove drop and create database statement.
Reply