Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Import SQL file command line

  1. #1
    Ronin is offline Programming Professional
    Join Date
    Apr 2006
    Posts
    309
    Rep Power
    24

    Import SQL file command line

    I have a SQL generated file and I would like to import it to MySQL via the command line. Can anyone post the method to do this?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    mylegoh is offline Newbie
    Join Date
    Sep 2006
    Location
    London
    Posts
    25
    Rep Power
    0
    From msdos:
    mysql -u username -p database_name < textfilewithsqlstatments.sql

    From unix:
    similar, but it has been a while so I cannot remember the exact syntax, it should not be too different.
    Last edited by John; 07-15-2009 at 06:56 AM.

  4. #3
    Ronin is offline Programming Professional
    Join Date
    Apr 2006
    Posts
    309
    Rep Power
    24
    yeah, it is the same command in Linux. I forgot to post that I figured this out afterwards.

  5. #4
    Lop's Avatar
    Lop
    Lop is offline Speaks fluent binary
    Join Date
    May 2006
    Posts
    1,178
    Rep Power
    30
    Except the password doesn't need to be there. Just:

    mysql -u username -p < textfile.sql

  6. #5
    Atmaweapon is offline Newbie
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    0
    i had to include the database name:
    mysql -u <username> -p <database> <textfile.sql>

  7. #6
    zerostar's Avatar
    zerostar is offline Newbie
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0
    heya

    I am copying a .sql db form a production server to a dev server. Do I have to place the .sql file in a certain directory to do the import from the cmd line? I can't seem to be able to complete the import.

    I'm running the latest revision of wampserver.

    thanks!

  8. #7
    Jordan Guest
    If you execute it as:

    mysql -u <username> -p <database> textfile.sql

    Then the file needs to be in the same directory you are currently in. If you know where the file is you can do:

    mysql -u <username> -p <database> /path/to/file/textfile.sql

  9. #8
    zerostar's Avatar
    zerostar is offline Newbie
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0
    Thanks for the reply

    I'm still getting an ERROR 1604 (syntax). Here is what I'm entering at the mysql> prompt:

    Code:
    mysql -u username -p databasename < dbtoimport.sql;
    is this correct?

    btw - this is from a sqldump from the Prod server.
    Last edited by zerostar; 01-23-2008 at 09:48 AM.

  10. #9
    Jordan Guest
    No, remove the ;

  11. #10
    zerostar's Avatar
    zerostar is offline Newbie
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0
    hmm...tried that but it just goes to the next line. sorry 'bout the n00bness

    I already created the DB and I'm just trying to import the structure and data from the dump file - is this procedure correct? They are named the same - would that present this problem?

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 6 users browsing this thread. (0 members and 6 guests)

Similar Threads

  1. How to compile at command line?
    By zeroradius in forum Java Help
    Replies: 5
    Last Post: 08-03-2010, 12:53 PM
  2. Command line
    By Papi in forum Ruby Programming
    Replies: 4
    Last Post: 11-07-2009, 05:47 PM
  3. Command Line
    By BlaineSch in forum Computer Software/OS
    Replies: 13
    Last Post: 07-31-2009, 05:50 AM
  4. Command line - %currentuser% type command
    By flipz in forum General Programming
    Replies: 0
    Last Post: 02-09-2009, 06:30 AM
  5. PHP command Line
    By dirkfirst in forum PHP Development
    Replies: 1
    Last Post: 10-26-2006, 08:31 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts