【1】修改库名
使用时,如果有账户密码请注意输入
sh renamedb.sh guangxi_mj_game_log guangxi_mj_log
#!/bin/bash source /etc/profile echo "$*" old_dbname=$1 new_dbname=$2 mysql -e "create database if not exists ${new_dbname}" list_table=$(mysql -N -e "select table_name from information_schema.TABLES where TABLE_SCHEMA='${old_dbname}';") for table in $list_table do mysql -e "rename table ${old_dbname}.${table} to ${new_dbname}.${table};" done