系統:CentOS 7.8(2003)版本最小化安裝
MySQL:8.0.21
下載地址:https://dev.mysql.com/downloads/mysql/
注意,頁面上沒有CentOS的選項,選擇RedHat 7相關的系統就行,他們之間的關系不可描述,囧。
先下載了RPM Server包,以為能夠一直安裝過
cd /usr/lcoal/src
wget https://..........mysql-community-server-8.0.21-1.el7.x86_64.rpm #直接去頁面上找地址
rpm -ivh mysql-community-server-8.0.21-1.el7.x86_64.rpm
結果發現缺少依賴包,囧。
警告:mysql-community-server-8.0.21-1.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY
錯誤:依賴檢測失敗:
mysql-community-client(x86-64) >= 8.0.11 被 mysql-community-server-8.0.21-1.el7.x86_64 需要
mysql-community-common(x86-64) = 8.0.21-1.el7 被 mysql-community-server-8.0.21-1.el7.x86_64 需要
net-tools 被 mysql-community-server-8.0.21-1.el7.x86_64 需要
於是干脆下了mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar包。
gwet https://......../ mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar #自己去頁面上找地址
tar -xvf mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar
yum -y install net-tools mariadb-libs
rpm -ivh mysql-community-common-8.0.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.21-1.el7.x86_64.rpm
順序不能錯,有依賴關系。
啟動服務:
systemctl start mysqld.service
systemctl enable mysqld.service
查看MySQL初始密碼,每次安裝都會不一樣,注意使用自己機器上的:
grep 'password' /var/log/mysqld.log
2020-07-16T03:01:40.135985Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: _hN6j8t_pWaO
用初始密碼進入MySQL
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
成功進入,修改密碼:
mysql> alter user 'root'@'%' idenfified by 'wenfei@fly'; #報錯,初始root用戶在localhost下面,沒有root@%用戶。
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'idenfified by 'wenfei@fly'' at line 1
mysql> alter user 'root'@'localhost' identified by 'WenFei@123'; #先修改一次root@localhost用戶,默認在本機登錄
Query OK, 0 rows affected (0.01 sec)
user mysql;
create user 'root'@'%' identified by 'WenFei@123'; #創建root@%用戶,方便其它IP登錄訪問數據庫
#update user set host ='%' where user=‘root'; #也可以直接替換root@localhost為root@%用戶
MySQL 8.0版本開始,密碼默認使用的插件是caching_sha2_password,規則是大寫、小寫、字符、數字、至少8位,這些條件必須滿足。如果要使用以前的mysql_native_password
ALTER USER `root`@`%` IDENTIFIED WITH mysql_native_password BY '123';
給root@%用戶授權最大權限
grant all on *.* to root@'%';
好了,這時候可以用Navicat之類的工具連接了,如果不能連接請檢查防火牆設置。