安全快速更改MySQL数据库名称

1、新建数据库centos_old.

  1. mysql > create database centos_old;

2、使用select concat拼成所有rename table的语句。

  1. 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内容大概为:

  1. rename table centos.wp_commentmeta to centos_old.wp_commentmeta;
  2. rename table centos.wp_comments to centos_old.wp_comments;
  3. rename table centos.wp_forum_forums to centos_old.wp_forum_forums;
  4. rename table centos.wp_forum_groups to centos_old.wp_forum_groups;
  5. rename table centos.wp_forum_posts to centos_old.wp_forum_posts;
  6. rename table centos.wp_forum_threads to centos_old.wp_forum_threads;
  7. rename table centos.wp_forum_usergroup2user to centos_old.wp_forum_usergroup2user;
  8. rename table centos.wp_forum_usergroups to centos_old.wp_forum_usergroups;
  9. rename table centos.wp_links to centos_old.wp_links;
  10. rename table centos.wp_options to centos_old.wp_options;
  11. rename table centos.wp_postmeta to centos_old.wp_postmeta;
  12. rename table centos.wp_posts to centos_old.wp_posts;
  13. rename table centos.wp_term_relationships to centos_old.wp_term_relationships;
  14. rename table centos.wp_term_taxonomy to centos_old.wp_term_taxonomy;
  15. rename table centos.wp_terms to centos_old.wp_terms;
  16. rename table centos.wp_usermeta to centos_old.wp_usermeta;
  17. rename table centos.wp_users to centos_old.wp_users;

3、执行rename语句

  1. mysql -uroot -p < rename_mysql_name.sql

这样就完成了centos数据库名更改为centos_old的操作。

转载于:https://www.cnblogs.com/zhonglizhengkai/p/4496692.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值