1. 程式人生 > 實用技巧 >Centos8上yum安裝mysql8

Centos8上yum安裝mysql8

安裝Yum Repository

[root@liujunjun ~]# wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
--2020-12-08 08:06:16--  https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
正在解析主機 repo.mysql.com (repo.mysql.com)... 23.215.59.160
正在連線 repo.mysql.com (repo.mysql.com)|23.215.59.160|:443... 已連線。
已發出 HTTP 請求,正在等待迴應... 
200 OK 長度:30388 (30K) [application/x-redhat-package-manager] 正在儲存至: “mysql80-community-release-el8-1.noarch.rpm” mysql80-community-release-el8-1.noarch.rp 100%[====================================================================================>] 29.68K 166KB/s 用時 0.2s 2020-12-08 08:06:17 (166 KB/s) - 已儲存 “mysql80-community-release-el8-1
.noarch.rpm” [30388/30388])

使用rpm來安裝MySQL

[root@liujunjun ~]# rpm -ivh mysql80-community-release-el8-1.noarch.rpm
警告:mysql80-community-release-el8-1.noarch.rpm: 頭V3 DSA/SHA1 Signature, 金鑰 ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
準備中...                          ################################# [
100%] 正在升級/安裝... 1:mysql80-community-release-el8-1 ################################# [100%]

使用yum安裝mysql服務

[root@liujunjun ~]# yum install mysql-server

啟動服務

[root@liujunjun ~]# systemctl start mysqld
[root@liujunjun ~]# systemctl enable mysqld.service
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@liujunjun ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21 Source distribution

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> 

修改root密碼

在MySQL 8.04前,執行:SET PASSWORD=PASSWORD(‘[新密碼]’);但是MySQL8.0.4開始,這樣預設是不行的。因為之前,MySQL的密碼認證外掛是“mysql_native_password”,而現在使用的是“caching_sha2_password”。

修改密碼為123456(密碼可以設定為任意值):

mysql> user mysql;
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 'user mysql' at line 1
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> 
[root@liujunjun ~]# 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 Source distribution

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>