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 }"