当前位置: 首页 > news >正文

在CentOS上用yum方式安装MySQL8过程记录

此文参考官方文档一步一步记录安装到正常运行全过程

安装环境:centos7
mysql版本:8.0.35

安装过程主要参考下面两边文章:
1.官方文档
https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html
2.linux yum安装mysql8

安装过程大概有以下几步:
1.查找mysql源链接
2.安装mysql源(仓库)
3.安装mysql服务
4.启动mysql服务
5.获取并修改密码
6.防火墙放行、远程登录和设置

因为我的这个centos之前用宝塔装过mysql5.6版本,所以走了一点弯路,过程也记录下来了。如果也是同样情况,建议一开始就卸载旧版本再安装8.0版本。

另外,我避开下面的坑,又重新记录了在一台centosh上mysql8.0过程,可以参考下面我写的另外一篇文章:
《在CentOS上用yum方式安装MySQL8真实全过程记录(顺利版本)》

一、查找mysql源链接

(MySQL Yum Repository,找MySQL官方yum仓库地址并下载)
根据官方文档提示,进入到mysql yum仓库的下载页面(如下图)
https://dev.mysql.com/downloads/repo/yum/

在这里插入图片描述
因为我的CentOS版本是7,所以选择对应的版本,点击download进入下载页面(如下图)
在这里插入图片描述
提示注册,不需要注册,我们直接复制下面的下载地址即可。
复制到的地址为:
https://repo.mysql.com//mysql80-community-release-el7-11.noarch.rpm

二、安装mysql源(仓库)

[root@szaliyun ~]# yum localinstall https://repo.mysql.com//mysql80-community-release-el7-11.noarch.rpm
已加载插件:fastestmirror
mysql80-community-release-el7-11.noarch.rpm                                                                                                                             |  14 kB  00:00:00     
正在检查 /var/tmp/yum-root-hMU7pD/mysql80-community-release-el7-11.noarch.rpm: mysql80-community-release-el7-11.noarch
/var/tmp/yum-root-hMU7pD/mysql80-community-release-el7-11.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql80-community-release.noarch.0.el7-11 将被 安装
--> 解决依赖关系完成依赖关系解决===============================================================================================================================================================================================Package                                            架构                            版本                               源                                                                 大小
===============================================================================================================================================================================================
正在安装:mysql80-community-release                          noarch                          el7-11                             /mysql80-community-release-el7-11.noarch                           17 k事务概要
===============================================================================================================================================================================================
安装  1 软件包总计:17 k
安装大小:17 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装    : mysql80-community-release-el7-11.noarch                                                                                                                                    1/1 验证中      : mysql80-community-release-el7-11.noarch                                                                                                                                    1/1 已安装:mysql80-community-release.noarch 0:el7-11                                                                                                                                                    完毕!

过程中提问是否安装,输入y后回车。

三、安装mysql服务

列出已启用的包含 “mysql.-community.” 关键字的软件包仓库

[root@szaliyun ~]# yum repolist enabled
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识                                                                               源名称                                                                                            状态
base/7/x86_64                                                                        CentOS-7                                                                                          10,070+2
epel/x86_64                                                                          Extra Packages for Enterprise Linux 7 - x86_64                                                    13,788+2
extras/7/x86_64                                                                      CentOS-7                                                                                               518
mysql-connectors-community/x86_64                                                    MySQL Connectors Community                                                                             234
mysql-tools-community/x86_64                                                         MySQL Tools Community                                                                                  102
mysql80-community/x86_64                                                             MySQL 8.0 Community Server                                                                             446
updates/7/x86_64                                                                     CentOS-7                                                                                           5,359+8
repolist: 30,517
[root@szaliyun ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                 234
mysql-tools-community/x86_64      MySQL Tools Community                      102
mysql80-community/x86_64          MySQL 8.0 Community Server                 446
[root@szaliyun ~]# 

yum repolist enabled 用于列出已启用的软件包仓库,grep “mysql.-community.” 用于过滤出包含 “mysql.-community.” 关键字的软件包仓库。

安装

[root@szaliyun ~]# yum install mysql-community-server
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
base                                                                                                                                                                    | 3.6 kB  00:00:00     
epel                                                                                                                                                                    | 4.7 kB  00:00:00     
extras                                                                                                                                                                  | 2.9 kB  00:00:00     
mysql-connectors-community                                                                                                                                              | 2.6 kB  00:00:00     
mysql-tools-community                                                                                                                                                   | 2.6 kB  00:00:19     
mysql80-community                                                                                                                                                       | 2.6 kB  00:00:04     
updates                                                                                                                                                                 | 2.9 kB  00:00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.8.0.35-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 8.0.35-1.el7,它被软件包 mysql-community-server-8.0.35-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-icu-data-files = 8.0.35-1.el7,它被软件包 mysql-community-server-8.0.35-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 8.0.11,它被软件包 mysql-community-server-8.0.35-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.8.0.35-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-client-plugins = 8.0.35-1.el7,它被软件包 mysql-community-client-8.0.35-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 8.0.11,它被软件包 mysql-community-client-8.0.35-1.el7.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.8.0.35-1.el7 将被 安装
---> 软件包 mysql-community-icu-data-files.x86_64.0.8.0.35-1.el7 将被 安装
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.68-1.el7 将被 取代
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
---> 软件包 mysql-community-client-plugins.x86_64.0.8.0.35-1.el7 将被 安装
---> 软件包 mysql-community-libs.x86_64.0.8.0.35-1.el7 将被 舍弃
--> 正在检查事务
---> 软件包 mysql-community-libs-compat.x86_64.0.8.0.35-1.el7 将被 舍弃
--> 解决依赖关系完成依赖关系解决===============================================================================================================================================================================================Package                                                    架构                               版本                                        源                                             大小
===============================================================================================================================================================================================
正在安装:mysql-community-libs                                       x86_64                             8.0.35-1.el7                                mysql80-community                             1.5 M替换  mariadb-libs.x86_64 1:5.5.68-1.el7mysql-community-libs-compat                                x86_64                             8.0.35-1.el7                                mysql80-community                             669 k替换  mariadb-libs.x86_64 1:5.5.68-1.el7mysql-community-server                                     x86_64                             8.0.35-1.el7                                mysql80-community                              64 M
为依赖而安装:mysql-community-client                                     x86_64                             8.0.35-1.el7                                mysql80-community                              16 Mmysql-community-client-plugins                             x86_64                             8.0.35-1.el7                                mysql80-community                             3.5 Mmysql-community-common                                     x86_64                             8.0.35-1.el7                                mysql80-community                             665 kmysql-community-icu-data-files                             x86_64                             8.0.35-1.el7                                mysql80-community                             2.2 M事务概要
===============================================================================================================================================================================================
安装  3 软件包 (+4 依赖软件包)总下载量:89 M
Is this ok [y/d/N]: y
Downloading packages:
mysql-community-client-8.0.35- FAILED                                             0% [                                                                       ] 1.1 kB/s |  46 kB  23:13:17 ETA 
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
mysql-community-client-plugins FAILED                                             0% [                                                                       ] 1.4 kB/s | 280 kB  18:15:11 ETA 
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
mysql-community-common-8.0.35- FAILED                                            0% [                                                                      ]  2.1 B/s | 434 kB 12427:49:49 ETA 
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-common-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-common-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
mysql-community-icu-data-files FAILED                                            0% [                                                                       ]  5.4 B/s |  68 kB 4752:59:45 ETA 
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
mysql-community-libs-8.0.35-1. FAILED                                            0% [                                                                      ]  0.8 B/s | 184 kB 31857:32:53 ETA 
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-libs-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-libs-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
mysql-community-libs-compat-8. FAILED                                            0% [                                                                       ]  9.6 B/s | 550 kB 2674:52:24 ETA 
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-libs-compat-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-libs-compat-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。mysql-community-server-8.0.35- FAILED                                          
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-server-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-server-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
mysql-community-client-8.0.35- FAILED                                            0% [-                                                                      ]  5.6 B/s | 804 kB 4605:51:37 ETA 
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
警告:/var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEYkB/s | 3.3 MB  00:01:59 ETA 
mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm 的公钥尚未安装
(1/7): mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm                                                                                                           | 3.5 MB  00:00:02     
(2/7): mysql-community-common-8.0.35-1.el7.x86_64.rpm                                                                                                                   | 665 kB  00:00:00     
(3/7): mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm                                                                                                           | 2.2 MB  00:00:00     
(4/7): mysql-community-libs-8.0.35-1.el7.x86_64.rpm                                                                                                                     | 1.5 MB  00:00:00     
(5/7): mysql-community-libs-compat-8.0.35-1.el7.x86_64.rpm                                                                                                              | 669 kB  00:00:00     
(6/7): mysql-community-server-8.0.35-1.el7.x86_64.rpm                                                                                                                   |  64 MB  00:00:10     
(7/7): mysql-community-client-8.0.35-1.el7.x86_64.rpm                                                                                                                   |  16 MB  00:00:02     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                            71 kB/s |  89 MB  00:21:14     
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023 检索密钥
导入 GPG key 0xA8D3785C:用户ID     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"指纹       : bca4 3417 c3b4 85dd 128e c6d4 b7b3 b788 a8d3 785c软件包     : mysql80-community-release-el7-11.noarch (@/mysql80-community-release-el7-11.noarch)来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
是否继续?[y/N]:从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022 检索密钥
导入 GPG key 0x3A79BD29:用户ID     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"指纹       : 859b e8d7 c586 f538 430b 19c2 467b 942d 3a79 bd29软件包     : mysql80-community-release-el7-11.noarch (@/mysql80-community-release-el7-11.noarch)来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
是否继续?[y/N]:y
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥
导入 GPG key 0x5072E1F5:用户ID     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"指纹       : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5软件包     : mysql80-community-release-el7-11.noarch (@/mysql80-community-release-el7-11.noarch)来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装    : mysql-community-common-8.0.35-1.el7.x86_64                                                                                                                                 1/8 正在安装    : mysql-community-client-plugins-8.0.35-1.el7.x86_64                                                                                                                         2/8 正在安装    : mysql-community-libs-8.0.35-1.el7.x86_64                                                                                                                                   3/8 正在安装    : mysql-community-client-8.0.35-1.el7.x86_64                                                                                                                                 4/8 正在安装    : mysql-community-icu-data-files-8.0.35-1.el7.x86_64                                                                                                                         5/8 正在安装    : mysql-community-server-8.0.35-1.el7.x86_64                                                                                                                                 6/8 
warning: /etc/my.cnf created as /etc/my.cnf.rpmnew正在安装    : mysql-community-libs-compat-8.0.35-1.el7.x86_64                                                                                                                            7/8 正在删除    : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                                         8/8 验证中      : mysql-community-client-plugins-8.0.35-1.el7.x86_64                                                                                                                         1/8 验证中      : mysql-community-common-8.0.35-1.el7.x86_64                                                                                                                                 2/8 验证中      : mysql-community-icu-data-files-8.0.35-1.el7.x86_64                                                                                                                         3/8 验证中      : mysql-community-libs-8.0.35-1.el7.x86_64                                                                                                                                   4/8 验证中      : mysql-community-client-8.0.35-1.el7.x86_64                                                                                                                                 5/8 验证中      : mysql-community-libs-compat-8.0.35-1.el7.x86_64                                                                                                                            6/8 验证中      : mysql-community-server-8.0.35-1.el7.x86_64                                                                                                                                 7/8 验证中      : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                                         8/8 已安装:mysql-community-libs.x86_64 0:8.0.35-1.el7                  mysql-community-libs-compat.x86_64 0:8.0.35-1.el7                  mysql-community-server.x86_64 0:8.0.35-1.el7                 作为依赖被安装:mysql-community-client.x86_64 0:8.0.35-1.el7                      mysql-community-client-plugins.x86_64 0:8.0.35-1.el7              mysql-community-common.x86_64 0:8.0.35-1.el7             mysql-community-icu-data-files.x86_64 0:8.0.35-1.el7             替代:mariadb-libs.x86_64 1:5.5.68-1.el7                                                                                                                                                           完毕!
[root@szaliyun ~]# 

可以看到安装并不顺利,程序自动更换镜像后安装最终完成。

四、启动mysql服务

[root@szaliyun ~]# systemctl status mysqld

启动失败,查日志
[root@szaliyun ~]# journalctl -xe | grep mysql
查到说redo log格式不对

1026 07:14:54 szaliyun mysqld[19819]: 2023-10-25T23:14:53.988237Z 1 [ERROR] [MY-013090] [InnoDB] Unsupported redo log format (v0). The redo log was created before MySQL 5.7.9

按网上查了一下,说是需要将ib_logfile0和ib_logfile1移走
于是查找并移走这两个文件,重启依旧报错,说找不到目录

Neither found #innodb_redo subdirectory, nor ib_logfile* files in /www/server/data/

尝试了网上说的一些方法,也解决不了,估计是mysql5.7版本没卸载导致8.0不能正常运行。
实在没办法就卸载重装吧:

[root@szaliyun ~]# rpm -qa | grep -i mysql
bt-mysql56-5.6.50-1.el7.x86_64
mysql-community-libs-8.0.35-1.el7.x86_64
mysql-community-libs-compat-8.0.35-1.el7.x86_64
mysql-community-client-plugins-8.0.35-1.el7.x86_64
mysql-community-client-8.0.35-1.el7.x86_64
mysql-community-server-8.0.35-1.el7.x86_64
mysql80-community-release-el7-11.noarch
mysql-community-common-8.0.35-1.el7.x86_64
mysql-community-icu-data-files-8.0.35-1.el7.x86_64
[root@szaliyun ~]# 
[root@szaliyun ~]# yum remove bt-mysql56-5.6.50-1.el7.x86_64
[root@szaliyun ~]# yum remove mysql-community-server-8.0.35-1.el7.x86_64
[root@szaliyun ~]# yum install mysql-community-server

启动mysql,继续报错:

[root@szaliyun ~]# cat /var/log/mysqld.log
2023-10-29T08:28:10.584709Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.35) initializing of server in progress as process 21123
2023-10-29T08:28:10.589908Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2023-10-29T08:28:10.589953Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2023-10-29T08:28:10.590006Z 0 [ERROR] [MY-010119] [Server] Aborting

