How to restore mysql Database using php

Alles, was PHP betrifft, kann hier besprochen werden.

How to restore mysql Database using php

Postby amardedhia » 29. July 2017 13:13

I have stored mysqldump file in one of the folder of my project.
I am using following command to restore the database.

$cmd = "mysql -h {$server_name} -u {$username} -p{$password} {$database_name} < $restore_file";
exec($cmd);

but it is not working.

Please help me.
amardedhia
 
Posts: 2
Joined: 29. July 2017 13:08
XAMPP version: 5.6.15-2
Operating System: Mac

Re: How to restore mysql Database using php

Postby Nobbie » 29. July 2017 17:36

Two possible fixes:

a) Instead of simply using "mysql ...." as program name, apply the full pathname (like "/Applications/Xampp/blabla..../mysql ...."), unfortunately i dont have a Mac here to verify the correct pathname.

or

b) Instead of your PHP script use PhpMyAdmin, select appropriate database and choose "Import" from the menu and apply the file from your dump.
Nobbie
 
Posts: 9617
Joined: 09. March 2008 13:04

Re: How to restore mysql Database using php

Postby amardedhia » 30. July 2017 08:23

Thanks you sir for your quick reply.

I tried using full pathname also /Applications/XAMPP/xamppfiles/bin/mysql but it is also not working.

And the main requirement is to sync data from live server to local xampp. And Our clients do not know anything about phpmyadmin. And we can not force them or tell them to use phpmyadmin so we are trying to sync data from our side only. For this they just have to click one button by which we are generating one sql file on our live server using mysqldump and then using file_get_contents we get the content of sql file from live server and insert those queries one by one using foreach in the local database. But it takes too much of time to sync all the data. And if local machine's configuration is old then it takes even more time. so i was thinking to use mysql linux command to sync data to offline server.

Thank you.
amardedhia
 
Posts: 2
Joined: 29. July 2017 13:08
XAMPP version: 5.6.15-2
Operating System: Mac

Re: How to restore mysql Database using php

Postby Nobbie » 31. July 2017 10:05

I cannot help on that issue any further, its on you to debug your script to find out what is going wrong. Maybe wrong pathname, wrong username, wrong database or whatever.
Nobbie
 
Posts: 9617
Joined: 09. March 2008 13:04

Re: How to restore mysql Database using php

Postby HokuApps » 14. September 2017 07:52

The syntax is mysqldump -u username -p password dbname > name.sql
Execute the above query to export the database. and import
mysql -u username -p password dbname < dabname.sql
However the easiest way to this is phpmyadmin.
HokuApps
 
Posts: 8
Joined: 11. September 2017 07:23
XAMPP version: 1.8.0
Operating System: Windows


Return to PHP

Who is online

Users browsing this forum: No registered users and 4 guests