473,770 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="mysql dump 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.sq l

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="mysql dump 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 3385
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.sq l


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.sq l";
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********@gmai l.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="mysql dump 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.sq l" 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
5575
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 other one.. and use INSERT INTO from the old database to the new one..so the Top level 'mysql' database has all the correct users and password and priviledge. however, when one of the php website trying to load..it'll say
0
6528
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 /tmp/mysql.sock. Let's say, /opt/mysql_root/sock/mysql.sock. Installed DBI without any problem. In /etc/my.cnf there are lines as ----- ----- -----
0
1454
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: shell>groupadd mtsqlid shell>mkdir /home/users shell>useradd -d /home/users/mysql -s /bin/false -g mysqlid mysqlid
0
3294
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" all afternoon and it seems to have something to do with the "mysql_install_db" not being installed correctly -- I have tried multiple installs with multiple downloaws. My log. . .
6
2497
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 looking at a few web tutorials (which talked about accessing the mysql bin) which I cant seem to find in my webspace. Can anyone help me with advice or a decent BASIC url tutorial that will take me through setting up a database up (and showing...
0
3948
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 version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
1
1979
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 install DBD::mysql and supply the password as a parameter - or get it to prompt me for it? Otherwise anyone know how I can remove the password temporarily for the root user in mysql?Angus
16
10766
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 Codes: Class ApplicationActionBarAdvisor:
39
5869
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 ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10102
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.