关键是这一条:2023-10-29T08:28:10.589953Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
大概是说指定的这个目录不可用,你可以删除所有这些文件。做好备份后删掉重新启动。

[root@szaliyun lib]# cp -r mysql/ mysql231029back
[root@szaliyun lib]# cd mysql
[root@szaliyun mysql]# ls
auto.cnf  binlog.index  ca-key.pem  ca.pem  client-cert.pem  client-key.pem  #innodb_redo  mysql-bin  private_key.pem  public_key.pem  server-cert.pem  server-key.pem
[root@szaliyun mysql]# rm -rf /var/lib/mysql/*
[root@szaliyun mysql]# ls
[root@szaliyun mysql]# systemctl start mysql
Failed to start mysql.service: Unit not found.
[root@szaliyun mysql]# systemctl start mysqld
[root@szaliyun mysql]# 
[root@szaliyun mysql]# systemctl status mysqld
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: active (running) since 日 2023-10-29 16:46:32 CST; 6s agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlProcess: 11202 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)Main PID: 11369 (mysqld)Status: "Server is operational"CGroup: /system.slice/mysqld.service└─11369 /usr/sbin/mysqld1029 16:46:26 szaliyun systemd[1]: Starting MySQL Server...
1029 16:46:32 szaliyun systemd[1]: Started MySQL Server.
[root@szaliyun mysql]# 

启动成功!

五、获取并修改密码

获取临时密码

[root@szaliyun mysql]# grep 'temporary password' /var/log/mysqld.log
2023-10-29T08:46:29.090680Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: giAufyacf3</
[root@szaliyun mysql]# 

然后尝试登录

[root@szaliyun /]# mysql -u root -p
-bash: mysql: 未找到命令  
[root@szaliyun mysql]# which mysql
/usr/bin/which: no mysql in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@szaliyun mysql]#

没有找到mysql,经过几番测试,还是没找到mysql的安装目录,最后GPT让我重装。

[root@szaliyun mysql]# rpm -qa | grep mysql
mysql-community-libs-8.0.35-1.el7.x86_64
mysql-community-libs-compat-8.0.35-1.el7.x86_64
mysql-community-server-8.0.35-1.el7.x86_64
mysql-community-client-plugins-8.0.35-1.el7.x86_64
mysql-community-client-8.0.35-1.el7.x86_64
mysql80-community-release-el7-11.noarch
mysql-community-common-8.0.35-1.el7.x86_64
mysql-community-icu-data-files-8.0.35-1.el7.x86_64
[root@szaliyun mysql]# yum reinstall mysql-community-client-8.0.35-1.el7.x86_64

重装完之后就可以了

[root@szaliyun mysql]# which mysql
/usr/bin/mysql

