【mysql】MySQL安装-centos7

1 下载 rpm 源

mysql 所有版本 与 KEY 源:https://repo.mysql.com

1
wget https://repo.mysql.com/mysql-community-release-el7.rpm

2 添加 yum 仓库

1
yum install mysql-community-release-el7.rpm

添加后 /etc/yum.repos.d/ 目录下会存在 mysql-community.repo 仓库

3 下载密钥

1
wget https://repo.mysql.com/RPM-GPG-KEY-mysql-2023

4 替换密钥

查看 mysql-community.repo 中所要安装的包密钥存放位置 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

在 /etc/pki/rpm-gpg/ 目录下将下载的 RPM-GPG-KEY-mysql-2023 密钥更名为 RPM-GPG-KEY-mysql 或 修改 mysql-community.repo 文件中 gpgkey 所指定的文件

5 安装

1
yum install mysql-community-server

6 启动

1
systemctl start mysqld

7 查看临时密码

1
cat /var/log/mysqld.log

找到这行:
[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hz8swEv%h+DN
hz8swEv%h+DN 为临时密码

8 修改临时密码

在 MySQL 8 中,默认的密码策略要求密码必须包含:小写字母、大写字母、数字和特殊字符,并且长度不能少于 8 个字符。

1
mysqladmin -u root -p password

9 登录

1
mysql -u root -p

输入密码登录

10 问题

启动权限报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 一 2024-04-01 10:17:17 CST; 2min 23s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 2074 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
Process: 2051 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 2074 (code=exited, status=1/FAILURE)
Status: "Server shutdown complete"
Error: 13 (权限不够)

4月 01 10:17:17 localhost.localdomain systemd[1]: Starting MySQL Server...
4月 01 10:17:17 localhost.localdomain systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
4月 01 10:17:17 localhost.localdomain systemd[1]: Failed to start MySQL Server.
4月 01 10:17:17 localhost.localdomain systemd[1]: Unit mysqld.service entered failed state.
4月 01 10:17:17 localhost.localdomain systemd[1]: mysqld.service failed.

解决:

1
2
sudo chown -R mysql:mysql /var/lib/mysql/
sudo chmod -R 750 /var/lib/mysql/

参考:

centos6 编译安装 mysql5.6 参考:

https://blog.csdn.net/weixin_33729196/article/details/91750709