Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # usage h2|mysql [mysql_port]
  3. # 默认的数据端口为 3300
  4.  
  5. if [[ ! $1 ]]; then
  6. echo "usage h2|mysql [mysql_port]"
  7. exit 1
  8. fi
  9.  
  10. type=$1
  11.  
  12. shift
  13. mysql_port=3300
  14. if [[ $1 ]]; then
  15. mysql_port=$1
  16. fi
  17.  
  18. ContextXML=/home/deve/tomcat/conf/Catalina/localhost/context.xml.default
  19.  
  20. case ${type} in
  21. h2)
  22. echo '即将切入h2模式...'
  23. # 将配置文件改成h2即可
  24. sed -i -e "s@market\" url=\"jdbc:mysql@market-mysql\" url=\"jdbc:mysql@g" ${ContextXML}
  25. sed -i -e "s@market-h2\" url=\"jdbc:h2@market\" url=\"jdbc:h2@g" ${ContextXML}
  26. ;;
  27. mysql)
  28. echo "即将切入mysql模式...使用端口${mysql_port};若脚本执行失败尝试更换端口也许可行。"
  29. # 即将处理的工作包括有
  30. # 关闭数据库系统
  31. # 建立数据库系统
  32. # 配置数据库系统
  33. # 建立数据库
  34. # 导入备份数据
  35. # 配置文件改成mysql
  36. # 配置mysql url的端口
  37.  
  38. mysqlsh <<EOF
  39. dba.stopSandboxInstance(${mysql_port},{password:''})
  40. EOF
  41. mysqlsh <<EOF
  42. dba.deleteSandboxInstance(${mysql_port})
  43. EOF
  44.  
  45. mysqlsh <<EOF
  46. dba.deploySandboxInstance(${mysql_port},{password:''})
  47. EOF
  48. #编辑my.conf
  49. echo 'collation-server=utf8_unicode_ci' >> ~/mysql-sandboxes/${mysql_port}/my.cnf
  50. echo 'character-set-server=utf8' >> ~/mysql-sandboxes/${mysql_port}/my.cnf
  51. echo 'lower_case_table_names=1' >> ~/mysql-sandboxes/${mysql_port}/my.cnf
  52. mysqlsh <<EOF
  53. dba.stopSandboxInstance(${mysql_port},{password:''})
  54. dba.startSandboxInstance(${mysql_port})
  55. EOF
  56.  
  57. mysql -u root --port=3300 -h 127.0.0.1 <<EOF
  58. create database market;
  59. use market;
  60. source current_backup.sql;
  61. EOF
  62.  
  63. sed -i -e "s@jdbc:mysql://localhost:(\d+)/@jdbc:mysql://localhost:${mysql_port}/@g" ${ContextXML}
  64. sed -i -e "s@market-mysql\" url=\"jdbc:mysql@market\" url=\"jdbc:mysql@g" ${ContextXML}
  65. sed -i -e "s@market\" url=\"jdbc:h2@market-h2\" url=\"jdbc:h2@g" ${ContextXML}
  66. ;;
  67. *)
  68. echo "错误的模式 ${type}"
  69. exit 1
  70. ;;
  71. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement