从mysql-5.6开始,Mysql改为用cmake编译安装。安装方法如下:
一、检查&安装cmake
[root@Mysql-249 ~]# rpm -qa cmake
cmake-2.8.12.2-4.el6.x86_64
如未安装,用yum方式安装cmake
yum install cmake -y
安装其他依赖包
yum install gcc gcc-c++ cmake ncurses-devel bison perl -y
二、环境配置
[root@Mysql-249 ~]#mkdir -p /www/data
[root@Mysql-249 ~]#useradd mysql
[root@Mysql-249 ~]#chown -R mysql:mysql /www/data/
三、安装包准备
[root@Mysql-249 ~]# cd /usr/local/src/
[root@Mysql-249 src]# wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.30.tar.gz
[root@Mysql-249 src]# tar -xzf mysql-5.6.30.tar.gz
[root@Mysql-249 src]# cd mysql-5.6.30
四、编译安装
[root@Mysql-249 mysql-5.6.30]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.30 \
-DMYSQL_DATADIR=/www/data \
-DSYSCONFDIR=/etc/my.cnf \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/www/data/mysqld.sock \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_TCP_PORT=3306
[root@Mysql-249 mysql-5.6.30]# make && make install
五、修改Mysql配置文件
[root@Mysql-249 mysql-5.6.30]# cat > /etc/my.cnf <<EOF
[mysqld]
datadir=/www/data
socket=/www/data/mysqld.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/www/data/mysqld.log
pid-file=/www/data/mysqld.pid
EOF
六、添加Mysql服务,配置开机自动启动
[root@Mysql-249 mysql-5.6.30]#cp /usr/local/mysql-5.6.30/support-files/mysql.server /etc/init.d/mysqld
[root@Mysql-249 mysql-5.6.30]#chkconfig --add mysqld
[root@Mysql-249 mysql-5.6.30]#chkconfig mysqld --level 345 on
七、初始化数据库,设置Mysql超级用户密码
[root@Mysql-249 mysql-5.6.30]# ln -s /usr/local/mysql-5.6.30 /usr/local/mysql
[root@Mysql-249 mysql-5.6.30]# ln -s /usr/local/mysql/bin/* /usr/bin/
[root@Mysql-249 mysql-5.6.30]# ln -s /usr/local/mysql/include/* /usr/local/include/
[root@Mysql-249 mysql-5.6.30]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/www/data/ --user=mysql
[root@Mysql-249 mysql-5.6.30]# /etc/init.d/mysqld start
[root@Mysql-249 mysql-5.6.30]# /usr/local/mysql/bin/mysql_secure_installation
八、Mysql测试
[root@Mysql-249 mysql-5.6.30]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.30 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> \s
--------------
mysql Ver 14.14 Distrib 5.6.30, for Linux (x86_64) using EditLine wrapper
Connection id: 1
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.6.30 Source distribution
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /www/data/mysqld.sock
Uptime: 16 sec
Threads: 1 Questions: 5 Slow queries: 0 Opens: 70 Flush tables: 1 Open tables: 63 Queries per second avg: 0.312
--------------
编译参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.30 #Mysql安装路径
-DMYSQL_DATADIR=/www/data #数据存放路径
-DSYSCONFDIR=/etc/my.cnf #配置文件路径
-DWITH_MYISAM_STORAGE_ENGINE=1 #支持MyISAM存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 #支持INNODB存储引擎
-DWITH_MEMORY_STORAGE_ENGINE=1 #支持MEMORY引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 #支持ARCHIVE引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 #支持数据库分区
-DWITH_READLINE=1 #支持快捷键
-DMYSQL_UNIX_ADDR=/www/data/mysqld.sock#Unixsocket文件路径
-DENABLED_LOCAL_INFILE=1 #允许本地导入数据库
-DEXTRA_CHARSETS=all #安装所有字符集
-DDEFAULT_CHARSET=utf8 #设置默认字符集为UTF8
-DDEFAULT_COLLATION=utf8_general_ci #设置默认字符校验
-DMYSQL_TCP_PORT=3306 #设置Mysql端口