mariadb-5.5.sh 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_MariaDB55() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. id -u mysql >/dev/null 2>&1
  13. [ $? -ne 0 ] && useradd -M -s /sbin/nologin mysql
  14. [ ! -d "${mariadb_install_dir}" ] && mkdir -p ${mariadb_install_dir}
  15. mkdir -p ${mariadb_data_dir};chown mysql:mysql -R ${mariadb_data_dir}
  16. if [ "${dbinstallmethod}" == "1" ]; then
  17. tar zxf mariadb-${mariadb55_ver}-linux-systemd-x86_64.tar.gz
  18. mv mariadb-${mariadb55_ver}-linux-systemd-x86_64/* ${mariadb_install_dir}
  19. sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/local/lib/libjemalloc.so@' ${mariadb_install_dir}/bin/mysqld_safe
  20. sed -i "s@/usr/local/mysql@${mariadb_install_dir}@g" ${mariadb_install_dir}/bin/mysqld_safe
  21. elif [ "${dbinstallmethod}" == "2" ]; then
  22. tar xzf mariadb-${mariadb55_ver}.tar.gz
  23. pushd mariadb-${mariadb55_ver}
  24. [ "${armplatform}" == "y" ] && patch -p1 < ../mysql-5.5-fix-arm-client_plugin.patch
  25. cmake . -DCMAKE_INSTALL_PREFIX=${mariadb_install_dir} \
  26. -DMYSQL_DATADIR=${mariadb_data_dir} \
  27. -DSYSCONFDIR=/etc \
  28. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  29. -DWITH_PARTITION_STORAGE_ENGINE=1 \
  30. -DWITH_FEDERATED_STORAGE_ENGINE=1 \
  31. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
  32. -DWITH_MYISAM_STORAGE_ENGINE=1 \
  33. -DWITH_READLINE=1 \
  34. -DWITH_EMBEDDED_SERVER=1 \
  35. -DENABLE_DTRACE=0 \
  36. -DENABLED_LOCAL_INFILE=1 \
  37. -DDEFAULT_CHARSET=utf8mb4 \
  38. -DDEFAULT_COLLATION=utf8mb4_general_ci \
  39. -DEXTRA_CHARSETS=all \
  40. -DCMAKE_EXE_LINKER_FLAGS='-ljemalloc'
  41. make -j ${THREAD}
  42. make install
  43. popd
  44. fi
  45. if [ -d "${mariadb_install_dir}/support-files" ]; then
  46. sed -i "s+^dbrootpwd.*+dbrootpwd='${dbrootpwd}'+" ../options.conf
  47. echo "${CSUCCESS}MariaDB installed successfully! ${CEND}"
  48. if [ "${dbinstallmethod}" == "1" ]; then
  49. rm -rf mariadb-${mariadb55_ver}-linux-systemd-x86_64
  50. elif [ "${dbinstallmethod}" == "2" ]; then
  51. rm -rf mariadb-${mariadb55_ver}
  52. fi
  53. else
  54. rm -rf ${mariadb_install_dir}
  55. echo "${CFAILURE}MariaDB install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  56. kill -9 $$; exit 1;
  57. fi
  58. /bin/cp ${mariadb_install_dir}/support-files/mysql.server /etc/init.d/mysqld
  59. sed -i "s@^basedir=.*@basedir=${mariadb_install_dir}@" /etc/init.d/mysqld
  60. sed -i "s@^datadir=.*@datadir=${mariadb_data_dir}@" /etc/init.d/mysqld
  61. chmod +x /etc/init.d/mysqld
  62. [ "${PM}" == 'yum' ] && { chkconfig --add mysqld; chkconfig mysqld on; }
  63. [ "${PM}" == 'apt-get' ] && update-rc.d mysqld defaults
  64. popd
  65. # my.cnf
  66. cat > /etc/my.cnf << EOF
  67. [client]
  68. port = 3306
  69. socket = /tmp/mysql.sock
  70. [mysqld]
  71. port = 3306
  72. socket = /tmp/mysql.sock
  73. basedir = ${mariadb_install_dir}
  74. datadir = ${mariadb_data_dir}
  75. pid-file = ${mariadb_data_dir}/mysql.pid
  76. user = mysql
  77. bind-address = 0.0.0.0
  78. server-id = 1
  79. init-connect = 'SET NAMES utf8mb4'
  80. character-set-server = utf8mb4
  81. skip-name-resolve
  82. #skip-networking
  83. back_log = 300
  84. max_connections = 1000
  85. max_connect_errors = 6000
  86. open_files_limit = 65535
  87. table_open_cache = 128
  88. max_allowed_packet = 500M
  89. binlog_cache_size = 1M
  90. max_heap_table_size = 8M
  91. tmp_table_size = 16M
  92. read_buffer_size = 2M
  93. read_rnd_buffer_size = 8M
  94. sort_buffer_size = 8M
  95. join_buffer_size = 8M
  96. key_buffer_size = 4M
  97. thread_cache_size = 8
  98. query_cache_type = 1
  99. query_cache_size = 8M
  100. query_cache_limit = 2M
  101. ft_min_word_len = 4
  102. log_bin = mysql-bin
  103. binlog_format = mixed
  104. expire_logs_days = 7
  105. log_error = ${mariadb_data_dir}/mysql-error.log
  106. slow_query_log = 1
  107. long_query_time = 1
  108. slow_query_log_file = ${mariadb_data_dir}/mysql-slow.log
  109. performance_schema = 0
  110. #lower_case_table_names = 1
  111. skip-external-locking
  112. default_storage_engine = InnoDB
  113. #default-storage-engine = MyISAM
  114. innodb_file_per_table = 1
  115. innodb_open_files = 500
  116. innodb_buffer_pool_size = 64M
  117. innodb_write_io_threads = 4
  118. innodb_read_io_threads = 4
  119. innodb_thread_concurrency = 0
  120. innodb_purge_threads = 1
  121. innodb_flush_log_at_trx_commit = 2
  122. innodb_log_buffer_size = 2M
  123. innodb_log_file_size = 32M
  124. innodb_log_files_in_group = 3
  125. innodb_max_dirty_pages_pct = 90
  126. innodb_lock_wait_timeout = 120
  127. bulk_insert_buffer_size = 8M
  128. myisam_sort_buffer_size = 8M
  129. myisam_max_sort_file_size = 10G
  130. myisam_repair_threads = 1
  131. interactive_timeout = 28800
  132. wait_timeout = 28800
  133. [mysqldump]
  134. quick
  135. max_allowed_packet = 500M
  136. [myisamchk]
  137. key_buffer_size = 8M
  138. sort_buffer_size = 8M
  139. read_buffer = 4M
  140. write_buffer = 4M
  141. EOF
  142. sed -i "s@max_connections.*@max_connections = $((${Mem}/3))@" /etc/my.cnf
  143. if [ ${Mem} -gt 1500 -a ${Mem} -le 2500 ]; then
  144. sed -i 's@^thread_cache_size.*@thread_cache_size = 16@' /etc/my.cnf
  145. sed -i 's@^query_cache_size.*@query_cache_size = 16M@' /etc/my.cnf
  146. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 16M@' /etc/my.cnf
  147. sed -i 's@^key_buffer_size.*@key_buffer_size = 16M@' /etc/my.cnf
  148. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 128M@' /etc/my.cnf
  149. sed -i 's@^tmp_table_size.*@tmp_table_size = 32M@' /etc/my.cnf
  150. sed -i 's@^table_open_cache.*@table_open_cache = 256@' /etc/my.cnf
  151. elif [ ${Mem} -gt 2500 -a ${Mem} -le 3500 ]; then
  152. sed -i 's@^thread_cache_size.*@thread_cache_size = 32@' /etc/my.cnf
  153. sed -i 's@^query_cache_size.*@query_cache_size = 32M@' /etc/my.cnf
  154. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 32M@' /etc/my.cnf
  155. sed -i 's@^key_buffer_size.*@key_buffer_size = 64M@' /etc/my.cnf
  156. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 512M@' /etc/my.cnf
  157. sed -i 's@^tmp_table_size.*@tmp_table_size = 64M@' /etc/my.cnf
  158. sed -i 's@^table_open_cache.*@table_open_cache = 512@' /etc/my.cnf
  159. elif [ ${Mem} -gt 3500 ]; then
  160. sed -i 's@^thread_cache_size.*@thread_cache_size = 64@' /etc/my.cnf
  161. sed -i 's@^query_cache_size.*@query_cache_size = 64M@' /etc/my.cnf
  162. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 64M@' /etc/my.cnf
  163. sed -i 's@^key_buffer_size.*@key_buffer_size = 256M@' /etc/my.cnf
  164. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 1024M@' /etc/my.cnf
  165. sed -i 's@^tmp_table_size.*@tmp_table_size = 128M@' /etc/my.cnf
  166. sed -i 's@^table_open_cache.*@table_open_cache = 1024@' /etc/my.cnf
  167. fi
  168. ${mariadb_install_dir}/scripts/mysql_install_db --user=mysql --basedir=${mariadb_install_dir} --datadir=${mariadb_data_dir}
  169. [ "${Wsl}" == true ] && chmod 600 /etc/my.cnf
  170. chown mysql:mysql -R ${mariadb_data_dir}
  171. [ -d "/etc/mysql" ] && /bin/mv /etc/mysql{,_bk}
  172. service mysqld start
  173. [ -z "$(grep ^'export PATH=' /etc/profile)" ] && echo "export PATH=${mariadb_install_dir}/bin:\$PATH" >> /etc/profile
  174. [ -n "$(grep ^'export PATH=' /etc/profile)" -a -z "$(grep ${mariadb_install_dir} /etc/profile)" ] && sed -i "s@^export PATH=\(.*\)@export PATH=${mariadb_install_dir}/bin:\1@" /etc/profile
  175. . /etc/profile
  176. ${mariadb_install_dir}/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"${dbrootpwd}\" with grant option;"
  177. ${mariadb_install_dir}/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"${dbrootpwd}\" with grant option;"
  178. ${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.user where Password='' and User not like 'mariadb.%';"
  179. ${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.db where User='';"
  180. ${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.proxies_priv where Host!='localhost';"
  181. ${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "drop database test;"
  182. ${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "reset master;"
  183. rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona}*.conf
  184. echo "${mariadb_install_dir}/lib" > /etc/ld.so.conf.d/z-mariadb.conf
  185. ldconfig
  186. service mysqld stop
  187. }