zoukankan      html  css  js  c++  java
  • MySQL数据库修改名字脚本

     脚本:

    [root@mysql-master-15-137 ~]# cat rename_database.sh 
    #!/bin/bash
    # 本脚本是针对于MySQL数据库类型为Innodb修改数据名的。
    # 假如是myisam的存储引擎,直接在数据目录下mv就行。
    # 用法:假设将OLD_DATABASE数据库名改为NEW_DATABASE
    
    OLD_DATABASE="loanflow"
    NEW_DATABASE="loanflow_test"
    PWD="123456"
    
    mysql -uroot -p$PWD -e "create database if not exists $NEW_DATABASE"
    
    list_table=$(mysql -uroot -p$PWD -Nse "select table_name from information_schema.TABLES where TABLE_SCHEMA='$OLD_DATABASE'")
    
    for table in $list_table
    do
    mysql -uroot -p$PWD -e "rename table $OLD_DATABASE.$table to $NEW_DATABASE.$table"
    done
  • 相关阅读:
    第二章例2-9
    第二章例2-8
    第二章例2-7
    第二章例2-6
    第二章例2-5
    第二章例2-4
    第二章例2-3
    第二章例2-2
    第二章例2-1
    第一章例1-2
  • 原文地址:https://www.cnblogs.com/sandshell/p/11637268.html
Copyright © 2011-2022 走看看