Mysql自动化安装脚本

时间:2022-12-30 15:59:22

此脚本是Mysql安装脚本,有需要朋友可以参考,脚本内容如下:

系统环境:CentOS 7.4

软件版本:5.7.29

[root@localhost ~]# vim auto_install_mysql.sh

  1. #!/bin/bash
  2. #2020-3-12 10:31:01
  3. #BY:YangXingZhen
  4. #Auto Install MYSQL Server

  5. source /etc/rc.d/init.d/functions

  6. #Define MYSQL path variables
  7. Boost_URL=https://mirrors.yangxingzhen.com/mysql
  8. Boost_File=boost_1_59_0.tar.gz

  9. #Define MYSQL path variables
  10. MYSQL_URL=http://mirrors.163.com/mysql/Downloads/MySQL-5.7
  11. MYSQL_FILES=mysql-5.7.29.tar.gz
  12. MYSQL_FILES_DIR=mysql-5.7.29
  13. MYSQL_PREFIX=/usr/local/mysql
  14. MYSQL_DIR=/data/mysql
  15. MYSQL_USER=mysql

  16. #Install Package
  17. yum -y install ncurses-devel perl perl-devel cmake wget gcc gcc-c++ bison* autoconf openssl-devel openssl

  18. #Install Boost
  19. wget -c ${Boost_URL}/${Boost_File}
  20. tar zxf ${Boost_File} -C /usr/local/

  21. #Install MYSQL
  22. if [ ! -d ${MYSQL_PREFIX} ];then
  23. wget -c ${MYSQL_URL}/${MYSQL_FILES}
  24. tar zxf ${MYSQL_FILES}
  25. cd ${MYSQL_FILES_DIR}
  26. cmake . -DCMAKE_INSTALL_PREFIX=${MYSQL_PREFIX} \
  27. -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
  28. -DMYSQL_DATADIR=${MYSQL_DIR} \
  29. -DSYSCONFDIR=/etc \
  30. -DEXTRA_CHARSETS=all \
  31. -DDEFAULT_CHARSET=utf8 \
  32. -DDEFAULT_COLLATION=utf8_general_ci \
  33. -DWITH_MYISAM_STORAGE_ENGINE=1 \
  34. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  35. -DWITH_MEMORY_STORAGE_ENGINE=1 \
  36. -DWITH_PARTITION_STORAGE_ENGINE=1 \
  37. -DDOWNLOAD_BOOST=1 \
  38. -DWITH_BOOST=/usr/local/boost_1_59_0 \
  39. -DENABLED_LOCAL_INFILE=1 \
  40. -DMYSQL_TCP_PORT=3306 \
  41. -DWITH_READLINE=1 \
  42. -DMYSQL_USER=${MYSQL_USER} \
  43. -DWITH_SSL=yes
  44. if [ $? -eq 0 ];then
  45. make && make install
  46. action "The MYSQL Install Sussess..." /bin/true
  47. else
  48. action "The MYSQL Install Failed..." /bin/false
  49. exit 1
  50. fi
  51. else
  52. echo -e "\033[31mThe MYSQL already Install...\033[0m"
  53. exit 1
  54. fi

  55. #Mysql config
  56. useradd -s /sbin/nlogin mysql >/dev/null 2>&1
  57. mkdir -p ${MYSQL_DIR}
  58. chown -R ${MYSQL_USER}.${MYSQL_USER} ${MYSQL_DIR}
  59. cat >/etc/my.cnf << EOF
  60. [mysqld]
  61. #数据存储目录
  62. datadir = ${MYSQL_DIR}
  63. #socket通信文件
  64. socket = /tmp/mysql.sock
  65. #使用mysql用户启动
  66. user = ${MYSQL_USER}
  67. #MYSQL服务运行的端口号
  68. port = 3306
  69. #开启bin-log日志
  70. log-bin = mysql-bin
  71. #MYSQL服务ID号
  72. server-id = 1
  73. #定义error错误文件
  74. log-error = ${MYSQL_DIR}/mysqld.log
  75. #PID文件路径
  76. pid-file = mysqld.pid
  77. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  78. #设置字符集为utf8
  79. character-set-server = utf8
  80. [client]
  81. default-character-set = utf8
  82. port = 3306
  83. socket = /tmp/mysql.sock
  84. [mysql]
  85. default-character-set = utf8
  86. EOF

  87. #Initialization Mysql
  88. /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql/ --basedir=/usr/local/mysql
  89. ln -sf ${MYSQL_PREFIX}/bin/* /usr/bin
  90. \cp ${MYSQL_PREFIX}/support-files/mysql.server /etc/init.d/mysqld
  91. chmod o+x /etc/init.d/mysqld
  92. /etc/init.d/mysqld start

脚本执行方式:

[root@localhost ~]# sh auto_install_mysql.sh

  • 输入编号:6683,直达文章
  • 输入m|M,直达目录列表