共计 1568 个字符,预计需要花费 4 分钟才能阅读完成。
导读 | MySQL 似乎没有更改数据库名称的语句(也许是我不知道),如果你有数据库服务器的管理权限,可以直接更改一下目录名即可,但如果没有权限,可以通过更改表名达到修改数据库名的目的。下面是把 centos 数据库更改为 centos_old。 |
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 < rename_mysql_name.sql
这样就完成了 centos 数据库名更改为 centos_old 的操作。
正文完
星哥玩云-微信公众号