Modify the database name in mysql.

Source: Internet
Author: User

Modify the database name in mysql.

#! /Bin/bash # Author: fafu_li # Time: 2015.08.10 # renaming a mysql database, there is no command to directly modify the database name on the official website. # You can only modify the table name to implement source/etc/profile # load the system environment variable source ~ /. Bash_profile # load the user environment variable set-o nounset # exit mysqlconn = "mysql-h localhost-uroot-p123456" When Referencing uninitialized variables # Name of the database to be modified olddb = "test1" # The modified database name newdb = "test2" # create a new database $ mysqlconn-e "drop database if exists $ {newdb }; create database $ {newdb}; "# retrieve all table names tables =$ ($ mysqlconn-N-e" select table_name from information_schema.tables where table_schema = '$ {olddb }'") # modify the table name for name in $ tables; do $ mysqlconn-e "rename table $ {olddb }. $ {name} to $ {newdb }. $ {name} "done # deleting old empty databases # $ mysqlconn-e" drop database $ {olddb }"

 

Related Article

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.