環境:centos7 mysql8.0.18 一、下載mysql服務軟體包 地址:https://dev.mysql.com/downloads/mysql/ rpm package:是某個特定的包,比如server,client,devle等 rpm bundle:是該版本所有包的集合 Compr ...
環境:centos7 mysql8.0.18
一、下載mysql服務軟體包
地址:https://dev.mysql.com/downloads/mysql/
rpm package:是某個特定的包,比如server,client,devle等
rpm bundle:是該版本所有包的集合
Compressed TAR Archive,是源碼,必須用源碼方式安裝
Compatibility Libraries:相容庫
Shared Libraries:共用庫
Development Libraries:開發庫
Test Suite:測試套件
Client Utilities:客戶端工具
下載時註意選則好對應的版本
二、安裝
(1)rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64
報錯信息:
error: Failed dependencies:
mariadb-libs is obsoleted by mysql-community-libs-8.0.18-1.el7.x86_64
原因:mariadb-libs和 mysql-community-libs衝突
解決辦法:卸載mariadb-libs
a.查詢mariadb-libs的包名
[root@izm5e8nyz28va3a786y465z src]# rpm -qa |grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
b.卸載該包
[root@izm5e8nyz28va3a786y465z src]# rpm -ev mariadb-libs-5.5.64-1.el7.x86_64
error: Failed dependencies:
libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
報錯原因:postfix是mariadb 的依賴包,要先卸載它
[root@izm5e8nyz28va3a786y465z src]# rpm -qa |grep postfix
postfix-2.10.1-7.el7.x86_64
[root@izm5e8nyz28va3a786y465z src]# rpm -ev postfix-2.10.1-7.el7.x86_64
error: Failed dependencies:
/usr/sbin/sendmail is needed by (installed) redhat-lsb-core-4.1-27.el7.centos.1.x86_64
[root@izm5e8nyz28va3a786y465z src]# rpm -qa |grep redhat-lsb
redhat-lsb-core-4.1-27.el7.centos.1.x86_64
redhat-lsb-submod-security-4.1-27.el7.centos.1.x86_64
[root@izm5e8nyz28va3a786y465z src]# rpm -ev redhat-lsb-core-4.1-27.el7.centos.1.x86_64
Preparing packages...
redhat-lsb-core-4.1-27.el7.centos.1.x86_64
[root@izm5e8nyz28va3a786y465z src]# rpm -ev postfix-2.10.1-7.el7.x86_64
Preparing packages...
postfix-2:2.10.1-7.el7.x86_64
上述步驟成功卸載掉mariadb-libs的依賴
[root@izm5e8nyz28va3a786y465z src]# rpm -ev mariadb-libs-5.5.64-1.el7.x86_64
Preparing packages...
mariadb-libs-1:5.5.64-1.el7.x86_64
繼續安裝:
[root@izm5e8nyz28va3a786y465z src]# rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-8.0.18-1.el7################################# [100%]
mysql-community-libs-8.0.18-1.el7包安裝成功
(2) rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm
(3) rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm
(4) rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64
解決依賴關係:
[root@izm5e8nyz28va3a786y465z src]# yum list |grep libaio
libaio.i686 0.3.109-13.el7 base
libaio.x86_64 0.3.109-13.el7 base
libaio-devel.i686 0.3.109-13.el7 base
libaio-devel.x86_64 0.3.109-13.el7 base
查詢到4個相關的依賴包,只需安裝libaio.x86_64 libaio-devel.x86_64
yum -y install libaio.x86_64 libaio-devel.x86_64
[root@izm5e8nyz28va3a786y465z src]# rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-8.0.18-1.e################################# [100%]
(5)rpm -ivh mysql-community-devel-8.0.18-1.el7.x86_64.rpm
error: Failed dependencies:
pkgconfig(openssl) is needed by mysql-community-devel-8.0.18-1.el7.x86_64
解決依賴關係:
yum -y install openssl openssl-devel
[root@izm5e8nyz28va3a786y465z src]# rpm -ivh mysql-community-devel-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-devel-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-devel-8.0.18-1.el################################# [100%]
至此Mysql安裝成功
小結:1. 卸載掉衝突組件 mariadb
rpm -ev redhat-lsb-core-4.1-27.el7.centos.1.x86_64 postfix-2.10.1-7.el7.x86_64 mariadb-libs-5.5.64-1.el7.x86_64
2.安裝相關依賴:
yum -y install openssl openssl-devel libaio libaio-devel
三、mysql服務設置
1.啟動mysql服務:systemctl start mysqld.service
查看MySQL服務是否啟動:netstat -tunpl |grep mysqld
2.登錄MySQL修改密碼
(1)登錄mysql
2種方法:跳過密碼驗證登錄 或 查看初始密碼登錄
a.查看初始密碼登錄
cat /var/log/mysqld.log
... 2019-11-11T14:28:57.523108Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ,2sg6>HrQdF!
標紅加粗部分為初始密碼 mysql -uroot -p 鍵入密碼可以登錄MySQL
b.跳過密碼驗證登錄
修改my.cnf文件,在[mysqld]區域下加入skip-grant-tables 重啟MySQL
[root@izm5e8nyz28va3a786y465z ~]# find / -name my.cnf
/etc/my.cnf
[root@izm5e8nyz28va3a786y465z ~]# vim /etc/my.cnf
[root@izm5e8nyz28va3a786y465z run]# systemctl restart mysqld.service
[root@izm5e8nyz28va3a786y465z run]# mysql #可直接登錄MySQL
註意:修改密碼後,將my.cnf文件內容還原
(2)修改密碼,2sg6>HrQdF!sf
mysql> alter user 'root'@'localhost' identified by 'root123';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
原因:密碼設置的太過簡單,初始密碼方針:必須包含數字、大寫字母、小寫字母、特殊符號、長度8位以上。
mysql> flush privileges;
3.設置字元編碼(從MySQL8.0開始,預設字元集就是utf8mb4 了)
[client]
default-character-set = utf8mb4 #客戶端字元編碼
[mysqld]
character-set-server = utf8mb4 #服務端字元編碼
查看預設字元集:
show global variables like '%character_set%';
查看支持的字元集:
show character set;
4.設置遠程登錄用戶和密碼
1.設置已有用戶遠程登錄
update user set Host='%' where User='root';
flush privileges;
2.新建遠程登錄用戶
mysql> create user 'xiaobai' identified by 'Abc1234!';
mysql> grant all privileges on *.* to 'xiaobai'@'%' with grant option;
mysql>flush privileges;
連接失敗,提示 驗證插件'caching_sha2_password'不能loade
原因:新版本的MySQL使用的是caching_sha2_password驗證方式,但此時的navicat還沒有支持這種驗證方式
解決辦法:更改加密方式
查看用戶加密方式:
mysql> select user,plugin from user where user='root';
+------+-----------------------+
| user | plugin |
+------+-----------------------+
| root | caching_sha2_password |
+------+-----------------------+
更改加密方式:
mysql> alter user 'root'@'%' identified by ',2sg6>HrQdF!sf' password expire never; #設置密碼永不過期
mysql> ALTER USER 'root'@'%' identified with mysql_native_password BY ',2sg6>HrQdF!sf'; #設置為老的加密方式
mysql> select user,plugin from user where user='root'; #加密方式已修改成功
+------+-----------------------+
| user | plugin |
+------+-----------------------+
| root | mysql_native_password |
+------+-----------------------+
刷新許可權:flush privileges #可連接成功