Forum Moderators: coopster

Message Too Old, No Replies

Importing MySQL DB tables

         

asantos

10:49 pm on Feb 7, 2007 (gmt 0)

10+ Year Member



Is there a way to EXPORT a remote MySQL table and then IMPORT it on a local MySQL table with pure php?

I need to set this by pressing a simple button.

sned

10:57 pm on Feb 7, 2007 (gmt 0)

10+ Year Member



mysqldump [dev.mysql.com] might do th trick for you ... (assuming you have shell access)

asantos

11:03 pm on Feb 7, 2007 (gmt 0)

10+ Year Member



actually i dont. i have three laptops and the 3 of them must download the data from some tables in a mysql in the server to their own mysql database.

so far all i can think of is a php function that does this:
1. clear the table in the localhost
2. make a select * from the remote table
3. generate a long string with the mysql INSERT command for each record selected in step (2).
4. execute each insert in the localhost mysql db

...what do you think about it?

jatar_k

11:15 pm on Feb 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can use export in phpmyadmin if you have it

if you don't then you have to have some db management tool. If you can tell us what it is then we may be able to help.

asantos

11:28 pm on Feb 7, 2007 (gmt 0)

10+ Year Member



jatar_k:
the thing is, i have to implement a solution through php so the user can click a single button to perform the whole data download.

Example:
[localhost...] << if user presses a button in there, the data will automatically be syncronized.

jatar_k

12:21 am on Feb 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



just run a cron on the server and have the backup done to a file on the server using mysqldump and tar gz

the user can then push a button and it will prompt them to save it somewhere

I, well myself and an admin, have built things like you're asking, they involve a bunch of different things

your steps in your above post would be fine, with larger dbs it may be very very slow. You would have to look at max_execution_time and probably a few other settings. If you make changes to your local then it doesn't have the samne settings as the remote server and could cause issues if you use the local for testing or running a dupe environment.

your best bet is to have the server do it and either push it to somewhere or when the user clicks the button it can ftp it to somewhere else, then IMPORT it to mysql.

This would be the fastest and stop the majority of possible problems and different environments.

you could have the cron run and attach it to an email if you wanted.

dreamcatcher

8:44 am on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



asantos, try hotscripts.com or the PHP classes repository, you might find a suitable backup class you can use with jatar_k`s solution.

[hotscripts.com...]
[phpclasses.org...]

dc

asantos

1:06 am on Feb 11, 2007 (gmt 0)

10+ Year Member



thanks for the tips!