然后就是修改密码:

[root@szaliyun /]# 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.35Copyright (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.mysql> 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'New%Password4';
Query OK, 0 rows affected (0.15 sec)mysql> 

至此修改密码完成。

六、防火墙放行、远程登录和设置

放开CentOS网络端口

[root@szaliyun ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@szaliyun ~]# firewall-cmd --reload

然后再在硬件防火墙上放开(如果需要),如果是使用云服务器(例如阿里云),则在云供应商的设置页面放开3306端口。
然后在公网上telnet ip 3306,端口通了。
再使用SQLyog尝试连接数据库,显示 :
在这里插入图片描述

出现这个Host is not allowed to connect to this MySQL server很常见,就是我现在要连接的ip没有授权访问,授权就好。

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 -ADatabase changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)mysql> 

继续测试连接,报下面错误:

在这里插入图片描述
Plugin caching_sha2_password could not be loaded报错
这是因为MYSQL8.0版使用了新的密码机制。
为了方便,将密码机制改为mysql_native_password(安全性降低了)

mysql> select Host,User,Plugin from mysql.user;
+-----------+------------------+-----------------------+
| Host      | User             | Plugin                |
+-----------+------------------+-----------------------+
| %         | root             | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)mysql> alter user root@'%' identified with mysql_native_password by 'New#password2';
Query OK, 0 rows affected (0.00 sec)mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)mysql> select Host,User,Plugin from mysql.user;
+-----------+------------------+-----------------------+
| Host      | User             | Plugin                |
+-----------+------------------+-----------------------+
| %         | root             | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)mysql>

再测试连接,成功!
在这里插入图片描述

七、命令记录

过程中敲过的一些命令:

#安装MYSQL8的yum源
[root@szaliyun ~]# yum localinstall https://repo.mysql.com//mysql80-community-release-el7-11.noarch.rpm
[root@szaliyun ~]# yum repolist enabled
[root@szaliyun ~]# yum repolist enabled | grep "mysql.*-community.*" 
[root@szaliyun ~]# find / -name ib_logfile0  #查找文件
[root@szaliyun data]# mkdir ib_logfilebackup
[root@szaliyun data]# cp ib_logfile0 ib_logfilebackup/
#卸载mysql5.6
[root@szaliyun ~]# yum remove bt-mysql56-5.6.50-1.el7.x86_64
#卸载mysql-community-server
[root@szaliyun ~]# yum remove mysql-community-server-8.0.35-1.el7.x86_64
[root@szaliyun ~]# yum install mysql-community-server
[root@szaliyun ~]# systemctl start mysqld
[root@szaliyun ~]# systemctl status mysqld
[root@szaliyun ~]# cat /var/log/mysqld.log
[root@szaliyun ~]# which mysql
#重装mysql客户端
[root@szaliyun mysql]# yum reinstall mysql-community-client-8.0.35-1.el7.x86_64
[root@szaliyun ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@szaliyun ~]# firewall-cmd --reload
[root@szaliyun /]# mysql -u root -p
#修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'New%Password4';  
#放开所有地址访问数据库
mysql> update user set host = '%' where user = 'root';
#修改密码规则
mysql> alter user root@'%' identified with mysql_native_password by 'New#password2'; 

