修改mysql數據庫名稱的方法:
1.重命名所有的表,代碼:
CREATE DATABASE new_db_name;RENAME TABLE db_name.table1 TO new_db_name.table1,
db_name.table2 TO new_db_name.table2;
DROP DATABASE db_name;
2.mysqldump導出數據再導入,代碼:
mysqldump -uxxxx -pxxxx -h xxxx db_name > db_name_dump.SQLmysql -uxxxx -pxxxx -h xxxx -e “CREATE DATABASE new_db_name”
mysql -uxxxx -pxxxx -h xxxx new_db_name < db_name_dump.SQL
mysql -uxxxx -pxxxx -h xxxx -e “DROP DATABASE db_name”
3.使用shell腳本重命名所有的表,代碼:
#!/bin/bashmysqlconn=”mysql -u xxxx -pxxxx -S /var/lib/mysql/mysql.sock -h localhost”
olddb=”db_name”
newdb=”new_db_name”
#$mysqlconn -e “CREATE DATABASE $newdb”
params=$($mysqlconn -N -e “SELECT TABLE_NAME FROM
INFORMATION_SCHEMA.TABLES WHERE table_schema='$olddb'”)
for name in $params; do
$mysqlconn -e “RENAME TABLE $olddb.$name to $newdb.$name”;
done;
#$mysqlconn -e “DROP DATABASE $olddb”