在CentOS 6.5 安装配置 MySQL 5.6

1.1 在CentOS 6.5 安装配置 Mysql5.6

CentOS 6.5 默认yum只能安装MySQL 5.1
安装前要检查机器是否安装过mysql,如果有的话需要先进行数据备份,然后清理

[root@murasakiseifu ~]# yum list installed | grep mysql
[root@murasakiseifu ~]# ps -ef|grep mysql
[root@murasakiseifu ~]# service mysqld stop
[root@murasakiseifu ~]# rpm -e mysql-libs --nodeps
[root@murasakiseifu ~]# yum -y remove mysql mysql-*

1.2 设置安装源

[root@murasakiseifu ~]# wget http://repo.mysql.com/mysql57-community-release-el6-8.noarch.rpm
[root@murasakiseifu ~]# rpm -ivh mysql57-community-release-el6-8.noarch.rpm
[root@murasakiseifu ~]# ls -1 /etc/yum.repos.d/mysql-community*
[root@murasakiseifu ~]# yum repolist all | grep mysql
[root@murasakiseifu ~]# vi /etc/yum.repos.d/mysql-community.repo

将[mysql56-community]的enabled设置为1,[mysql55、57-community]的enabled设置为0 

[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[root@snails ~]# yum repolist enabled | grep mysql
mysql-connectors-community MySQL Connectors Community                         21
mysql-tools-community      MySQL Tools Community                              37
mysql56-community          MySQL 5.6 Community Server                        265

1.3 安装 MySQL

[root@murasakiseifu ~]# yum -y install mysql-server mysql

1.4 修改默认配置

[root@murasakiseifu ~]# mkdir /data/mysql
[root@murasakiseifu ~]# vi /etc/my.cnf

[mysql]
default-character-set=utf8
[mysqld]#canal 配置 无视即可
server-id=1
log_bin=mysql-bin
binlog_format=ROW
character_set_server=utf8

#
# 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
#
# 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
datadir=/usr/local/mysql/data #设置mysql数据库的数据的存放目录
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

1.5 启动服务

[root@murasakiseifu ~]# service mysqld start

可能会遇到的问题:
1.Can't connect to local MySQL server through socket '/tmp/mysql.sock'
提示得很清楚 就是连接的时候要/tmp路径下找一个mysql.sock文件 这里没有找到。
我们可以查找下哪里有这个文件  或者去它的路径下看看有没有这个文件。

[root@murasakiseifu ~]# sudo find / -name "mysql.sock"

我们会发现/var/lib/mysql/mysql.sock下有该文件(此路径跟你安装时的路径有关)  
但是/tmp下没有该文件  (如果/tmp下有该文件的话就是权限问题 用chown -R /tmp 命令即可)
这时我们有两个解决方案:
方案一:
     我们可以去/etc/mysql.cnf中修改配置路径
方案二:
     方案二:
     客户端连接时会默认去找/tmp路径下的mysql.sock。所以,我们这里的第二个方案是:看能不能把
     mysql.sock 复制到 /tmp路径下 
     
     [root@murasakiseifu ~]# cp /var/lib/mysql/mysql.sock   /tmp/mysql.sock
     如若提示:cp: 无法打开 “/var/lib/mysql/mysql.sock” 读取数据: 没有那个设备或地址
     用如下指令:
     [root@murasakiseifu ~]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

1.6 检查

[root@murasakiseifu ~]# netstat -ano |grep 3306
tcp        0      0 :::3306          :::*        LISTEN      off (0.00/0/0)

1.7 修改root密码

[root@murasakiseifu ~]# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("GIVE-NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

参考文献:
https://www.jianshu.com/p/5a2...
http://blog.csdn.net/zzq90050...
https://segmentfault.com/q/10...

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

相关推荐