Securely and quickly change the MySQL database name

Source: Internet
Author: User

Securely and quickly change the MySQL database name
GuideMySQL does not seem to have a statement to change the Database Name (maybe I don't know). If you have the permission to manage the database server, you can directly change the directory name, but if you do not have the permission, you can modify the database name by changing the table name. Change the centos database to centos_old.1. Create a database centos_old.

mysql > create database centos_old;
2. Use select concat to construct all rename table statements.
    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

Open rename_mysql_name. SQL and delete the first line.

Rename_mysql_name. SQL contains the following content:

    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. Execute the rename statement
mysql -uroot -p < rename_mysql_name.sql

In this way, the centos database name is changed to centos_old.

Address: https://www.centos.bz/2013/09/quick-and-secure-modify-mysql-name/

Address: http://www.linuxprobe.com/linux-mysql.html


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.