Centos 6 安裝mysql5.7

Step1: 檢測系統(tǒng)是否自帶安裝mysql

yum list installed | grep mysql

Step2: 刪除系統(tǒng)自帶的mysql及其依賴

yum -y remove mysql-libs.x86_64

Step3: 給CentOS添加rpm源,并且選擇較新的源
CeontOS6只能用el6的。

3.1配置YUM源

在MySQL官網(wǎng)中下載YUM源rpm安裝包:

3.2下載mysql源安裝包

http://dev.mysql.com/downloads/repo/yum/

wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm

3.3安裝mysql源

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

3.4查看啟用情況

yum repolist all | grep mysql

3.5設(shè)置啟用mysql57

檢查mysql源是否安裝成功

yum repolist enabled | grep "mysql.-community."

CentOS6.9安裝mysql5.7.21教程

看到上圖所示表示安裝成功。

3.6修改啟用mysql57

可以修改vim /etc/yum.repos.d/mysql-community.repo源,改變默認(rèn)安裝的mysql版本。比如要安裝5.6版本,將5.7源的enabled=1改成enabled=0。然后再將5.6源的enabled=0改成enabled=1即可。改完之后的效果如下:


CentOS6.9安裝mysql5.7.21教程

3.7查看mysql啟用情況

yum repolist enabled | grep mysql

CentOS6.9安裝mysql5.7.21教程

Step4:安裝mysql 服務(wù)器命令:

yum install mysql-community-server

順利的話。。。
不順利的話會缺少依賴:
解決辦法:

修改vim /etc/yum.repos.d/mysql-community.repo 源文件

[mysql57-community]

name=MySQL 5.7 Community Server

# baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

7.yum install mysql-community-server #再次安裝mysql

Step5:啟動MySQL服務(wù)

service mysqld start

[ok]

Step6:查看root 臨時密碼

grep 'temporary password' /var/log/mysqld.log

2018-01-07T01:25:58.867073Z 1 [Note] A temporary password is generated for root@localhost: umDn1uy4q>B;

其中的;也是密碼的一部份。

Step7:修改root密碼

mysql -uroot -p

mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass2!';

如果您只是寫一個簡單的如,123456,則會報錯。
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

SHOW VARIABLES LIKE 'validate_password%';

這個其實與validate_password_policy的值有關(guān)。
validate_password_policy有以下取值:

默認(rèn)是1,即MEDIUM,所以剛開始設(shè)置的密碼必須符合長度,且必須含有數(shù)字,小寫或大寫字母,特殊字符。
有時候,只是為了自己測試,不想密碼設(shè)置得那么復(fù)雜,譬如說,我只想設(shè)置root的密碼為123456。
必須修改兩個全局參數(shù):
首先,修改validate_password_policy參數(shù)的值
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

這樣,判斷密碼的標(biāo)準(zhǔn)就基于密碼的長度了。這個由validate_password_length參數(shù)來決定。(默認(rèn)需要長度8)

mysql> set global validate_password_length=4;

Step8:開放遠(yuǎn)程登錄權(quán)限

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';
FLUSH PRIVILEGES;

Step9:關(guān)閉防火墻

(1) 用root用戶登錄后,執(zhí)行查看防火墻狀態(tài)。

[root@bigdata-senior01 hadoop]# service iptables status

(2) 用[root@bigdata-senior01 hadoop]# service iptables stop關(guān)閉防火墻,這個是臨時關(guān)閉防火墻。

[root@bigdata-senior01 hadoop-2.5.0]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]

(3) 如果要永久關(guān)閉防火墻用。

[root@bigdata-senior01 hadoop]# chkconfig iptables off

關(guān)閉,這種需要重啟才能生效。


若mysql開啟失敗
報 Fatal error: mysql.user table is damaged. Please run mysql_upgrade.
或 InnoDB: Plugin initialization aborted with error Generic error。
刪除 /var/lib/mysql下的所有文件再重啟。

tips:在高并發(fā)情況下,
Caused by:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections",這是由于請求的連接太多導(dǎo)致,在/etc/my.cnf文件里加
max_connections=1000 為設(shè)置最大的連接數(shù)
max_user_connections=500 設(shè)置每用戶最大的 連接數(shù)500
wait_timeout=200 表示200秒后將關(guān)閉空閑連接,但對正在工作的連接不受影響。

5.7版本group by后的列必須出現(xiàn)在select里,可以再my.cnf里添加
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
(只要sql_mode里沒有only_full_group_by這一項就可以)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容