相关文章:

在CentOS上用yum方式安装MySQL8过程记录

此文参考官方文档一步一步记录安装到正常运行全过程 安装环境&#xff1a;centos7 mysql版本&#xff1a;8.0.35 安装过程主要参考下面两边文章&#xff1a; 1.官方文档 https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html 2.linux yum安装mysql8 安…...

CEYEE希亦新品洗地机Pro系列发布, 领跑行业的「水汽混动」技术的旗舰新杰作

CEYEE希亦全新一代洗地机T800 PRO正式上市&#xff0c;采用双滚刷&#xff0c;双倍活水洗拖洗方式&#xff0c;达到拖一遍抵两遍&#xff0c;相对于10倍洁净效果&#xff01; 这款希亦Pro系列产品不仅刷新了洗地机行业技术水准&#xff0c;满足了用户愈发极致的清洁效能追求&a…...

为什么要安装防静电门禁闸机

安装防静电门禁闸机可以带来以下几个方面的好处&#xff1a; 防止静电干扰&#xff1a;静电是一种非常危险的物理现象&#xff0c;它可以对电子元器件、电路板和其他敏感设备造成损害&#xff0c;甚至导致设备故障和生产中断。防静电门禁闸机可以有效地防止静电的产生和传导&am…...

[linux] shell中的()和{}

参考&#xff1a;https://www.cnblogs.com/cheer-lingmu/p/16467561.html 参考&#xff1a;shell中各种括号的作用详解()、(())、[]、[[]]、{}(推荐)_linux shell_脚本之家 一、小括号() 1、命令替换&#xff1a;等同于cmd&#xff0c;shell扫描一遍命令行&#xff0c;发现了…...

jdk官网下载(详细步骤)

jdk全部版本下载网址 Java Archive | Oraclehttps://www.oracle.com/java/technologies/downloads/archive/ 下载之前先建立oracle账号(免费创建)&#xff0c;不用特意去搜&#xff0c;你点击下载jdk的时候会自动弹出来&#xff0c;自己建立一个账号就能下载了 找到自己要下载…...

10.24 校招 实习 内推 面经

绿*泡*泡&#xff1a; neituijunsir 交流裙 &#xff0c;内推/实习/校招汇总表格 1、校招 | 吉利控股集团2024届全球校园招聘路特斯科技专场&#xff08;内推&#xff09; 校招 | 吉利控股集团2024届全球校园招聘路特斯科技专场&#xff08;内推&#xff09; 2、数字IC验证…...

Pico Neo4、Neo3开发手柄的使用交互监听

