CentOS7下安裝mysql8

mengjie0617發表於2020-12-04

1.CentOS7下安裝mysql8

CentOS7(連結:https://pan.baidu.com/s/1ufvFykiS0DPv-uvFgLDlYQ 提取碼:oa91 )

MySQL(連結:https://pan.baidu.com/s/11P_P-9Kqmg5VHRJrjG5auw 提取碼:7w49)

1.1下載mysql安裝包

https://dev.mysql.com/downloads/mysql/

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片儲存下來直接上傳(img-WLuGKgP6-1607067334708)(./assets/Mysql/mysql.png)]

1.2安裝mysql

1). 解除安裝 centos 中預安裝的 mysql
	rpm -qa | grep -i mysql
	rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps(這步還沒操作不知對錯)
	
2). 上傳 mysql 的安裝包
	alt + p -------> put D:/mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar
	
3). 解壓 mysql 的安裝包
	cd root (上傳的壓縮包在root目錄下)
	mkdir mysql
	tar -xvf mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar -C /root/mysql
	cd mysql(進入mysql包,為下一步安裝做準備)
	
4). 安裝依賴包
	a.安裝mysql-community-client-plugins包
		rpm -ivh mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm
	b.解除安裝CentOS7自帶的mariadb-libs資料庫
		rpm -qa | grep mariadb
		rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
				(版本根據上一步查出來的,--nodeps強制解除安裝)
	c.安裝mysql-community-common包
		rpm -ivf mysql-community-common-8.0.22-1.el7.x86_64.rpm
	d.安裝mysql-community-libs包
		rpm -ivf mysql-community-libs-8.0.22-1.el7.x86_64.rpm
		
5). 安裝 mysql-client
	rpm -ivh mysql-community-client-8.0.22-1.el7.x86_64.rpm
	
6). 安裝 mysql-server
	rpm -ivh mysql-community-server-8.0.22-1.el7.x86_64.rpm

1.3 啟動mysql

systemctl start mysqld.service
systemctl status mysqld.service

1.4 登陸mysql

1).首次登陸檢視臨時密碼
	grep "password" /var/log/mysqld.log 
	mysql -uroot -p臨時密碼
2)重新設定密碼
	mysql為了安全性,預設validate_password.policy=1,即設定的密碼必須長度要大於8位數,並且必須包含有數	字,小寫或大寫字母,特殊字元。
	ALTER USER 'root'@'localhost' IDENTIFIED BY '123qweasdZXC.'
3)退出後重新登陸
	quit
	mysql -uroot -p密碼

擴充:可修改密碼規則,具體引數如下

SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |密碼長度>=8
| validate_password.mixed_case_count   | 1      |密碼中特殊字元的長度
| validate_password.number_count       | 1      |密碼中數字的長度
| validate_password.policy             | MEDIUM |0:LOW;1:MEDIUM(預設);2:STRONG
| validate_password.special_char_count | 1      |密碼中特殊字元的長度
+--------------------------------------+--------+

如:
	set validate_password.policy=0
	ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678'

1.5 其他問題

1).缺少依賴/usr/bin/perl

安裝server時報錯(參考https://blog.csdn.net/zy_1995/article/details/102588103)

​ (其他CentOS上遇到,暫未解決)


[root@localhost mysql]# rpm -ivh mysql-community-server-8.0.22-1.el7.x86_64.rpm
警告:mysql-community-server-8.0.22-1.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 金鑰 ID 5072e1f5: NOKEY
錯誤:依賴檢測失敗:
        /usr/bin/perl 被 mysql-community-server-8.0.22-1.el7.x86_64 需要
        perl(Getopt::Long) 被 mysql-community-server-8.0.22-1.el7.x86_64 需要
        perl(strict) 被 mysql-community-server-8.0.22-1.el7.x86_64 需要

2)缺少依賴libaio.so

在阿里雲ECS伺服器上安裝mysql-server時報錯

error: Failed dependencies:
        libaio.so.1()(64bit) is needed by mysql-community-server-8.0.22-1.el7.x86_64
        libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.22-1.el7.x86_64
        libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.22-1.el7.x86_64

解決方案

安裝伺服器前先安裝依賴libaio.so,然後再執行之前的6).安裝 mysql-server下的安裝命令

安裝命令:yum install libaio

3)MySQL隨機生成的臨時密碼中有特殊字元

最近一次安裝時,隨機臨時密碼中有特殊字元“;”等,直接用mysql -uroot -p臨時密碼登陸時就會報錯無法登陸

A temporary password is generated for root@localhost: i/;T7fwo?.k;
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
-bash: T7fwo?.k: command not found

解決方案

1、直接將密碼用單引號引起來。 
2、在特殊字元&前面加上'\'來進行登入。
我這次直接加單引號登陸成功:mysql -uroot -p'i/;T7fwo?.k;'

相關文章