修改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”