mysql-5.5.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # Blog: http://blog.linuxeye.com
  4. Install_MySQL-5-5()
  5. {
  6. cd $oneinstack_dir/src
  7. . ../functions/download.sh
  8. . ../functions/check_os.sh
  9. . ../options.conf
  10. src_url=http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-$mysql_5_version.tar.gz && Download_src
  11. useradd -M -s /sbin/nologin mysql
  12. mkdir -p $mysql_data_dir;chown mysql.mysql -R $mysql_data_dir
  13. tar zxf mysql-$mysql_5_version.tar.gz
  14. cd mysql-$mysql_5_version
  15. if [ "$je_tc_malloc" == '1' ];then
  16. EXE_LINKER="-DCMAKE_EXE_LINKER_FLAGS='-ljemalloc'"
  17. elif [ "$je_tc_malloc" == '2' ];then
  18. EXE_LINKER="-DCMAKE_EXE_LINKER_FLAGS='-ltcmalloc'"
  19. fi
  20. make clean
  21. [ ! -d "$mysql_install_dir" ] && mkdir -p $mysql_install_dir
  22. cmake . -DCMAKE_INSTALL_PREFIX=$mysql_install_dir \
  23. -DMYSQL_DATADIR=$mysql_data_dir \
  24. -DSYSCONFDIR=/etc \
  25. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  26. -DWITH_PARTITION_STORAGE_ENGINE=1 \
  27. -DWITH_FEDERATED_STORAGE_ENGINE=1 \
  28. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
  29. -DWITH_MYISAM_STORAGE_ENGINE=1 \
  30. -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
  31. -DWITH_READLINE=1 \
  32. -DENABLED_LOCAL_INFILE=1 \
  33. -DENABLE_DTRACE=0 \
  34. -DDEFAULT_CHARSET=utf8 \
  35. -DDEFAULT_COLLATION=utf8_general_ci \
  36. -DWITH_EMBEDDED_SERVER=1 \
  37. $EXE_LINKER
  38. make -j `grep processor /proc/cpuinfo | wc -l`
  39. make install
  40. if [ -d "$mysql_install_dir/bin" ];then
  41. echo -e "\033[32mMySQL install successfully! \033[0m"
  42. else
  43. rm -rf $mysql_install_dir
  44. echo -e "\033[31mMySQL install failed, Please contact the author! \033[0m"
  45. kill -9 $$
  46. fi
  47. /bin/cp support-files/mysql.server /etc/init.d/mysqld
  48. chmod +x /etc/init.d/mysqld
  49. OS_CentOS='chkconfig --add mysqld \n
  50. chkconfig mysqld on'
  51. OS_Debian_Ubuntu='update-rc.d mysqld defaults'
  52. OS_command
  53. cd ..
  54. [ -d "$mysql_install_dir" ] && /bin/rm -rf mysql-$mysql_5_version
  55. cd ..
  56. # my.cf
  57. cat > /etc/my.cnf << EOF
  58. [client]
  59. port = 3306
  60. socket = /tmp/mysql.sock
  61. [mysqld]
  62. port = 3306
  63. socket = /tmp/mysql.sock
  64. basedir = $mysql_install_dir
  65. datadir = $mysql_data_dir
  66. pid-file = $mysql_data_dir/mysql.pid
  67. user = mysql
  68. bind-address = 0.0.0.0
  69. server-id = 1
  70. skip-name-resolve
  71. #skip-networking
  72. back_log = 300
  73. max_connections = 1000
  74. max_connect_errors = 6000
  75. open_files_limit = 65535
  76. table_open_cache = 128
  77. max_allowed_packet = 4M
  78. binlog_cache_size = 1M
  79. max_heap_table_size = 8M
  80. tmp_table_size = 16M
  81. read_buffer_size = 2M
  82. read_rnd_buffer_size = 8M
  83. sort_buffer_size = 8M
  84. join_buffer_size = 8M
  85. key_buffer_size = 4M
  86. thread_cache_size = 8
  87. query_cache_type = 1
  88. query_cache_size = 8M
  89. query_cache_limit = 2M
  90. ft_min_word_len = 4
  91. log_bin = mysql-bin
  92. binlog_format = mixed
  93. expire_logs_days = 30
  94. log_error = $mysql_data_dir/mysql-error.log
  95. slow_query_log = 1
  96. long_query_time = 1
  97. slow_query_log_file = $mysql_data_dir/mysql-slow.log
  98. performance_schema = 0
  99. #lower_case_table_names = 1
  100. skip-external-locking
  101. default_storage_engine = InnoDB
  102. #default-storage-engine = MyISAM
  103. innodb_file_per_table = 1
  104. innodb_open_files = 500
  105. innodb_buffer_pool_size = 64M
  106. innodb_write_io_threads = 4
  107. innodb_read_io_threads = 4
  108. innodb_thread_concurrency = 0
  109. innodb_purge_threads = 1
  110. innodb_flush_log_at_trx_commit = 2
  111. innodb_log_buffer_size = 2M
  112. innodb_log_file_size = 32M
  113. innodb_log_files_in_group = 3
  114. innodb_max_dirty_pages_pct = 90
  115. innodb_lock_wait_timeout = 120
  116. bulk_insert_buffer_size = 8M
  117. myisam_sort_buffer_size = 8M
  118. myisam_max_sort_file_size = 10G
  119. myisam_repair_threads = 1
  120. interactive_timeout = 28800
  121. wait_timeout = 28800
  122. [mysqldump]
  123. quick
  124. max_allowed_packet = 16M
  125. [myisamchk]
  126. key_buffer_size = 8M
  127. sort_buffer_size = 8M
  128. read_buffer = 4M
  129. write_buffer = 4M
  130. EOF
  131. Memtatol=`free -m | grep 'Mem:' | awk '{print $2}'`
  132. if [ $Memtatol -gt 1500 -a $Memtatol -le 2500 ];then
  133. sed -i 's@^thread_cache_size.*@thread_cache_size = 16@' /etc/my.cnf
  134. sed -i 's@^query_cache_size.*@query_cache_size = 16M@' /etc/my.cnf
  135. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 16M@' /etc/my.cnf
  136. sed -i 's@^key_buffer_size.*@key_buffer_size = 16M@' /etc/my.cnf
  137. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 128M@' /etc/my.cnf
  138. sed -i 's@^tmp_table_size.*@tmp_table_size = 32M@' /etc/my.cnf
  139. sed -i 's@^table_open_cache.*@table_open_cache = 256@' /etc/my.cnf
  140. elif [ $Memtatol -gt 2500 -a $Memtatol -le 3500 ];then
  141. sed -i 's@^thread_cache_size.*@thread_cache_size = 32@' /etc/my.cnf
  142. sed -i 's@^query_cache_size.*@query_cache_size = 32M@' /etc/my.cnf
  143. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 32M@' /etc/my.cnf
  144. sed -i 's@^key_buffer_size.*@key_buffer_size = 64M@' /etc/my.cnf
  145. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 512M@' /etc/my.cnf
  146. sed -i 's@^tmp_table_size.*@tmp_table_size = 64M@' /etc/my.cnf
  147. sed -i 's@^table_open_cache.*@table_open_cache = 512@' /etc/my.cnf
  148. elif [ $Memtatol -gt 3500 ];then
  149. sed -i 's@^thread_cache_size.*@thread_cache_size = 64@' /etc/my.cnf
  150. sed -i 's@^query_cache_size.*@query_cache_size = 64M@' /etc/my.cnf
  151. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 64M@' /etc/my.cnf
  152. sed -i 's@^key_buffer_size.*@key_buffer_size = 256M@' /etc/my.cnf
  153. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 1024M@' /etc/my.cnf
  154. sed -i 's@^tmp_table_size.*@tmp_table_size = 128M@' /etc/my.cnf
  155. sed -i 's@^table_open_cache.*@table_open_cache = 1024@' /etc/my.cnf
  156. fi
  157. $mysql_install_dir/scripts/mysql_install_db --user=mysql --basedir=$mysql_install_dir --datadir=$mysql_data_dir
  158. chown mysql.mysql -R $mysql_data_dir
  159. service mysqld start
  160. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$mysql_install_dir/bin:\$PATH" >> /etc/profile
  161. [ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep $mysql_install_dir /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=$mysql_install_dir/bin:\1@" /etc/profile
  162. . /etc/profile
  163. $mysql_install_dir/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"$dbrootpwd\" with grant option;"
  164. $mysql_install_dir/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"$dbrootpwd\" with grant option;"
  165. $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.user where Password='';"
  166. $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.db where User='';"
  167. $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies_priv where Host!='localhost';"
  168. $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
  169. $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
  170. sed -i "s@^db_install_dir.*@db_install_dir=$mysql_install_dir@" options.conf
  171. sed -i "s@^db_data_dir.*@db_data_dir=$mysql_data_dir@" options.conf
  172. service mysqld stop
  173. }