我是靠谱客的博主 糊涂皮皮虾,这篇文章主要介绍MySQL中修改库名的操作教程,现在分享给大家,希望可以做个参考。

MySQL在5.1引入了一个rename database操作,但在MySQL5.1.23后又不支持这个命令。可以说是一个实验性的功能,没有在生产中支持过(mysql-5.1 release在mysql-5.1.30),那么生产中我们有时为了追求完美需要改一下库名。怎么操作呢?
这里提供一个变通的方法。
1. 创建出新库名:

mysql>create database db_v2;
 
mysql>create database db_v2;

2.生成rename语句,从olddb里迁移,我这里olddb里sbtest;

mysql>select concat("rename table ",table_schema,".",table_name," to db_v2.",table_name,";") into outfile '/tmp/rename_to_db_v2.sql' from information_schema.tables where table_schema='sbtest';
 
mysql>select concat("rename table ",table_schema,".",table_name," to db_v2.",table_name,";") into outfile '/tmp/rename_to_db_v2.sql' from information_schema.tables where table_schema='sbtest';

3.执行生成的sql

mysql>source /tmp/rename_to_db_v2.sql
 
mysql>source /tmp/rename_to_db_v2.sql

就这么简单可以搞定了。
Good luck!

最后

以上就是糊涂皮皮虾最近收集整理的关于MySQL中修改库名的操作教程的全部内容,更多相关MySQL中修改库名内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(127)

评论列表共有 0 条评论

立即
投稿
返回
顶部