1. 程式人生 > >CentOS6.5安裝MySQL5.7詳細教程(本人6.3也行)

CentOS6.5安裝MySQL5.7詳細教程(本人6.3也行)

過程 centos 6 yum安裝 -1 兩個文件 bin gre 開機 bsp

本文參考http://www.cnblogs.com/lzj0218/p/5724446.html

主要參考博文:

https://segmentfault.com/a/1190000003049498

http://www.th7.cn/db/mysql/201601/175073.shtml

1.檢測系統是否已經安裝過mysql或其依賴,若已裝過要先將其刪除,否則第4步使用yum安裝時會報錯:

1 # yum list installed | grep mysql
2 mysql-libs.i686         5.1.71-1.el6      @anaconda-CentOS-201311271240.i386/6.5
3 # yum -y remove mysql-libs.i686

2.從mysql的官網下載mysql57-community-release-el6-5.noarch.rpm(註意這裏的el6-5即適配RHEL6.5的版本,如果下載了其它版本後面的安裝過程中可能會報錯):

wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm    (本文備份https://files.cnblogs.com/files/weiyiyong/mysql-community-release-el6-5.noarch.rar)

3.安裝第一步下載的rpm文件:

 yum install mysql-community-release-el6-5.noarch.rpm

安裝成功後,我們可以看到/etc/yum.repos.d/目錄下增加了以下兩個文件

1 # ls /etc/yum.repos.d
2 mysql-community-source.repo
3 mysql-community.repo

查看mysql57的安裝源是否可用,如不可用請自行修改配置文件(/etc/yum.repos.d/mysql-community.repo)使mysql57下面的enable=1

若有mysql其它版本的安裝源可用,也請自行修改配置文件使其enable=0

1 # yum repolist enabled | grep mysql
2 mysql-connectors-community MySQL Connectors Community                        13
3 mysql-tools-community      MySQL Tools Community                             18
4 mysql57-community-dmr      MySQL 5.7 Community Server Development Milesto    65

4.使用yum安裝mysql:

yum install mysql-community-server

5.啟動mysql服務:

service mysqld start

查看root密碼:

1 # grep "password" /var/log/mysqld.log
2 2016-08-10T15:03:02.210317Z 1 [Note] A temporary password is generated for [email protected]: AYB(&-3Cz-rW

現在必須立刻修改密碼,不然會報錯:(http://www.cnblogs.com/weiyiyong/p/7636333.html)

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

修改密碼(如果在此步報錯ERROR 1819,請向下翻查看原因及解決方法):

mysql> SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘newpass‘);

6.查看mysqld是否開機自啟動,並設置為開機自啟動:

1 chkconfig --list | grep mysqld
2 chkconfig mysqld on

7.修改字符集為UTF-8:

vim /etc/my.cnf

在[mysqld]部分添加:

character-set-server=utf8

在文件末尾新增[client]段,並在[client]段添加:

default-character-set=utf8

修改好之後重啟mysqld服務:

service mysqld restart

查看修改結果:

技術分享
mysql> show variables like "%character%";(出現需要密碼時重新重置密碼,坑逼   使用SET PASSWORD = PASSWORD(‘yong123456‘);)
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
技術分享

註:在修改密碼步驟,若設置的密碼為簡單密碼,可能會出現如下錯誤:

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

這一錯誤其實與validate_password_policy值的設置有關:

技術分享

validate_password_policy值默認為1,即MEDIUM,所以剛開始設置的密碼必須符合長度要求,且必須含有數字,小寫或大寫字母,特殊字符

如果我們只是做為測試用而不需要如此復雜的密碼,可使用如下方式修改validate_password_policy值

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

這樣,對密碼要求就只有長度了,而密碼的最小長度由validate_password_length值決定

validate_password_length參數默認為8,它有最小值的限制,最小值為:

validate_password_number_count+ validate_password_special_char_count+ (2 * validate_password_mixed_case_count)

其中,validate_password_number_count指定了密碼中數字的長度,validate_password_special_char_count指定了密碼中特殊字符的長度,validate_password_mixed_case_count指定了密碼中大小字母的長度。這些參數的默認值均為1,所以validate_password_length最小值為4,如果顯性指定validate_password_length的值小於4,盡管不會報錯,但validate_password_length的值將設為4

設置validate_password_length的值:

mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)

如果修改了validate_password_number_count,validate_password_special_char_count,validate_password_mixed_case_count中任何一個值,則validate_password_length將進行動態修改。

CentOS6.5安裝MySQL5.7詳細教程(本人6.3也行)