编译安装mysql-server5.6.32

摘自:http://www.cnblogs.com/yaohan/p/6288620.html

1
2
wget http://downloads.mysql.com/archives/get/file/mysql-5.6.32.tar.gz  
tar -zxvf mysql-5.6.32.tar.gz

安装编译环境

1
2
3
4
5
6
yum install gcc gcc-c++
yum install -y ncurses-devel
yum install -y cmake
yum install -y libaio
yum install -y bison
yum install -y perl-Module-Install.noarch

编译

1
2
3
4
5
6
7
8
9
10
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DMYSQL_DATADIR=/home/mysqldata
-DMYSQL_TCP_PORT=3306
-DENABLE_DOWNLOADS=1

若要重新运行配置,需要删除目录内CMakeCache.txt文件

1
rm CMakeCache.txt
1
make && make install

使用下面的命令查看是否有mysql用户及用户组

1
2
3
4
5
6
7
8
cat /etc/passwd   #查看用户列表
cat /etc/group #查看用户组列表

如果没有就创建
groupadd mysql
useradd -g mysql mysql
修改/usr/local/mysql权限
chown -R mysql:mysql /usr/local/mysql

修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
cp support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf


-----my.cnf begin------
[client]
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
default-character-set=utf8


[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /home/mysqldata/
port = 3306
# server_id = .....
socket = /usr/local/mysql/mysql.sock
character-set-server=utf8
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
-----my.cnf end------

初始化数据库

1
2
cd /usr/local/mysql/
./scripts/mysql_install_db --user=mysql --datadir=/home/mysqldata

修改文件和目录权限,否则开启服务会报错

1
2
chown -R mysql:root /usr/local/mysql/mysql.sock
chown -R mysql:root /usr/local/mysql

测试开启编译安装的Mysql

1
/usr/local/mysql/bin/mysqld_safe

运行正常则添加启动脚本

1
2
3
4
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
service mysql start --启动MySQL
ln -s /usr/local/mysql/bin/mysql /usr/bin
------ end ------
0%