473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Back up mysql db from shell

Hi there.
I need to update a remote database from a local one. I use mysqldump in
my php page in order to create a file for each table, like this:

$command="mysqldump table_products > table_products.sql";
system($command);

This works perfect and it gives me a file with a drop-table,
create-table and all the insert values.

Then I need to connect to the remote server and run the
table_products.sql file.

The way I do that is by calling the following in my php page:

$command="mysql --host=$host --user=$user --password=$pass
--database=$db;";
system($command);

, where $host, $user etc are being set at the top of the page. This
works fine and I get connected to the remote database.

Now I need to run the following mysql command: source stb_products.sql

When I try this sequence from a command line (windows dos prompt), it
works perfect. When I
call "mysql --host=$host --user=$user --password=$pass --database=$db;"
in command line I get the "mysql>" prompt, and the run the "source
table_products.sql" and the remote database gets updated.

When I do this through PHP the last command doesn't work.

I guess I am not calling 'source' from within a "mysql" prompt?

How should I do it?

Any other ideas for achieving the same result? I need to do everything
from a single PHP page that runs on a local machine.

The full code is the following :
//DUMP DATA IN FILE
$command="mysqldump backcatalogue table_products > table_products.sql";
system($command);

//CONNECT TO REMOTE DATABASE
$command="mysql --host=$ohost --user=$ouser --password=$opass
--database=$odb;";
system($command);

//UPDATE REMOTE DATABASE FROM FILE
$command ="mysql source table_products.sql;";
system("command ") ;

Thanks in advance,
Asaq
END PHP CODE -->

May 10 '06 #1
3 3369
On Tue, 09 May 2006 00:35:55 -0700, apostolosl wrote:
$command="mysql --host=$host --user=$user --password=$pass
--database=$db;";
system($command);

, where $host, $user etc are being set at the top of the page. This works
fine and I get connected to the remote database.

Now I need to run the following mysql command: source stb_products.sql


That's where you're going wrong. What you want to do is:

$command="mysql --host=$host --user=$user --password=$pass
--database=$db < stb_products.sql";
system($command);

Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

May 10 '06 #2

ap********@gmail.com wrote:
Hi there.
I need to update a remote database from a local one. I use mysqldump in
my php page in order to create a file for each table, like this:

$command="mysqldump table_products > table_products.sql";
system($command);

This works perfect and it gives me a file with a drop-table,
create-table and all the insert values.

Then I need to connect to the remote server and run the
table_products.sql file.

The way I do that is by calling the following in my php page:

$command="mysql --host=$host --user=$user --password=$pass
--database=$db;";
system($command);


Adding "< stb_products.sql" to the end of the command line should work.
Tim

May 10 '06 #3
Thanks guys, I thought I tried this... Probably I was adding a
semicolon at the end of the command...
It works like a charm now!!!
Thanks again and take care...
Apostolos

May 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: atlasyeo | last post by:
Hi, my first time posting on a newsgroup. anyway, let's cut to the chase. I'm trying to migrate mysql database form one server to another server. So I copied the data from /var/lib/mysql to the...
0
by: JL | last post by:
Platform: Linux Red Hat RHEL 3 (and red hat 9) Installed MySQL from source. As a matter of fact, installed all LAMPS from source, and the mysql socket file was arranged in a place other than...
0
by: root | last post by:
hi there, I've tried to install mysql-3.23.55.tar.gz but failed. Firstly, I've created directory /home/users/mysql and add group for mysql. Those are the command that I've used previously: ...
0
by: Ian | last post by:
Dear All, I just downloaded & installed MYSQL. It seemed to work and I can start it and enter my password and change a directory but that is about all. I have been ready and playing "hit & miss"...
6
by: Jim Flack | last post by:
I have a new website hosted by www.easily.co.uk which contains a mysql database (I have the initial access codes etc ). My problem is I have never used PHP or dealt with mysql before. I have tried...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
1
by: Angus Comber | last post by:
I have set a password for the mysql root user so when I do this: shell> perl -MCPAN -e shell cpan> install DBI cpan> install DBD::mysql install DBD::mysql fails Is there a way I can run...
16
by: Ananthu | last post by:
Hi I dont know how to connect mysql with ECLIPSE in RCP application. Please send me the sample code of connecting mysql sever with ECLIPSE in RCP application. Coding Part: RCP Application...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.