#============== Install mysql 5.5.23 ==================#
#使用Tcmalloc 优化nginx、mysql
#64位操作系统请先安装 libunwind库,32位操作系统不要安装。libunwind库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能,其中包括用于输出堆栈跟踪的API、用于以编程方式辗转开解堆栈的API以及支持C++异常处理机制的API
- cd /opt
- tar -zxvf libunwind-1.0.1.tar.gz
- cd libunwind-1.0.1
- ./configure
- make;make install
- cd ../
- tar -zxvf gperftools-2.0.tar.gz
- cd gperftools-2.0
- ./configure
- make;make install
- echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
- /sbin/ldconfig
- cd ../
- tar -zxvf cmake-2.8.8.tar.gz
- cd cmake-2.8.8
- ./bootstrap
- gmake
- gmake install
- cd ../
- /usr/sbin/groupadd mysql
- /usr/sbin/useradd -g mysql mysql -s /sbin/nologin
- mkdir -p /data/mysql/{data,binlog,relaylog,mysql}
- chown -R mysql:mysql /data/mysql
- cd /opt
- tar zxvf mysql-5.5.23.tar.gz
- cd mysql-5.5.23/
- rm -rf CMakeCache.txt
- cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
- -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
- -DDEFAULT_CHARSET=utf8 \
- -DDEFAULT_COLLATION=utf8_general_ci \
- -DEXTRA_CHARSETS=all \
- -DWITH_MYISAM_STORAGE_ENGINE=1 \
- -DWITH_INNOBASE_STORAGE_ENGINE=1 \
- -DWITH_READLINE=1 \
- -DENABLED_LOCAL_INFILE=1 \
- -DMYSQL_DATADIR=/data/mysql/data \
- -DMYSQL_TCP_PORT=3306
- make;make install
- chmod +w /usr/local/mysql
- chown -R mysql:mysql /usr/local/mysql
- ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
#编辑mysql配置文件
- cat >> /etc/my.cnf <<EOF
- [client]
- port = 3306
- socket = /data/mysql/mysql.sock
- [mysqld]
- character_set_server = utf8
- collation-server = utf8_general_ci
- replicate-ignore-db = mysql
- replicate-ignore-db = test
- replicate-ignore-db = information_schema
- user = mysql
- port = 3306
- socket = /data/mysql/mysql.sock
- basedir = /usr/local/mysql
- datadir = /data/mysql/data
- log-error = /data/mysql/mysql_error.log
- pid-file = /data/mysql/mysql.pid
- open_files_limit = 10240
- back_log = 600
- max_connections = 5000
- max_connect_errors = 6000
- table_cache = 512
- external-locking = FALSE
- max_allowed_packet = 32M
- sort_buffer_size = 6M
- join_buffer_size = 8M
- thread_cache_size = 300
- thread_concurrency = 8
- query_cache_size = 512M
- query_cache_limit = 2M
- query_cache_min_res_unit = 2k
- default-storage-engine = MyISAM
- thread_stack = 256K
- transaction_isolation = READ-COMMITTED
- tmp_table_size = 256M
- max_heap_table_size = 256M
- long_query_time = 3
- log-slave-updates
- log-bin = /data/mysql/binlog/binlog
- binlog_cache_size = 4M
- binlog_format = MIXED
- max_binlog_cache_size = 8M
- max_binlog_size = 100M
- relay-log-index = /data/mysql/relaylog/relaylog
- relay-log-info-file = /data/mysql/relaylog/relaylog
- relay-log = /data/mysql/relaylog/relaylog
- expire_logs_days = 30
- key_buffer_size = 384M
- read_buffer_size = 4M
- read_rnd_buffer_size = 16M
- bulk_insert_buffer_size = 64M
- myisam_sort_buffer_size = 128M
- myisam_max_sort_file_size = 10G
- myisam_repair_threads = 1
- myisam_recover
- interactive_timeout = 120
- wait_timeout = 120
- skip_external_locking
- skip-name-resolve
- #master-connect-retry = 10
- slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
- #master-host = 192.168.1.2
- #master-user = username
- #master-password = password
- #master-port = 3306
- server-id = 1
- skip-innodb
- #log-slow-queries = /data/mysql/slow.log
- #long_query_time = 10
- [mysqldump]
- quick
- max_allowed_packet = 32M
- EOF
#初始化mysql
- /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql
