在CentOS 6.5 安装配置 MySQL 5.6

前端之家收集整理的这篇文章主要介绍了在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...

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

猜你在找的CentOS相关文章