import mysql dump OR copy database with PHP

I know this has likely been asked a million times so I'm gonna keep it
brief.

1. I'm in need of creating clones of a database I'm using as a template.

2. I've got a dump that I'm currently using "exec('mysql -p dbname
<dump.sql')" to clone but I'm looking for a more elegant way of doing this.

3. I do NOT need a program like phpmyadmin or bigdump to do the
importing. I'm simply attempting to find a more elegant way to do this
in my script that is handling other features for me as well.


4. In the past(read early this morning) I managed to read the dump file,
remove the comments, explode it at the ";" to separate into individual
queries and build the table structure with this but I cannot get it
populate the tables with the data in the dump.

I'd LOVE to simply be able to copy the database like phpmyadmin does but
there doesn't seem to be an easy solution for that though earlier I saw
something about a replication master/client that seemed close but I
couldn't find enough about it...if that's the way to go, just tell me
and I'll do my reading.

All I need are pointers to where to find the info since most of the
links I've found are for end users and not programmers.


Thanks for reading this and for any pointers you may have.

Eric
REMOVE-CAPSburnFORout [ Sa, 17 März 2007 00:01 ] [ ID #1659852 ]

Re: import mysql dump OR copy database with PHP

Eric H. wrote:
> I know this has likely been asked a million times so I'm gonna keep it
> brief.
>
> 1. I'm in need of creating clones of a database I'm using as a template.
>
> 2. I've got a dump that I'm currently using "exec('mysql -p dbname
> <dump.sql')" to clone but I'm looking for a more elegant way of doing this.

IMHO this is an elegant solution to the whole, parsing the dump file and then
use sql queries and error checking for each query feels a bit overkill.

--

//Aho
Shion [ Sa, 17 März 2007 00:27 ] [ ID #1659853 ]

Re: import mysql dump OR copy database with PHP

Eric H. wrote:

> I know this has likely been asked a million times so I'm gonna keep it
> brief.
>
> 1. I'm in need of creating clones of a database I'm using as a template.
>
> 2. I've got a dump that I'm currently using "exec('mysql -p dbname
> <dump.sql')" to clone but I'm looking for a more elegant way of doing this.

mysqldump -u username -ppassword databasename [tablename(s)]
Mick

>
> 3. I do NOT need a program like phpmyadmin or bigdump to do the
> importing. I'm simply attempting to find a more elegant way to do this
> in my script that is handling other features for me as well.
>
>
> 4. In the past(read early this morning) I managed to read the dump file,
> remove the comments, explode it at the ";" to separate into individual
> queries and build the table structure with this but I cannot get it
> populate the tables with the data in the dump.
>
> I'd LOVE to simply be able to copy the database like phpmyadmin does but
> there doesn't seem to be an easy solution for that though earlier I saw
> something about a replication master/client that seemed close but I
> couldn't find enough about it...if that's the way to go, just tell me
> and I'll do my reading.
>
> All I need are pointers to where to find the info since most of the
> links I've found are for end users and not programmers.
>
>
> Thanks for reading this and for any pointers you may have.
>
> Eric
Mick White [ So, 18 März 2007 00:56 ] [ ID #1661146 ]
PHP » alt.php.sql » import mysql dump OR copy database with PHP

Vorheriges Thema: WTD: Site Design and Built
Nächstes Thema: Formatting output from database