Redhat 8.7 安装Mysql 8.0.34步骤(超级详细)

查看Redhat 版本

[root@node1-221 ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.7 (Ootpa)

下载MySQL Yum Repository

下载MySQL源官网地址:https://dev.mysql.com/downloads/repo/yum/
根据系统版本选择下载相应的MySQL Yum源
在这里插入图片描述

安装mysql

[root@node1-221 ~]# yum install mysql80-community-release-el8-7.noarch.rpm
[root@node1-221 ~]# yum repolist
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

repo id                                                                                         repo name
appstream                                                                                       appstream
baseos                                                                                          baseos
mysql-connectors-community                                                                      MySQL Connectors Community
mysql-tools-community                                                                           MySQL Tools Community
mysql80-community                                                                               MySQL 8.0 Community Server
[root@node1-221 ~]# yum repolist| grep mysql
mysql-connectors-community              MySQL Connectors Community
mysql-tools-community                   MySQL Tools Community
mysql80-community                       MySQL 8.0 Community Server

Disabling the Default MySQL Module

(EL8 systems only) EL8-based systems such as RHEL8 and Oracle Linux 8 include a MySQL module that is enabled by default. Unless this module is disabled, it masks packages provided by MySQL repositories. To disable the included module and make the MySQL repository packages visible, use the following command (for dnf-enabled systems, replace yum in the command with dnf):
EL8系统,需要禁掉默认的MySQL仓库

[root@node1-221 ~]# yum module disable mysql

安装MySQL

[root@node1-221 ~]# yum install mysql-community-server

启动MySQL

[root@node1-221 ~]# systemctl start mysqld
[root@node1-221 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2023-08-11 14:44:16 CST; 1s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 14401 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 14473 (mysqld)
   Status: "Server is operational"
    Tasks: 38 (limit: 24850)
   Memory: 454.2M
   CGroup: /system.slice/mysqld.service
           └─14473 /usr/sbin/mysqld

Aug 11 14:44:10 node1-221 systemd[1]: Starting MySQL Server...
Aug 11 14:44:16 node1-221 systemd[1]: Started MySQL Server.

查看MySQL临时密码

通过日志文件MySQL初始密码
MySQL的临时密码存放在/var/log/mysqld.log文件下

[root@node1-221 ~]# grep 'temporary password' /var/log/mysqld.log
2023-08-11T06:44:12.606853Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Ig3PKBN3z.36

进入MySQL,修改临时密码

[root@node1-221 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.34

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.
mysql> alter user 'root'@'localhost' identified by 'Lab123!@#';
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

使用新密码登陆MySQL

[root@node1-221 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.34 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.

mysql> 

通过客户端登陆,不成功
在这里插入图片描述


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 -A

Database changed
mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

可以正常通过客户端远程登陆数据库了
在这里插入图片描述

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值