MySQL Modify database name

Source: Internet
Author: User

#!/bin/bash#fafu_li# Email: [Email protected]&348926676@qq. com# Time:2015.08.Ten#mysql数据库改名, the official does not have a command to directly modify the database name # only by modifying the table name to implement the source/etc/Profile #加载系统环境变量source~/. Bash_profile #加载用户环境变量set-o nounset #引用未初始化变量时退出mysqlconn="mysql-h localhost-uroot-p123456"#需要修改的数据库名olddb="test1"#修改后的数据库名newdb="test2"#创建新数据库 $mysqlconn-E"drop database if exists ${newdb};create database ${newdb};"#获取所有表名tables=$ ($mysqlconn-N-E"Select table_name from information_schema.tables where table_schema= ' ${olddb} '") #修改表名 forNameinch$tables; Do$mysqlconn-E"Rename table ${olddb}.${name} to ${newdb}.${name}" Done#删除老的空库 # $mysqlconn-E"drop Database ${olddb}"

MySQL Modify database name

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.