开发者

Copying a database into a new database including structure and data

In phpMyAdmin under operations I can "Copy database to:" and select

  • Structure and data
  • CREATE DATABASE before copying
  • Add AUTO_INCREMENT value

I need to be able to do that without using phpMyAdmin.

I know how to create the database and user. I have a source database that's a shell that I can work from so all I really need is the how to copy all the table structure and data part. (I know, the harder part)

system() & exec() are not options for me which rules out mysqldump. (I think)

How can I loop through each table and recreate it's structure and data?

Is it just looping through the results of

SHOW TABLES

then for each table looping through

DESCRIBE tablename

Then, is there a开发者_运维问答n easy way for getting the data copied?


UPDATE:

So, I ended up going with:

SHOW TABLES;

for each table then I did

SHOW CREATE TABLE `tablename`;

and then

INSERT INTO `newBDname`.`tablename` SELECT * FROM `existingDBname`.`tablename`;    


You can use mysql_fetch_assoc on SHOW TABLES and then for each result, store the output of mysql_fetch_result SHOW CREATE TABLE $table_name and then issue mysql_query on $show_create_table

Hope that helps ... more into helping than doing it for you. :)


Use SELECT INTO to accomplish this.

SELECT * 
INTO destinationDB..newTable 
FROM sourceDB..existingTable
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