Importing mysql dump

200 views Asked by At

I am trying to sync data from one mysql database living on one server to another (location with you).

I have a series of php scripts that package up the data, download it to the server and decompress it.. but I am having little joy in importing the data via command line.

I am running the terminal command

mysql -u dbusername -h blaa.mysql.eu1.frbit.com mypasswordhere database_name < /var/www/blaa/sqlfilehere.sql

Via php exec command.. I get no errors or anything show in the error log but nothing seems to import :( When I run the same command via terminal it works but says something along the lines of 'using your mysql password in the terminal is stupid'

Just wondering if there is a more sane way to do this via PHP so I don't have to do it by hand each time I want to sync..

3

There are 3 answers

0
Thickey On BEST ANSWER

So I ended up going with a php class that someone else put together here on github. Which did the job faster/better than I could have done in PHP and doesn't mess about with the command line.

2
Olli On

try the following:

mysql -u dbusername -h blaa.mysql.eu1.frbit.com -p mypasswordhere database_name < /var/www/blaa/sqlfilehere.sql

or

mysql -udbusername -hblaa.mysql.eu1.frbit.com -pmypasswordhere database_name < /var/www/blaa/sqlfilehere.sql

depending on the implementaion (thanks to eKom for pointing that out). take care to use -p before the password. that might help. Otherwise the mysql command takes your supplied password as name of the database. (although it should give you an error in this case)

0
emiliopedrollo On

try something like this:

...
$dbhost = "blaa.mysql.eu1.frbit.com";
$dbuser = "dbusername";
$dbpass = 'mypasswordhere';
$dbname = "database_name";
$filename = "/var/www/blaa/sqlfilehere.sql"

system("mysql -h $dbhost -u $dbuser --password='$dbpass' $dbname < $filename");
...