Link to home
Start Free TrialLog in
Avatar of Insoftservice inso
Insoftservice insoFlag for India

asked on

mysql dump from one database to other

Hi,
I want a script which would copy database table (selected table) from one database to other with its backup.
Please note its on windows server.

Thanx
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Avatar of Insoftservice inso

ASKER

hi,
@ray

C:\Program Files\MySQL\MySQL Server 5.1\bin/mysqldump -u -p www | C:\Program Files\MySQL\MySQL Server 5.1\bin/mysql -u -p test

what it means actual i wanted to copy 'www' to sql file and then to ' test' but its saving the database of 'test' in sql file so whts the issue in code.
even i had removed the code after '| ' i.e  "C:\Program Files\MySQL\MySQL Server 5.1\bin/mysql -u -p test"
Check the link here.  I think you could just plug those queries into your PHP code and away-you-go!
(slaps forehead)

http://forums.mysql.com/read.php?108,93119,93987#msg-93987

Says, ...

CREATE TABLE db2.table LIKE db1.table;
INSERT INTO db2.table SELECT * FROM db1.table;

You just substitute your data base names for db1 and db2,
Hi @ray,
thx for ur comments but issue is that the table name can be dynamic.
So creating db will not be fesible .
Please check the above code and let me know whts the issue in it.
Can't you use a variable for the table name?  I may still not be understanding your question.
hi,
this are two database with same no of table.
the logic is that it will take backup of the table daily.
so it will take db backup and paste it on other.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

Thx its nearly done.
May i know how to use mysqldump for multiple table name
Hi,
@ray
thx for ur comments ,
ya its an cron job . the database is getting transferred to other table but i have used array since table name can vary so instead of using array and foreach if i would have used implode() and thn provide it to mysqldump it would be better. or simple string of the table name to mysqldump command
hi,
@ray is there any code which would copy index, trigger of the table.
my code currently uses array for multiple tables. but fails for trigger.
i have not checked for index will mysqldump support it .
hi,

srry ray.

'LOAD DATA INFILE ' is used to dump the file to the db table.
i am extremely srry to give wrong info .ya for copy from db to folder mysqldump is used. but for restoring i am using 'LOAD DATA INFILE '.

pls let me know whether it supports triggers ,index or not
Sorry, I don't know.  I have always used COPY.
hi,
ray actually i forgot to say that mysqldump is not workng at my end i dont know y.
Hi Ray,
Thanx for ur comments .
I had resolved my issue with other method.