安装 MySQL 官方 YUM 仓库:
bash
[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
--2024-12-02 16:14:09-- https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 23.52.218.134, 2600:1417:4400:89a::2e31, 2600:1417:4400:8ac::2e31
Connecting to dev.mysql.com (dev.mysql.com)|23.52.218.134|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm [following]
--2024-12-02 16:14:10-- https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 2.19.153.220, 2600:1417:4400:e8c::1d68, 2600:1417:4400:e84::1d68
Connecting to repo.mysql.com (repo.mysql.com)|2.19.153.220|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 26024 (25K) [application/x-redhat-package-manager]
Saving to: 'mysql80-community-release-el7-3.noarch.rpm'
mysql80-community-rel 100%[=========================>] 25.41K 125KB/s in 0.2s
2024-12-02 16:14:11 (125 KB/s) - 'mysql80-community-release-el7-3.noarch.rpm' saved [26024/26024]
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ll
total 32
-rw-------. 1 root root 789 Dec 2 2024 anaconda-ks.cfg
-rw-r--r--. 1 root root 26024 Apr 25 2019 mysql80-community-release-el7-3.noarch.rpm
[root@localhost ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
安装MySQL服务
bash
[root@localhost ~]# sudo yum install mysql-server
启动 MySQL 服务:
bash
[root@localhost ~]# sudo systemctl start mysqld
[root@localhost ~]# sudo systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: d>
Active: active (running) since Mon 2024-12-02 16:16:40 CST; 9s ago
Process: 2507 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/S>
Process: 2530 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=e>
Main PID: 2605 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 21409)
Memory: 461.6M
CGroup: /system.slice/mysqld.service
└─ 2605 /usr/libexec/mysqld --basedir=/usr
Dec 02 16:16:24 localhost.localdomain systemd[1]: Starting MySQL 8.0 database server...
Dec 02 16:16:25 localhost.localdomain mysql-prepare-db-dir[2530]: Initializing MySQL da>
Dec 02 16:16:40 localhost.localdomain systemd[1]: Started MySQL 8.0 database server.
查看MySQL初始密码
bash
[root@localhost ~]# sudo grep 'temporary password' /var/log/mysqld.log
通常初次安装点回车就会进入MySQL
bash
[root@localhost ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost ~]# sudo grep 'temporary password' /var/log/mysqld.log
grep: /var/log/mysqld.log: No such file or directory
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.40 Source distribution
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
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>
修改秘密
bash
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Wyxbuke00.';
Query OK, 0 rows affected (0.01 sec)