宝塔linux面板数据库存放路径修改脚本
宝塔linux面板数据库存放路径修改脚本注意:该脚本仅适合宝塔linux面板使用
支持版本:宝塔linux面板全系列
功能参数:修改 还原
sh xxx.sh #修改存放路径
sh xxx.sh old #还原数据库原路径
如果你的数据库存在在系统盘的都建议你把数据库存放路径修改到数据盘下。
修改数据库路径:
还原数据库路径:
shell代码:
#!/bin/bashStack=$1if [ "${Stack}" = "" ]; then Stack="new"else Stack=$1fimysqld_start(){service mysqld restart}mysql_alter(){Old_path="/www/server"clearecho -e "\033; then read -p "Enter a new database path (for example, /home/mysql):" Route if [ "${Route}" == "" ]; then echo "New database path cannot be empty!" else echo "Copying database file to:${Route} Please be patient" service mysqld stop killall -TERM mysqld mkdir ${Route} chown -R root:mysql ${Route} mkdir ${Route}/var cp -r -p $Old_path/data/* ${Route}/var chown -R mysql:mysql ${Route}/var mv $Old_path/data $Old_path/data.old cp /etc/my.cnf /etc/my.cnfold #/etc/my/cnf sed -i 's#^datadir = '$Old_path/data'#datadir = '${Route}/var'#g' /etc/my.cnf sed -i 's#^innodb_data_home_dir = '$Old_path/data'#innodb_data_home_dir = '${Route}/var'#g' /etc/my.cnf sed -i 's#^innodb_log_group_home_dir = '$Old_path/data'#innodb_log_group_home_dir = '${Route}/var'#g' /etc/my.cnf mysqld_start if netstat -ntulp |grep -w 3306; then echo "#####################################" echo "Database directory changed successfully!" echo -e "New database file path:\033; thenecho -e "Prompt:\033[31m/www/server/data folder already exists, not allowed to restore.\033[0m"elseservice mysqld stopkillall -TERM mysqldrm -rf /etc/my.cnfmv /etc/my.cnfold /etc/my.cnfmv /www/server/data.old /www/server/datamysqld_startif netstat -ntulp |grep -w 3306; thenecho -e "Prompt:\033[32mrecover successfully\033[0m"echo "For more information visit: http://www.tieww.com"elseecho -e "Prompt:\033[31mrecovery failed\033[0m"echo "For more information visit: http://www.tieww.com"fifi}case "${Stack}" in new) mysql_alter ;; old) Old_mysql ;; *) echo "Usage: $0 {new|old}" ;;esac
脚本下载:
wget http://www.tieww.com/soft/mysql_alter.sh && sh mysql_alter.sh
如修改或还原报错,请把相关错误信息回复到留言或者发铁网维邮箱第一时间回复 谢谢
页:
[1]