宝塔linux面板数据库存放路径修改脚本
注意:该脚本仅适合宝塔linux面板使用
支持版本:宝塔linux面板全系列
功能参数:修改 还原
sh xxx.sh #修改存放路径
sh xxx.sh old #还原数据库原路径
如果你的数据库存在在系统盘的都建议你把数据库存放路径修改到数据盘下。
修改数据库路径:
还原数据库路径:
shell代码:
#!/bin/bash Stack=$1 if [ "${Stack}" = "" ]; then Stack="new" else Stack=$1 fi mysqld_start(){ service mysqld restart } mysql_alter() { Old_path="/www/server" clear echo -e "\033[33mUsage: $0 {new|old}\033[0m" echo -e "\033[33msh $0 (default:new)\033[0m" echo -e "\033[33msh $0 old (Restore database)\033[0m" echo "===============================" if [ -d /www/server/data ]; 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[33m${Route}/var\033[0m" echo "For more information visit: http://XWCX.NET" echo "#####################################" else echo "#####################################" echo -e "Prompt:\033[31mDatabase directory changes not successful\033[0m" echo "#####################################" fi fi else echo -e "Prompt:\033[31mSorry, I can't find the /www/server/data directory\033[0m" fi } Old_mysql() { if [ -d /www/server/data ]; then echo -e "Prompt:\033[31m/www/server/data folder already exists, not allowed to restore.\033[0m" else service mysqld stop killall -TERM mysqld rm -rf /etc/my.cnf mv /etc/my.cnfold /etc/my.cnf mv /www/server/data.old /www/server/data mysqld_start if netstat -ntulp |grep -w 3306; then echo -e "Prompt:\033[32mrecover successfully\033[0m" echo "For more information visit: http://XWCX.NET" else echo -e "Prompt:\033[31mrecovery failed\033[0m" echo "For more information visit: http://XWCX.NET" fi fi } case "${Stack}" in new) mysql_alter ;; old) Old_mysql ;; *) echo "Usage: $0 {new|old}" ;; esac
脚本下载:
wget http://XWCX.NET/soft/mysql_alter.sh && sh mysql_alter.sh
如修改或还原报错,请把相关错误信息回复到留言或者发创新互联邮箱 第一时间回复 谢谢
文章名称:创新互联linux教程:宝塔linux面板数据库存放路径修改脚本
文章来源:http://www.shufengxianlan.com/qtweb/news20/448570.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联