首页 / 数据库 / MySQL / 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 save2:安装相关依赖包
# yum -y install gcc gcc-c++ ncurses ncurses-devel openssl openssl-devel cmake perl lsof bison3:删除自带的mysql
# rpm -qa|grep mysql
# rpm -e --allmatches --nodeps mysql-libs-5.1.71-1.el6.x86_644:创建相关目录
# 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 install7:修改相关目录权限并创建软连接
# 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/bin8:修改配置文件
# 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 = true9:安装mysql数据库
# /doiido/server/mysql/scripts/mysql_install_db --basedir=/doiido/server/mysql --datadir=/doiido/mysql/data --user=mysql10:设置mysql开机自动启动服务
# cp /doiido/server/mysql/support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --level 345 mysqld on11:修改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.gz1:安装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 install2:安装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/ldconfig3:修改MySQL启动脚本(根据MySQL安装位置而定):
# vi /doiido/server/mysql/bin/mysqld_safe
在# executing mysqld_safe的下面加上:export LD_PRELOAD=/usr/local/lib/libtcmalloc.so# service mysqld restart4:查看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 http://www.linuxidc.com/Linux/2014-05/102366.htm《MySQL权威指南(原书第2版)》清晰中文扫描版 PDF http://www.linuxidc.com/Linux/2014-03/98821.htmUbuntu 14.04 LTS 安装 LNMP NginxPHP5 (PHP-FPM)MySQL http://www.linuxidc.com/Linux/2014-05/102351.htmUbuntu 14.04下搭建MySQL主从服务器 http://www.linuxidc.com/Linux/2014-05/101599.htmUbuntu 12.04 LTS 构建高可用分布式 MySQL 集群 http://www.linuxidc.com/Linux/2013-11/93019.htmUbuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb http://www.linuxidc.com/Linux/2013-08/89270.htmMySQL-5.5.38通用二进制安装 http://www.linuxidc.com/Linux/2014-07/104509.htm--------------------------------------分割线 --------------------------------------本文永久更新链接地址