Linux下Mysql安裝以及優化
系統環境:CentOS 6.5
mysql版本:mysql-5.6.19.tar.gz
軟件上傳路徑:/doiido/soft
一、Mysql安裝
1:防火牆打開相應端口
# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
# /etc/rc.d/init.d/iptables save
2:安裝相關依賴包
# yum -y install gcc gcc-c++ ncurses ncurses-devel openssl openssl-devel cmake perl lsof bison
3:刪除自帶的mysql
# rpm -qa|grep mysql
# rpm -e --allmatches --nodeps mysql-libs-5.1.71-1.el6.x86_64
4:創建相關目錄
# mkdir /doiido/soft
# mkdir -p /doiido/mysql/data/
5:創建mysql用戶
# /usr/sbin/groupadd mysql
# /usr/sbin/useradd -s /sbin/nologin -M -g mysql mysql
# chown -R mysql:mysql /doiido/mysql/
6:安裝mysql
# cd /doiido/soft
# tar -zxvf mysql-5.6.19.tar.gz
# cd mysql-5.6.19
# cmake -DCMAKE_INSTALL_PREFIX=/doiido/server/mysql -DMYSQL_DATADIR=/doiido/mysql/data -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DSYSCONFDIR=/etc/ -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
-DWITH_READLINE=on
# make && make install
7:修改相關目錄權限並創建軟連接
# chmod +w /doiido/server/mysql
# chown -R mysql:mysql /doiido/server/mysql/
# ln -s /doiido/server/mysql/lib/lib* /usr/lib/
# ln -s /doiido/server/mysql/bin/mysql /usr/bin
8:修改配置文件
# cp /doiido/server/mysql/support-files/my-default.cnf /etc/my.cnf
# vi /etc/my.cnf
[mysqld]
character-set-server = utf8
default-storage-engine = MyISAM
basedir = /doiido/server/mysql
datadir = /doiido/mysql/data
log-error = /doiido/mysql/mysql_error.log
pid-file = /doiido/mysql/mysql.pid
max_allowed_packet = 32M
explicit_defaults_for_timestamp = true
9:安裝mysql數據庫
# /doiido/server/mysql/scripts/mysql_install_db --basedir=/doiido/server/mysql --datadir=/doiido/mysql/data --user=mysql
10:設置mysql開機自動啟動服務
# cp /doiido/server/mysql/support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --level 345 mysqld on
11:修改mysqld文件並啟動mysql
# vi /etc/init.d/mysqld
#修改mysqld文件中的下面兩項
basedir=/doiido/server/mysql
datadir=/doiido/mysql/data
# service mysqld start
二、mysql優化
軟件版本
libunwind:libunwind-1.1.tar.gz
google-perftools:gperftools-2.2.tar.gz
1:安裝libunwind(基於64位)
# cd /doiido/soft
# tar zxvf libunwind-1.1.tar.gz
# cd libunwind-1.1
# CFLAGS=-fPIC ./configure
# make CFLAGS=-fPIC
# make CFLAGS=-fPIC install
2:安裝google-perftools:
# cd /doiido/soft
# tar zxvf gperftools-2.2.tar.gz
# cd gperftools-2.2/
# ./configure
# make && make install
# echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
# /sbin/ldconfig
3:修改MySQL啟動腳本(根據MySQL安裝位置而定):
# vi /doiido/server/mysql/bin/mysqld_safe
在# executing mysqld_safe的下面加上:
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
# service mysqld restart
4:查看tcmalloc是否起效:
# /usr/sbin/lsof -n | grep tcmalloc
如果發現以下信息,說明tcmalloc已經起效:
mysqld 11227 mysql mem REG 8,1 2171746 18287 /usr/local/lib/libtcmalloc.so.4.1.2