在CentOS 6.5 安裝配置 MySQL 5.6

1.1 在CentOS 6.5 安裝配置 Mysql5.6node

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 設置安裝源mysql

[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,[mysql5五、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 安裝 MySQLsql

[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 啓動服務segmentfault

[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 檢查socket

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

1.7 修改root密碼tcp

[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...ui

著做權歸做者全部。商業轉載請聯繫做者得到受權,非商業轉載請註明出處。url

相關文章
相關標籤/搜索