MySQL 5.5之后的源码包版本,安装方式采用CMake工具编译进行安装,因此在安装最新版MySQL之前,需要提前安装它。CMake是一个跨平台、开源软件构建系统,用于控制软件编译过程及生成独立的配置文件(makefile或者project),可以在编译时选择CMake编译器进行安装需要的软件。CMake官网https://cmake.org/,目前最新版本是3.4.3。
CMake安装方法
# wget https://cmake.org/files/v3.4/cmake-3.4.3.tar.gz
# yum install gcc gcc-c++ make automake
# ./bootstrap && make && make install
MySQL 5.6新特性
MySQL官网对MySQL 5.6的介绍:
MySQL5.6是有史以来最好的版本,是世界上最广为使用的开源数据库,它提供了一套新的、先进的功能,使我们能建设的新一代基于网络和嵌入式应用和服务。
MySQL5.6的功能和特性
1、更好的性能和可扩展性
改进InnoDB存储引擎所带来更好的交易吞吐量
改良的优化所带来更好的查询执行时间和诊断能力
2、在线DDL /架构操作所带来更好的应用程序可用性
3、通过Memcached的API以NoSQL访问InnoDB所带来的更好的开发速度
4、改进复制技术所带来的高性能和能自行修复的集群部署
5、改进的Performance Schema所带来的更好的侦测和监测能力
6、改进的安全控制,使您部署应用程序时不需担心
7、其他重要的增强功能
MySQL5.6编译参数
官方文档:http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html
编译安装mysql-5.6.28
step1:创建mysql用户、组
[root@www ~]# groupadd mysql
[root@www ~]# useradd -r -g mysql mysql
[root@www ~]# id mysql
uid=996(mysql) gid=1000(mysql) groups=1000(mysql)
[root@www ~]# mkdir /usr/local/mysql
[root@www ~]# mkdir /data/mysqldb
step2:安装必须的软件包
[root@www src]# yum install gcc gcc-c++ ncurses-devel bison bison-devel
step3:编译安装MySQL
1、将下载的mysql源码包解压,并进入其解压目录下
[root@www mysql-5.6.28]# cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysqldb \
-DSYSCONFDIR=/etc \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0
重新cmake需要删除CMakeCache.txt文件
[root@www mysql-5.6.28]# gmake
[root@www mysql-5.6.28]# gmake install
[root@www mysql-5.6.28]# ls /usr/local/mysql/ COPYING README data include man scripts sql-bench INSTALL-BINARY bin docs lib mysql-test share support-files
2、设置MySQL目录权限
[root@www mysql-5.6.28]# chown -R root:mysql /usr/local/mysql/ [root@www mysql-5.6.28]# chown -R mysql:mysql /data/mysqldb/
3、安装系统数据库
[root@www scripts]# chmod +x mysql_install_db [root@www scripts]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysqldb --no-defaults --user=mysql [root@www scripts]# ls /data/mysqldb/ ib_logfile0 ib_logfile1 ibdata1 mysql performance_schema test
4、拷贝配置文件my.cnf
[root@www mysql-5.6.28]# cd support-files/ [root@www support-files]# cp my-default.cnf /etc/my.cnf
[root@www support-files]# vim /etc/my.cnf [mysqld] basedir = /usr/local/mysql datadir = /data/mysqldb port = 3306 # server_id = ..... socket = /var/lib/mysql/mysql.sock
5、拷贝启动脚本
[root@www support-files]# cp mysql.server /etc/init.d/mysqld [root@www support-files]# chmod 755 /etc/init.d/mysqld [root@www support-files]# chkconfig mysqld on [root@www ~]# service mysqld restart Shutting down MySQL. SUCCESS! Starting MySQL. SUCCESS! [root@www ~]# netstat -ntlp |grep mysqld tcp6 0 0 :::3306 :::* LISTEN 20708/mysqld
6、设置mysql环境变量
[root@www ~]# vim /etc/profile.d/path.sh #!/bin/bash export PATH=$PATH:/usr/local/mysql/bin [root@www ~]# source /etc/profile [root@www ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.28 Source distribution Copyright (c) 2000, 2015, 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>
7、初始化MySQL及相关安全选项配置
[root@www ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! Cleaning up...
MySQL优化配置
[root@www ~]# vim /etc/my.cnf
[mysqld] basedir = /usr/local/mysql datadir = /data/mysqldb port = 3306 socket = /var/lib/mysql/mysql.sock key_buffer_size = 256M sort_buffer_size = 2M read_buffer_size = 1M read_rnd_buffer_size = 8M myisam_sort_buffer_size = 64M net_buffer_length = 8K table_open_cache = 1024 query_cache_size = 32M thread_cache_size = 8 max_connections = 1000 max_allowed_packet = 4M tmp_table_size = 16M thread_concurrency = 8 skip-name-resolve interactive_timeout = 8 wait_timeout = 8 long_query_time = 2 slow_query_log=on slow_query_log_file = /data/mysql/mysql.slow long_query_time = 1
[root@www ~]# systemctl restart mysqld.service
防火墙配置
[root@www ~]# firewall-cmd --permanent --add-port=3306/tcp
[root@www ~]# firewall-cmd --reload