SQL将表从一个数据库复制到另一个数据库 [英] Sql Copy table from One Database to Another Database
本文介绍了SQL将表从一个数据库复制到另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将一个表从一个数据库复制到另一个数据库.因此,我尝试按以下方式在SqlFiddle中进行查询,但出现错误
I need to copy a table from one database to another. So I tried to query in SqlFiddle as follows but getting error
CREATE TABLE ForgeRock
(`id` int, `productName` varchar(7), `description` varchar(55))
;
INSERT INTO ForgeRock
(`id`, `productName`, `description`)
VALUES
(1, 'OpenIDM', 'Platform for building enterprise provisioning solutions'),
(2, 'OpenAM', 'Full-featured access management'),
(3, 'OpenDJ', 'Robust LDAP server for Java')
;
CREATE TABLE ForgeRock1 AS SELECT * FROM ForgeRock
错误:
MySQL的查询面板中不允许使用DDL和DML语句.仅允许使用SELECT语句.将DDL和DML放在架构面板中.
DDL and DML statements are not allowed in the query panel for MySQL; only SELECT statements are allowed. Put DDL and DML in the schema panel.
推荐答案
您还可以使用mysqldump
将表转储到另一个数据库中:
You could also use mysqldump
to dump a table into another database:
mysqldump -u<user> -p<password> <first_database> <table_name> | mysql -u<user> -p<password> <second_database>
当然必须先创建第二个数据库,这可以使用以下命令来完成:
Of course the second database must then first be created, which can be done using a command like:
mysql -u<user> -p<password> -e"CREATE DATABASE <second_database>"
这篇关于SQL将表从一个数据库复制到另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文