宁波建设工程检测行业协会网站汽车企业管理系统
news/
2025/10/7 23:56:32/
文章来源:
宁波建设工程检测行业协会网站,汽车企业管理系统,wordpress支持asp.net,外包公司注册需要什么由于原本的数据库命名不规范#xff0c;需要进行重新命名#xff0c;最终确定方案为新建数据库后迁移表#xff0c;以下为脚本。
#!/bin/bashecho -e \033[34m 此脚本功能为修改数据库名称#xff08;需要新建数据库后将数据迁移到新数据库#xff09;#xff0c;…由于原本的数据库命名不规范需要进行重新命名最终确定方案为新建数据库后迁移表以下为脚本。
#!/bin/bashecho -e \033[34m 此脚本功能为修改数据库名称需要新建数据库后将数据迁移到新数据库请在能执行mysql命令的服务器执行 \033[0m
echo -e \033[34m 警告执行本操作前请备份数据库 \033[0mfunction printConsole(){echo echo -e \033[34m 1.重命名TEST数据库 \033[0mecho -e \033[34m 2.重命名自定义数据库 \033[0mecho echo echo read -p Select Number(CtrlC to EXIT): numecho export NUM$num
}function renameTest(){read -p 请输入TEST系统MySQL IP默认localhost testMysqlHostif [ -z ${testMysqlHost} ];thentestMysqlHostlocalhostfiexport TEST_MYSQL_HOST$testMysqlHostread -p 请输入TEST系统MYSQL PORT默认3306 testMysqlPortif [ -z ${testMysqlPort} ];thentestMysqlPort3306fiexport TEST_MYSQL_PORT$testMysqlPortread -p 请输入TEST系统Mysql用户名 testMysqlUserNameexport TEST_MYSQL_USER_NAME$testMysqlUserNameread -p 请输入TEST系统Mysql密码 testMysqlPasswordexport TEST_MYSQL_PASSWORD$testMysqlPasswordifCreateNewYexport IF_CREATE_NEW_DB$ifCreateNewifDeleteOldYexport IF_DELETE_OLD_DB$ifDeleteOldecho -e \033[34m 重命名test auth数据库 \033[0mexport OLD_DB_NAMEtest-authexport NEW_DB_NAMEtest_authrenameecho -e \033[34m 重命名test db数据库 \033[0mexport OLD_DB_NAMEtest-dbexport NEW_DB_NAMEtest_dbrenameecho -e \033[34m 重命名test nacos数据库 \033[0mexport OLD_DB_NAMEtest-register-configexport NEW_DB_NAMEtest_register_configrename
}function configParam(){read -p 请输入MySQL IP默认localhost testMysqlHostif [ -z ${testMysqlHost} ];thentestMysqlHostlocalhostfiexport TEST_MYSQL_HOST$testMysqlHostread -p 请输入MYSQL PORT默认3306 testMysqlPortif [ -z ${testMysqlPort} ];thentestMysqlPort3306fiexport TEST_MYSQL_PORT$testMysqlPortread -p 请输入Mysql用户名 testMysqlUserNameexport TEST_MYSQL_USER_NAME$testMysqlUserNameread -p 请输入Mysql密码 testMysqlPasswordexport TEST_MYSQL_PASSWORD$testMysqlPasswordread -p 请输入旧数据库名称 olddbexport OLD_DB_NAME$olddbread -p 请输入新数据库名称 newdbexport NEW_DB_NAME$newdbread -p 是否需要创建新数据库 Y/N 默认 Y ifCreateNewif [ -z ${ifCreateNew} ];thenifCreateNewYfiexport IF_CREATE_NEW_DB$ifCreateNewread -p 是否需要删除旧数据库 Y/N 默认 N 建议手动删除 ifDeleteOldif [ -z ${ifDeleteOld} ];thenifDeleteOldNfiexport IF_DELETE_OLD_DB$ifDeleteOld
}function rename(){mysqlconnmysql -u ${TEST_MYSQL_USER_NAME} -p${TEST_MYSQL_PASSWORD} -S /var/lib/mysql/mysql.sock -h ${TEST_MYSQL_HOST} -P ${TEST_MYSQL_PORT}#创建新数据库if [[ ${IF_CREATE_NEW_DB} Y ]];then$mysqlconn -e CREATE DATABASE ${NEW_DB_NAME} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_cifi#查询数据库表params$($mysqlconn -N -e SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE table_schema${OLD_DB_NAME})tableParma\#数据库表迁移for name in $paramsdo$mysqlconn -e RENAME TABLE $tableParam${OLD_DB_NAME}$tableParam.$tableParam$name$tableParam to $tableParam${NEW_DB_NAME}$tableParam.$tableParam$name$tableParam$mysqlconn -e ALTER TABLE ${NEW_DB_NAME}.$name CHARACTER SET utf8mb4, COLLATE utf8mb4_unicode_ciecho -e \033[34m 数据表$name 已迁移至新数据库${NEW_DB_NAME} \033[0mdone#删除旧数据库if [[ $ifDeleteOld Y ]];then$mysqlconn -e DROP DATABASE $tableParam${OLD_DB_NAME}$tableParamfi#$mysqlconn -e DROP DATABASE $olddb
}function callback(){case $NUM in1)renameTestprintConsolecallback;;2)configParamrenameprintConsolecallback;;*)echo -e \033[31m 输入错误请重新输入 \033[0mprintConsolecallbackesac
}printConsole
callback
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/930984.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!