Reputation: 427
I have two SQL databases in phpMyadmin, db1 and db2. Say db1 has 3 tables: 1_a, 1_b, 1_c; and db2 has 3 tables: 2_d, 2_e, 2_f. I would like to transfer my db1's 1_a,1_b,1_c over to db2 and replace with db2's 2_d,2_e,2_f.
So, firstly, I will have to select 1_a, 1_b, 1_c tables from db1, and export them as a SQL file. Afterwards, I will have to select 2_d,2_e,2_f tables from db2, and drop them from db2. Thirdly, I just have import the file from first step to db2.
I am wondering what are the correct SQL statements for first and second steps? Assuming all tables that I am going to move around have their prefix like 1_x and 2_x, and there are some other tables in db1 and db2 that has no prefix and I do not want to touch them. Appreciate your answers.
Upvotes: 0
Views: 384
Reputation: 4218
you can use mysqldump to backup 3 tables or use select ... into outfile
syntax for csv output:
SELECT * FROM `1_a` INTO '/home/1_a.txt'
SELECT * FROM `1_b` INTO '/home/1_b.txt'
SELECT * FROM `1_c` INTO '/home/1_c.txt'
or better yet use phpmyadmin backup function. and afterwards you should use
DROP TABLE `2_d`;
DROP TABLE `2_e`;
DROP TABLE `2_f`;
to drop tables in second database
Upvotes: 1