Linux(CentOS 7) yum一键安装mysql8

1、通过yum安装

(1)下载mysql

在Linux找个地方输入以下命令

复制代码
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

(2)安装mysql yum 仓库配置文件

复制代码
[root@VM-8-15-centos ~]# sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm

(3)先清理缓存(可能以前被操作过)

复制代码
[root@VM-8-15-centos ~]#  sudo yum clean all

(4)生成缓存

复制代码
[root@VM-8-15-centos ~]# sudo yum makecache

(5)安装Mysql

复制代码
[root@VM-8-15-centos ~]# sudo yum install mysql-community-server 

如果报异常:

The GPG keys listed for the "MySQL 8.0 Community Server" repository are already installed but they are not correct for this package.

Check that the correct key URLs are configured for this repository.

Failing package is: mysql-community-client-plugins-8.0.40-1.el7.x86_64

GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

那么就重新来过一次,添加 --nogpgcheck

复制代码
[root@VM-8-15-centos ~]#sudo yum install mysql-community-server --nogpgcheck

(6)启动Mysql服务

复制代码
[root@VM-8-15-centos ~]# sudo systemctl start mysqld

(7)设置开机启动

复制代码
[root@VM-8-15-centos ~]# sudo systemctl enable mysqld

(8)查看Mysql 服务状态

复制代码
[root@VM-8-15-centos ~]# sudo systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2024-11-12 17:49:35 CST; 1min 13s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 29395 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─29395 /usr/sbin/mysqld

Nov 12 17:49:27 VM-8-15-centos systemd[1]: Starting MySQL Server...
Nov 12 17:49:35 VM-8-15-centos systemd[1]: Started MySQL Server.

2、登录Mysql

(1)查找临时登录密码

复制代码
[root@VM-8-15-centos log]# sudo grep 'temporary password' /var/log/mysqld.log
2024-11-12T09:49:30.521947Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: g.<we6/h<W7f

(2)输入密码并且修改密码(密码规则是4种类型字符)

登录命令: mysql -u root -p

修改密码:set password for root@localhost='Admin123!';

复制代码
[root@VM-8-15-centos log]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.40

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> set password for root@localhost='Admin123!';
Query OK, 0 rows affected (0.01 sec)

3、修改远程链接并且生效

(1)选中mysql数据库

sql 复制代码
mysql> use mysql;

(2)设置允许远程连接并生效

sql 复制代码
mysql> update user set host='%' where user='root'; 
mysql> flush privileges;

root表示想要被连接的数据库的用户名

其中"%"表示允许所有机器能访问root用户

(3)开放防火墙3306端口

mysql已经可以本地连接上了,但要用图形化界面远程连接,需开放防火墙的3306端口才行

--permanent代表永久生效,否则重启linux后则需要再次开启

sql 复制代码
 [root@localhost mysql-8.0]# firewall-cmd --add-port=3306/tcp --permanent
 
 [root@localhost mysql-8.0]# firewall-cmd --reload

查看防火墙端口开放状态

sql 复制代码
[root@localhost mysql-8.0]# firewall-cmd --list-all

自此在linux系统上安装mysql8已经完成,并且可以使用图形化界面远程连接

  1. 可视化界面链接mysql

我这里是使用Navicat for MySQL

获取数据库IP:

sql 复制代码
[root@localhost mysql-8.0]# ifconfig

inet 192.200.xx.xx 就是你服务器的地址

输入链接IP、账号root、密码123456,端口号 3306,显示"连接成功"代表流程通了

相关推荐
曹瑞曹瑞9 分钟前
VMware导入vmdk文件
linux·运维·服务器
Johny_Zhao13 分钟前
2025年6月Docker镜像加速失效终极解决方案
linux·网络·网络安全·docker·信息安全·kubernetes·云计算·containerd·yum源·系统运维
寒山李白13 分钟前
MySQL复杂SQL(多表联查/子查询)详细讲解
sql·mysql·子查询·多表联查
冰橙子id23 分钟前
centos7编译安装LNMP架构
mysql·nginx·架构·centos·php
玛奇玛丶38 分钟前
面试官:千万级订单表新增字段怎么弄?
后端·mysql
hello kitty w39 分钟前
Python学习(7) ----- Python起源
linux·python·学习
十年磨一剑~1 小时前
centos查看开启关闭防火墙状态
linux·运维·centos
行云流水剑1 小时前
【学习记录】在 Ubuntu 中将新硬盘挂载到 /home 目录的完整指南
服务器·学习·ubuntu
天天摸鱼的java工程师2 小时前
从被测试小姐姐追着怼到运维小哥点赞:我在项目管理系统的 MySQL 优化实战
java·后端·mysql
搬码临时工2 小时前
如何把本地服务器变成公网服务器?内网ip网址转换到外网连接访问
运维·服务器·网络·tcp/ip·智能路由器·远程工作·访问公司内网