背景:
阅读新闻
Linux下 MySQL 安装以及优化
[日期:2015-02-28] 来源:Linux社区 作者:doiido [字体:]
系统环境: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
--------------------------------------分割线 --------------------------------------
Ubuntu 14.04下安装MySQL