一、安装环境:CentOS 7 Linux version 3.10.0-229.el7.x86_64 Nginx-1.9.12

                          Mysql-5.6.14

二、安装步骤

2.1 安装mysql相关的组件

命令:yum install –y autoconf automake imake libxml2-devel expat-devel cmake gcc gcc-c++ libaio libaio-devel bzr bison libtool ncurses5-devel

CentOS 7 安装 mysql-5.6.14_第1张图片

2.2 下载mysql-5.6.14

命令:cd /usr/local/src

wget -c http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz/from/http://cdn.mysql.com/ -O mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz

2016-04-11 00-09-36

2.3 解压并移动mysql文件夾

命令:tar –zxf mysql-5.6.14-linux-glibc2.5-x86_64 .tar.gz

CentOS 7 安装 mysql-5.6.14_第2张图片

命令:mv mysql-5.6.14-linux-glibc2.5-x86_64 ../mysql

CentOS 7 安装 mysql-5.6.14_第3张图片

2.4 创建mysql用户组和用户,及数据库存放目录

mkdir -p /data/mysql_data  
mkdir -p /data/mysql_log    
mkdir -p /data/log-bin    
groupadd mysql    
useradd mysql -g mysql -M -s /sbin/nologin    
chown -R mysql.mysql /data/mysql_data /data/mysql_log /data/log-bin    
chown -R mysql.mysql /usr/local/mysql

5-usrerconf

2.5 配置mysql文件my.cnf

命令:vim /etc/my.cnf

配置内容:

[mysqld]  
# GENERAL #    
user = mysql    
default-storage-engine = InnoDB    
socket = /data/mysql_data/mysql.sock    
port = 3306    
explicit_defaults_for_timestamp=true    
# MyISAM #    
key_buffer_size = 1344M    
myisam_recover = FORCE,BACKUP    
# SAFETY #    
max_allowed_packet = 16M    
max_connect_errors = 1000000    
skip_name_resolve    
# DATA STORAGE #    
datadir = /data/mysql_data/    
long_query_time = 1    
# BINARY LOGGING #    
log-bin = /data/log-bin/mysql-bin-3306    
expire-logs-days = 14    
sync-binlog = 1    
server-id = 1    
max_binlog_size = 500M    
# REPLICATION #    
relay-log = /data/log-bin/relay-bin-3306    
slave-net-timeout = 60    
# CACHES AND LIMITS #    
tmp_table_size = 32M    
max_heap_table_size = 32M    
max_connections = 500    
thread_cache_size = 50    
open_files_limit = 65535    
table_definition_cache = 4096    
table_open_cache = 4096    
# INNODB #    
innodb_data_file_path = ibdata1:128M;ibdata2:10M:autoextend    
innodb_flush_method = O_DIRECT    
innodb_log_files_in_group = 2    
innodb_lock_wait_timeout = 50    
innodb_log_file_size = 256M    
innodb_flush_log_at_trx_commit = 1    
innodb_file_per_table = 1    
innodb_thread_concurrency = 8    
innodb_buffer_pool_size = 8G    
# LOGGING #    
log-error = /data/mysql_log/mysql-error-3306.log    
log-queries-not-using-indexes = 1    
slow-query-log = 1    
long_query_time = 1    
slow-query-log-file = /data/mysql_log/mysql-slow-3306.log    
# FOR SLAVE #    
#binlog-format = ROW    
#log-slave-updates = true    
#gtid-mode = on    
#enforce-gtid-consistency = true    
#master-info-repository = TABLE    
#relay-log-info-repository = TABLE    
#sync-master-info = 1    
#slave-parallel-workers = 2    
#binlog-checksum = CRC32    
#master-verify-checksum = 1    
#slave-sql-verify-checksum = 1    
#binlog-rows-query-log_events = 1    
#report-port = 3306    
#report-host = 192.168.41.98

[mysqld_safe]  
pid-file=/data/mysql_data/mysql.pid    
[mysql]    
socket=/data/mysql_data/mysql.sock    
[mysqldump]    
socket=/data/mysql_data/mysql.sock    
[mysqladmin]    
socket=/data/mysql_data/mysql.sock

CentOS 7 安装 mysql-5.6.14_第4张图片

2.6 配置mysql为系统服务并设置成开机启动

命令1:cp -af /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

           vim /etc/init.d/mysqld

修改以下内容并保存

basedir=/usr/local/mysql  
datadir=/data/mysql_data

8-mysqld

命令2:chmod 755 /etc/init.d/mysqld  
             chkconfig --add mysqld    
             chkconfig --level 345 mysqld on

             chkconfig --list

CentOS 7 安装 mysql-5.6.14_第5张图片

2.7 初始化数据库

命令:cd /usr/local/mysql  
           ./scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf

CentOS 7 安装 mysql-5.6.14_第6张图片

2.8 启动、关闭与重启mysql服务

命令:service mysqld start  #启动mysql服务

service mysqld stop  #关闭mysql服务

           service mysqld restart  #重启mysql服务

10-mysqlstart

2.9 修改root 密码并设置登陆权限

命令:

ln -s /usr/local/mysql/bin/mysql /usr/bin

mysql -uroot    #root用户初始密码为空,直接输入此命令即可登陆mysql  
>set password for 'root'@'localhost' = password('HKbfmysql'); #配置root密码为HKbfmysql    
>grant all privileges on *.* to 'root'@'%' identified by 'HKbfmysql' with grant option; #配置允许所有主机可以用root用户登陆mysql

>exit

CentOS 7 安装 mysql-5.6.14_第7张图片

12-everaddlogin