MySQL中如何快速更改数据库名称
作者:归人云淡风轻
时间:2023-04-28
浏览:2
1、新建数据库centos_old.mysql>createdatabasecentos_old;2、使用selectconcat拼成所有renametable的语句。mysql-uroot-p-e"selectconcat('renametablecentos.',table_name,'tocentos_old.',table_name,';')frominformation_schema.TABLESwhereTABLE_SCHEMA='cen

1、新建数据库centos_old.
mysql > create database centos_old;
2、使用select concat拼成所有rename table的语句。
mysql -uroot -p -e "select concat('rename table centos.',table_name,' to centos_old.',table_name,';') from information_schema.TABLES where TABLE_SCHEMA='centos';" > rename_mysql_name.sql打开rename_mysql_name.sql,把第一行删除。
rename_mysql_name.sql内容大概为:
rename table centos.wp_commentmeta to centos_old.wp_commentmeta; rename table centos.wp_comments to centos_old.wp_comments; rename table centos.wp_forum_forums to centos_old.wp_forum_forums; rename table centos.wp_forum_groups to centos_old.wp_forum_groups; rename table centos.wp_forum_posts to centos_old.wp_forum_posts; rename table centos.wp_forum_threads to centos_old.wp_forum_threads; rename table centos.wp_forum_usergroup2user to centos_old.wp_forum_usergroup2user; rename table centos.wp_forum_usergroups to centos_old.wp_forum_usergroups; rename table centos.wp_links to centos_old.wp_links; rename table centos.wp_options to centos_old.wp_options; rename table centos.wp_postmeta to centos_old.wp_postmeta; rename table centos.wp_posts to centos_old.wp_posts; rename table centos.wp_term_relationships to centos_old.wp_term_relationships; rename table centos.wp_term_taxonomy to centos_old.wp_term_taxonomy; rename table centos.wp_terms to centos_old.wp_terms; rename table centos.wp_usermeta to centos_old.wp_usermeta; rename table centos.wp_users to centos_old.wp_users;
3、执行rename语句
mysql -uroot -p
这样就完成了centos数据库名更改为centos_old的操作。
作者最新文章
NetLimiter安装配置方法及详细操作步骤教程
2026-10-09 15:54
win10怎么只关闭大版本升级保留安全更新推送
2026-10-06 12:00
3ds Max修改器堆栈顺序对模型的影响及调整技巧
2026-10-04 12:33
荣耀MagicOS 11发布计划与Agent Harness架构解析
2026-09-08 19:23
AI重构企业业务架构:超聚变“智企”范式核心解析
2026-09-08 18:39
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多










