using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.XR;public class InputEvent : MonoSingleton<InputEvent> {//*************输入设别**************************InputDevice leftHandController;Inp…...

【k8s】pod详解

一、Pod介绍 1、Pod的基础概念 Pod是kubernetes中最小的资源管理组件&#xff0c;Pod也是最小化运行容器化应用的资源对象&#xff0c;一个pod代表着集群中运行的一个进程。kubernetes中其它大多数组件都是围绕着pod来进行支持和扩展pod功能的。 例如&#xff0c;用于管理po…...

优思学院:质量管理7原则、8大要点

在质量管理的道路上&#xff0c;没有捷径可循。质量管理是一项需要不断积累经验和智慧的长期过程&#xff0c;其中涵盖了七大关键原则&#xff0c;这些原则是组织在质量管理方面取得持续成功的基石。 1. 以顾客为关注焦点 释义&#xff1a; 质量管理的核心在于满足顾客需求&am…...

自动化测试如何解析excel文件?

前言 自动化测试中我们存放数据无非是使用文件或者数据库&#xff0c;那么文件可以是csv&#xff0c;xlsx&#xff0c;xml&#xff0c;甚至是txt文件&#xff0c;通常excel文件往往是我们的首选&#xff0c;无论是编写测试用例还是存放测试数据&#xff0c;excel都是很方便的。…...

职场好物:乐歌M9S升降办公电脑台,告别久坐办公,升职加薪就选它

办公是现代生活不可避免的组成部分&#xff0c;科技的快速发展&#xff0c;给了我们更多新的生活方式&#xff0c;促使我们更加关注自己的身体状况&#xff0c;我们挨过了饭都吃不饱的年代&#xff0c;随着办公人群的不断扩张&#xff0c;不知道你有没有发现身边人或多或少都有…...

springboot+vue基于Hadoop短视频流量数据分析与可视化系统的设计与实现【内含源码+文档+部署教程】

博主介绍&#xff1a;✌全网粉丝10W,前互联网大厂软件研发、集结硕博英豪成立工作室。专注于计算机相关专业毕业设计项目实战6年之久&#xff0c;选择我们就是选择放心、选择安心毕业✌ &#x1f345;由于篇幅限制&#xff0c;想要获取完整文章或者源码&#xff0c;或者代做&am…...

审核 Microsoft SQL Server 日志

手动审核数据库活动是一项艰巨的任务&#xff0c;有效完成审计的最佳方法是使用简化和自动化数据库监控的综合解决方案&#xff0c;该解决方案还应使数据库管理员能够监控、跟踪和即时识别任何操作问题的根本原因&#xff0c;并实时检测对机密数据的未经授权的访问。 什么是 S…...

【NLP】什么是语义搜索以及如何实现 [Python、BERT、Elasticsearch]

语义搜索是一种先进的信息检索技术&#xff0c;旨在通过理解搜索查询和搜索内容的上下文和含义来提高搜索结果的准确性和相关性。与依赖于匹配特定单词或短语的传统基于关键字的搜索不同&#xff0c;语义搜索会考虑查询的意图、上下文和语义。 语义搜索在搜索结果的精度和相关…...

【JavaScript】JS基础语法

1 JavaScript 的书写形式 1.1 行内式 直接嵌入到 html 元素内部 <input type"button" value"按钮" onclick"alert(hello JavaScript)" >1.2 内嵌式 写在script标签内 <script>alert("haha")</script>1.3 外部式…...

06-云计算概览及问题关注

容器生态系统 容器生态系统包含核心技术、平台技术和支持技术。 1-1 容器核心技术 其中容器核心技术指的是能让容器在主机服务器上运行的技术&#xff0c;包含容器规范、容器 runtime、容器管理工具、容器生态工具、registries、容器 OS。 容器规范&#xff1a; 容器除了常…...

怎么监控钉钉聊天记录内容(监控钉钉聊天记录的3种形式)

企业沟通工具的普及&#xff0c;越来越多的企业开始使用钉钉作为内部沟通工具。然而&#xff0c;对于企业管理者来说&#xff0c;如何监控钉钉聊天记录内容成为了一个重要的问题。本文将介绍几种方法&#xff0c;帮助企业管理者实现监控钉钉聊天记录内容的目的。 一、钉钉自带功…...

深入理解强化学习——强化学习的历史:时序差分学习

分类目录&#xff1a;《深入理解强化学习》总目录 相关文章&#xff1a; 强化学习的历史&#xff1a;最优控制 强化学习的历史&#xff1a;试错学习 强化学习的历史&#xff1a;试错学习的发展 强化学习的历史&#xff1a;K臂赌博机、统计学习理论和自适应系统 强化学习的…...

OpenCloudOS9操作系统搭建Confluence8.0.4企业WIKI

OpenCloudOS9操作系统搭建Confluence8.0.4企业WIKI 1. 概要2. 系统基础环境配置3. 安装并配置MySQL3.1. 安装MySQL3.2. MySQL基本配置3.3. 创建Confluence数据库4. 安装并配置Confluence5. 破解Confluence6. 优化配置Confluence7. confluence对接Windows AD域环境1. 概要 Atlas…...

03-Vue中的常用指令的使用,事件及其修饰符

常用指令 指令语法和插值语法 Vue框架中的所有指令的名字都以v-开始,完整语法格式<HTML标签 v-指令名:参数"javascript表达式(表达式的结果是一个值)"></HTML标签>: 指令的职责是当表达式的值改变时,将其产生的连带影响,响应式地作用于DOM元素不是所有…...

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...

C++:std::is_convertible

C++标志库中提供is_convertible,可以测试一种类型是否可以转换为另一只类型: template <class From, class To> struct is_convertible; 使用举例: #include <iostream> #include <string>using namespace std;struct A { }; struct B : A { };int main…...

【Java学习笔记】Arrays类

Arrays 类 1. 导入包&#xff1a;import java.util.Arrays 2. 常用方法一览表 方法描述Arrays.toString()返回数组的字符串形式Arrays.sort()排序&#xff08;自然排序和定制排序&#xff09;Arrays.binarySearch()通过二分搜索法进行查找&#xff08;前提&#xff1a;数组是…...

【SpringBoot】100、SpringBoot中使用自定义注解+AOP实现参数自动解密

在实际项目中,用户注册、登录、修改密码等操作,都涉及到参数传输安全问题。所以我们需要在前端对账户、密码等敏感信息加密传输,在后端接收到数据后能自动解密。 1、引入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId...

spring:实例工厂方法获取bean

spring处理使用静态工厂方法获取bean实例&#xff0c;也可以通过实例工厂方法获取bean实例。 实例工厂方法步骤如下&#xff1a; 定义实例工厂类&#xff08;Java代码&#xff09;&#xff0c;定义实例工厂&#xff08;xml&#xff09;&#xff0c;定义调用实例工厂&#xff…...

安宝特方案丨船舶智造的“AR+AI+作业标准化管理解决方案”(装配)

船舶制造装配管理现状&#xff1a;装配工作依赖人工经验&#xff0c;装配工人凭借长期实践积累的操作技巧完成零部件组装。企业通常制定了装配作业指导书&#xff0c;但在实际执行中&#xff0c;工人对指导书的理解和遵循程度参差不齐。 船舶装配过程中的挑战与需求 挑战 (1…...

基于TurtleBot3在Gazebo地图实现机器人远程控制

1. TurtleBot3环境配置 # 下载TurtleBot3核心包 mkdir -p ~/catkin_ws/src cd ~/catkin_ws/src git clone -b noetic-devel https://github.com/ROBOTIS-GIT/turtlebot3.git git clone -b noetic https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git git clone -b noetic-dev…...

A2A JS SDK 完整教程:快速入门指南

目录 什么是 A2A JS SDK?A2A JS 安装与设置A2A JS 核心概念创建你的第一个 A2A JS 代理A2A JS 服务端开发A2A JS 客户端使用A2A JS 高级特性A2A JS 最佳实践A2A JS 故障排除 什么是 A2A JS SDK? A2A JS SDK 是一个专为 JavaScript/TypeScript 开发者设计的强大库&#xff…...

【Nginx】使用 Nginx+Lua 实现基于 IP 的访问频率限制

使用 NginxLua 实现基于 IP 的访问频率限制 在高并发场景下&#xff0c;限制某个 IP 的访问频率是非常重要的&#xff0c;可以有效防止恶意攻击或错误配置导致的服务宕机。以下是一个详细的实现方案&#xff0c;使用 Nginx 和 Lua 脚本结合 Redis 来实现基于 IP 的访问频率限制…...

在 Spring Boot 项目里,MYSQL中json类型字段使用

前言&#xff1a; 因为程序特殊需求导致&#xff0c;需要mysql数据库存储json类型数据&#xff0c;因此记录一下使用流程 1.java实体中新增字段 private List<User> users 2.增加mybatis-plus注解 TableField(typeHandler FastjsonTypeHandler.class) private Lis…...