centos 6.5下通过yum安装的mysql是5.1版的,于是想通过源代码安装高版本的5.6.15。
版本为 Percona 5.6.15源码版,下载地址:
http://www.percona.com/redir/downloads/Percona-Server-5.6/LATEST/source/Percona-Server-5.6.15-rel63.0.tar.gz
一、卸载原有MySQL
检查是否安装有MySQL Server:
复制代码 代码示例:
rpm -qa | grep mysql
删除方法:
复制代码 代码示例:
rpm -e mysql #普通删除模式
rpm -e --nodeps mysql #强行删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其强行删除。
二、安装gcc编译环境
复制代码 代码示例:
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
三、安装CMake
下载地址:
http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz
切换到root用户,使用命令安装:
复制代码 代码示例:
./bootstrap
#检查无误后安装
make && make install
四、安装MySQL
1,设置权限
复制代码 代码示例:
groupadd dba
useradd mysql -g dba
2,设置安装环境
复制代码 代码示例:
#为保证数据安全,将数据单独存盘于/data目录下
mkdir /app/mysql
mkdir /data/mysql
cd /data/mysql
mkdir run data tmp logs
chown -R mysql:dba /app/mysql
chown -R mysql:dba /data/mysql
3,安装mysql(Percona 5.6.15)
复制代码 代码示例:
tar zxvf Percona-Server-5.6.15-rel63.0.tar.gz
cd Percona-Server-5.6.15
cmake . -LH
cmake .
-DCMAKE_INSTALL_PREFIX=/app/mysql #设置程序安装路径
-DMYSQL_DATADIR=/data/mysql/data #设置数据存放路径
-DSYSCONFDIR=/etc
-DWITH_
myisam_STORAGE_ENGINE=1 #启用MYISAM存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_READLINE=1 #启用MySQL快捷键
-DMYSQL_UNIX_ADDR=/data/mysql/run/mysqld.sock #设置套接字存放位置
-DMYSQL_TCP_PORT=3306 #设置开放端口
-DENABLED_LOCAL_INFILE=1 #设置读取本地文件
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 #默认字符串
-DDEFAULT_COLLATION=utf8_general_ci #默认检验规则
#以上代码为方便查看,若直接执行,可使用下面代码
cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/data/mysql/run/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make -j 4 && make install
4,安装完成Percona 5.6.15后,开始建立配置文件。
复制代码 代码示例:
chown mysql:dba /etc/my.cnf
vim /etc/my.cnf
[client]
#password = your_password
port = 3306
socket = /data/mysql/run/mysql.sock
default-character-set=utf8
[mysqld]
port = 3306
socket = /data/mysql/run/mysql.sock
baserdir = /app/mysql
datadir = /data/mysql/data
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
default-storage-engine =
innodb
character_set_server = utf8
tmpdir = /data/mysql/tmp/
log-bin=/data/mysql/logs/mysql-bin
expire_logs_days= 14
binlog_format=mixed
log-error = /data/mysql/logs/error.log
slow-query-log = 1
long_query_time= 3
slow_query_log_file = /data/mysql/logs/slow.log
server-id = 1
innodb_data_home_dir = /data/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /data/mysql/logs
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_file_per_table = 1
[
mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
5,初始MySQL配置表(用户权限表等)
复制代码 代码示例:
./scripts/mysql_install_db --ba
sedir=/app/mysql --datadir=/data/mysql/data --user=mysql --force
6,设置开机启动
复制代码 代码示例:
su -
cp /app/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig -add mysql
chkconfig --level 345 mysql on
7,修改Path变量
vim /etc/profile
在句末加入
复制代码 代码示例:
PATH=/app/mysql/bin:$PATH
export PATH
启用PATH
复制代码 代码示例:
. /etc/profile
#or
source /etc/profile
8,启动MySQL,并设置密码
复制代码 代码示例:
service mysql start
mysqladmin -uroot password '******'
至此,成功安装Percona 5.6.15。