从 mysql 内部复制 mysql 数据库?
这可能是一个遥不可及的事情,但是.. 是否可以使用存储过程中的一个查询或多个查询来复制整个数据库布局(表、视图、过程等)?
基本上寻找与我使用 mysqldump 相同的功能,
# mysqldump -u root -ppassword --no-data --routines dbname > file
//create database copyofdbname
# mysql -u root -ppassword copyofdbname < file
是否可以在没有任何外部工具的情况下在 mysql 过程中执行此操作?
我想我可以通过使用“显示表”来创建表,然后迭代结果以获得每个表的“创建表”语句并将它们转发到新数据库中。
但这只是猜测,不知道如何以这种方式从数据库复制存储过程。
This is probably a longshot but..
is it possible to duplicate a whole database layout (tables, view, procedures, everything) with a query or multiple queries in a stored procedure?
Basically looking for the same functionality as if I would use mysqldump like this
# mysqldump -u root -ppassword --no-data --routines dbname > file
//create database copyofdbname
# mysql -u root -ppassword copyofdbname < file
Is it possible to do this in a mysql procedure without any external tools?
I guess I could do the tables by using 'show tables' and then a iterate over the results to get the 'create table' statatements for each table and forward them into the new database.
This is just speculation though, no idea how I would copy the stored procedures from the database this way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上没有,MYSql没有重复数据库功能。一些外部工具可能会,但我不知道。我使用 php 完成了这个过程,但我确信它可以使用存储过程或任何其他中间层应用程序来完成。这是我在高级别上遵循的步骤。我假设您知道如何执行每个步骤的详细信息。
CREATE TABLE dbnew.tableA LIKE dbold.tableA
它将完美地复制表的结构修正:在我之前的研究中,我发现有一个版本的 mySql 有重复的数据库命令,但它有错误并在以后的版本中被删除。即使您运行的版本具有可用的命令,遵循这些步骤仍然比使用该命令更好。
Basically no, MYSql does not have a duplicate database feature. Some external tools might, but none that I'm aware of. I did this process using php, but I'm sure it can be done using stored procedures or anything other middle tier application. Here's the steps I followed in high level. I assume you know the details of how to do each step.
CREATE TABLE dbnew.tableA LIKE dbold.tableA
It will duplicate the structure of the table perfectlyAmendment: In my research doing this before, I found that there was a version of mySql that had a duplicate database command, but it was buggy and taken out in future versions. Even if you are running the version with that command available, you are still better off following these steps than using that command.
复制表适用于我这个过程(新的数据库名称作为参数)
Copy table works for me with this procedure (new db name as argument)