Importing a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alien
    New Member
    • Sep 2007
    • 61

    Importing a database

    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:

    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:
    -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?
  • coolsti
    Contributor
    • Mar 2008
    • 310

    #2
    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:
    Code:
    mysql -p --user=web16u1 databasename < workready.txt
    Of course, substitute the word "databasena me" 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:

    Code:
    use databasename;
    Again substitute your database name with the word "databasena me". This is just a simple statement to change the current database.

    Comment

    • tomarvijay80
      New Member
      • Nov 2006
      • 10

      #3
      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.

      Comment

      Working...