एक डेटाबेस से दूसरे में टेबल कॉपी करने का निम्नलिखित सिंटैक्स है।
INSERT INTO yourDestinationDatabaseName.yourTableName SELECT * from yourSourceDatabaseName.yourtableName;
आइए एक उदाहरण देखते हैं।
CREATE कमांड का उपयोग 'business' डेटाबेस में एक टेबल बनाने के लिए किया जाता है। हम यहां एक नई टेबल बना रहे हैं।
<business>
mysql> use business; Database changed mysql> create table OriginalTable -> ( -> id int -> ); Query OK, 0 rows affected (0.46 sec)
'test' डेटाबेस में एक नई टेबल बनाना।
<test>
mysql> use test; Database changed mysql> create table OriginalTable -> ( -> id int -> ); Query OK, 0 rows affected (0.47 sec)
INSERT कमांड की मदद से पहली टेबल में रिकॉर्ड्स डाले जाते हैं।
mysql> use business; Database changed mysql> insert into OriginalTable values(1),(2),(3),(4); Query OK, 4 rows affected (0.18 sec) Records: 4 Duplicates: 0 Warnings: 0
सभी रिकॉर्ड्स प्रदर्शित करने के लिए।
mysql> select *from OriginalTable;
यहां आउटपुट है।
+------+ | id | +------+ | 1 | | 2 | | 3 | | 4 | +------+ 4 rows in set (0.00 sec)
उपरोक्त टेबल को डेटाबेस "business" से दूसरे डेटाबेस "test" में कॉपी करने के लिए।
mysql> INSERT INTO test.OriginalTable SELECT * from business.OriginalTable; Query OK, 4 rows affected (0.20 sec) Records: 4 Duplicates: 0 Warnings: 0
जांचने के लिए कि टेबल कॉपी की गई है या नहीं।
mysql> use test; Database changed mysql> select *from OriginalTable;
निम्नलिखित आउटपुट दर्शाता है कि टेबल "OriginalTable" सफलतापूर्वक दूसरे डेटाबेस में कॉपी हो गई है।
+------+ | id | +------+ | 1 | | 2 | | 3 | | 4 | +------+ 4 rows in set (0.00 sec)
अन्य तरीके:CREATE TABLE dest_db.table LIKE src_db.table; INSERT INTO dest_db.table SELECT * FROM src_db.table;संरचना और डेटा दोनों कॉपी करता है।mysqldumpकमांड लाइन टूल बड़े डेटासेट के लिए अधिक कुशल है।