Announcement

Collapse
No announcement yet.

mysql import via command line using PHP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • mysql import via command line using PHP

    I'm trying to import a Wordpress database via the command line, using PHP.

    Yes, I know I can use the cPanel to do it via the phpMyAdmin (which is what I just did).

    I would like to have a simple php file that I can import the database without having to log into cPanel, as I'm probably going to be doing this often for testing purposes on a production Wordpress blog for a customer.

    What I have in the php file:

    Code:
    <?php system('mysql -h localhost -u MyUserName -p MyPassword -d MyDatabase < MyDumpFile;'); ?>
    The only output I get is the same as if I entered 'mysql -?` from the command line.

    I have verified that the username, password, database, and dump file names are all correct. When I changed it to a mysqldump command (with appropriate syntax changes), it worked fine.


    I figure there is something I'm missing, but can't figure it out.

    Need help

  • #2
    I've never used the switch -d when using mysql command

    Try the following
    Code:
    <?php system('mysql -h localhost -u MyUserName -p MyPassword MyDatabase < MyDumpFile;'); ?>
    I see you also have posted this on other websites. I hope I'm not trying to help a bot, cause that would be just silly!

    EDIT - The correct syntax is -D, --database=name Database to use. Try using a capital D
    Last edited by clivejo; 15-09-2012, 07:21 PM.

    Comment

    Working...
    X