在 centos 上安装配置 MySQL8.0 教程
在 centos7 上安装配置 MySQL8.0 教程
在 Centos 环境上的安装配置
安装环境为:在 win11系统 -> virtualbox 虚拟机 -> centos7.9 系统 -> MySQL8.0
测试时间为:2023 年 05 月
安装
- 确定所要下载的版本:
$ uname -m # 输出 x86_64
$ cat /etc/redhat-release # 输出 CentOS Linux release 7.9.2009 (Core)
- 下载对应版本的 rpm 文件资源 Download MySQL Yum Repository :
对应文件为:Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent)
点击:浏览器 ->下载 -> 右键复制文件下载链接,安装 yum 资源:
下载链接为:https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm
$ rpm -ivh https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm
- 查看 MySQL 当前版本:
$ yum info mysql-community-server # 8.0.33
- 安装 MySQL:
$ yum -y install mysql-community-server
安装完成!
配置
- 启动 MySQL 服务:
$ systemctl start mysqld.service
- 查看 MySQL 运行状态:
$ systemctl status mysqld.service
- 获取 root 用户的密码:
$ grep "password" /var/log/mysqld.log
2023-05-10T01:41:41.632792Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: _ih4M9ogiXt%
# 其中最后的 _ih4M9ogiXt% 就是密码
- 进入数据库:
$ mysql -u root -p # 初始密码为之前获取的 _ih4M9ogiXt%
- 修改新的密码:
# 密码设置必须要大小写字母数字和特殊符号
$ ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
- 重新进入数据库:
$ mysql -u root -p # 使用修改过后的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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.
配置完成!
连接
所使用的数据库管理软件为 Datagrip,亲测十分好用。
- 打开软件,调出配置界面:

- 先配置 SSH 连接:


- 再进行常规连接:

- 调出所有数据库,创建会话:


连接完成!