Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

mysql

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

like image 666
Sarvap Praharanayuthan Avatar asked Mar 21 '13 21:03

Sarvap Praharanayuthan


People also ask

How do I move a table from one database to another?

Steps that need to be followed are:Launch SQL Server Management Studio. Select and right-click on the Source Database, go to Tasks > Export Data. Import/Export Wizard will be opened and click on Next to proceed. Enter the data source, server name and select the authentication method and the source database.

What does flush do in MySQL?

MySQL flush command is used to clean up the internal caches used by MySQL and only the root level user can have permissions for a FLUSH command.It is mainly used to clear the host cache tables. The most common options for FLUSH command are: PRIVILEGES.

How do I move a table in phpMyAdmin?

To perform the corresponding operations on a database table, you should select the desired table in phpMyAdmin and click on the Operations tab. The Move table to section allows you to move the table with a new name under the current database or to move it under a different database.


2 Answers

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.

like image 94
user2196728 Avatar answered Oct 18 '22 04:10

user2196728


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

like image 39
GGio Avatar answered Oct 18 '22 03:10

GGio