vlambda博客
学习文章列表

Mysql自动化安装脚本

此脚本是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.  

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

  7.  

  8. #Define MYSQL path variables

  9. Boost_URL=https://mirrors.yangxingzhen.com/mysql

  10. Boost_File=boost_1_59_0.tar.gz

  11.  

  12. #Define MYSQL path variables

  13. MYSQL_URL=http://mirrors.163.com/mysql/Downloads/MySQL-5.7

  14. MYSQL_FILES=mysql-5.7.29.tar.gz

  15. MYSQL_FILES_DIR=mysql-5.7.29

  16. MYSQL_PREFIX=/usr/local/mysql

  17. MYSQL_DIR=/data/mysql

  18. MYSQL_USER=mysql

  19.  

  20. #Install Package

  21. yum -y install ncurses-devel perl perl-devel cmake wget gcc gcc-c++ bison* autoconf openssl-devel openssl

  22.  

  23. #Install Boost

  24. wget -c ${Boost_URL}/${Boost_File}

  25. tar zxf ${Boost_File} -C /usr/local/

  26.  

  27. #Install MYSQL

  28. if [ ! -d ${MYSQL_PREFIX} ];then

  29. wget -c ${MYSQL_URL}/${MYSQL_FILES}

  30. tar zxf ${MYSQL_FILES}

  31. cd ${MYSQL_FILES_DIR}

  32. cmake . -DCMAKE_INSTALL_PREFIX=${MYSQL_PREFIX} \

  33. -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

  34. -DMYSQL_DATADIR=${MYSQL_DIR} \

  35. -DSYSCONFDIR=/etc \

  36. -DEXTRA_CHARSETS=all \

  37. -DDEFAULT_CHARSET=utf8 \

  38. -DDEFAULT_COLLATION=utf8_general_ci \

  39. -DWITH_MYISAM_STORAGE_ENGINE=1 \

  40. -DWITH_INNOBASE_STORAGE_ENGINE=1 \

  41. -DWITH_MEMORY_STORAGE_ENGINE=1 \

  42. -DWITH_PARTITION_STORAGE_ENGINE=1 \

  43. -DDOWNLOAD_BOOST=1 \

  44. -DWITH_BOOST=/usr/local/boost_1_59_0 \

  45. -DENABLED_LOCAL_INFILE=1 \

  46. -DMYSQL_TCP_PORT=3306 \

  47. -DWITH_READLINE=1 \

  48. -DMYSQL_USER=${MYSQL_USER} \

  49. -DWITH_SSL=yes

  50. if [ $? -eq 0 ];then

  51. make && make install

  52. action "The MYSQL Install Sussess..." /bin/true

  53. else

  54. action "The MYSQL Install Failed..." /bin/false

  55. exit 1

  56. fi

  57. else

  58. echo -e "\033[31mThe MYSQL already Install...\033[0m"

  59. exit 1

  60. fi

  61.  

  62. #Mysql config

  63. useradd -s /sbin/nlogin mysql >/dev/null 2>&1

  64. mkdir -p ${MYSQL_DIR}

  65. chown -R ${MYSQL_USER}.${MYSQL_USER} ${MYSQL_DIR}

  66. cat >/etc/my.cnf << EOF

  67. [mysqld]

  68. #数据存储目录

  69. datadir = ${MYSQL_DIR}

  70. #socket通信文件

  71. socket = /tmp/mysql.sock

  72. #使用mysql用户启动

  73. user = ${MYSQL_USER}

  74. #MYSQL服务运行的端口号

  75. port = 3306

  76. #开启bin-log日志

  77. log-bin = mysql-bin

  78. #MYSQL服务ID号

  79. server-id = 1

  80. #定义error错误文件

  81. log-error = ${MYSQL_DIR}/mysqld.log

  82. #PID文件路径

  83. pid-file = mysqld.pid

  84. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

  85. #设置字符集为utf8

  86. character-set-server = utf8

  87. [client]

  88. default-character-set = utf8

  89. port = 3306

  90. socket = /tmp/mysql.sock

  91. [mysql]

  92. default-character-set = utf8

  93. EOF

  94.  

  95. #Initialization Mysql

  96. /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql/ --basedir=/usr/local/mysql

  97. ln -sf ${MYSQL_PREFIX}/bin/* /usr/bin

  98. \cp ${MYSQL_PREFIX}/support-files/mysql.server /etc/init.d/mysqld

  99. chmod o+x /etc/init.d/mysqld

  100. /etc/init.d/mysqld start

脚本执行方式:

[root@localhost ~]# sh auto_install_mysql.sh

  • 输入编号:6683,直达文章

  • 输入m|M,直达目录列表