Move table from one database to another in MySQL [closed]

How to move a table from one Database to another Database without using phpMyAdmin? It will be better if it is possible by PHP.


Solution 1:

ALTER TABLE .. can be used to move tables from one database to another:

alter table my_old_db.mytable rename my_new_db.mytable

Warning: as you asked, this is a move, not a copy to the new database!

But you will keep table data (and not integrity constraints if they apply in your case)

Regarding php, php is able to run sql commands so it won't be a problem.

Solution 2:

Entire Database (all tables):

mysqldump -u root databasename > dump.sql
mysql -u root databasename < dump.sql

One Table:

mysqldump -u root -p yourpass dbname tablename | mysql -u root -p pass secondDB

PHP:

Run PHP SELECT FROM SOURCE-DB TABLE and Run INSERT INTO Table IN TARGET-DB