安装MySQL8.4

安装MySQL8.4

前置条件

1.已正确安装Vmware,网络配置正常,如无可参考下面文章

2.已安装CentOS 9.0+版本及衍生版本(RedHat 9 、RockyLinux 9、AlmaLinux 9 等),如无可参考下面文章

安装AlmaLinux系统-真不错鸭
安装AlmaLinux系统-真不错鸭
真不错鸭的头像-真不错鸭5个月前
6012

3.系统优化及部分依赖软件

安装基础Linux组件-真不错鸭
安装基础Linux组件-真不错鸭
真不错鸭的头像-真不错鸭5个月前
937

安装流程

MySQL官方网站:https://www.mysql.com/

目前最新版是8.4版本,参考文档:Installing MySQL on Linux Using the MySQL Yum Repository

建议使用Google翻译,文档写的非常详细。

图片[1]-安装MySQL8.4-真不错鸭

1.添加 MySQL Yum 存储库

MySQL Yum 存储库页面 下载 mysql84-community-release-el9-1.noarch.rpm

图片[2]-安装MySQL8.4-真不错鸭

通过SSH工具将mysql84-community-release-el9-1.noarch.rpm上传到服务器用户目录中

[root@tutu ~]# ls
anaconda-ks.cfg  mysql84-community-release-el9-1.noarch.rpm

#安装下载的发布包
[root@tutu ~]# dnf localinstall mysql84-community-release-el9-1.noarch.rpm


#命令检查 MySQL Yum 存储库是否已成功添加并启用
[root@tutu ~]# dnf repolist enabled | grep mysql.*-community
mysql-8.4-lts-community                 MySQL 8.4 LTS Community Server
mysql-connectors-community              MySQL Connectors Community
mysql-tools-8.4-lts-community           MySQL Tools 8.4 LTS Community


注意:一旦您的系统上启用了 MySQL Yum 存储库,任何通过yum update 命令(或启用 dnf 的系统的dnf upgrade)进行的系统范围更新都会升级系统上的 MySQL 软件包并替换任何本机第三方软件包(如果 Yum 在 MySQL Yum 存储库中找到了它们的替代品);

会小版本升级,但不会大版本升级,贴心!

2.安装 MySQL

下面将安装 MySQL 服务器软件包(mysql-community-server)以及运行服务器所需的组件软件包,包括客户端软件包(mysql-community-client)、客户端和服务器的常见错误消息和字符集(mysql-community-common)以及共享客户端库(mysql-community-libs)

#安装MySQL
[root@tutu ~]# dnf install mysql-community-server

#启动MySQL
[root@tutu ~]# systemctl start mysqld

#查看MySQL状态
[root@tutu ~]# systemctl status mysqld

#MySQL开机启动
[root@tutu ~]# systemctl enable mysqld

#查看当前数据库的临时密码
[root@tutu ~]# grep 'temporary password' /var/log/mysqld.log
2024-12-18T13:12:38.671182Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: j)jf/1f0l=QW

#命令行用上面的临时密码登录MySQL
[root@tutu ~]# mysql -uroot -p
Enter password:


3.配置MySQL

命令行登录MySQL客户端后,配置root账户的密码及远程访问权限,下面注意修改成自己的MySQL的登陆密码。

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.3

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> 

#更改root密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Z8LDVX@K.jAanXa*zNex';
Query OK, 0 rows affected (0.00 sec)

#切换到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> update user set host='%' where user ='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,plugin from user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| root             | %         | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
4 rows in set (0.01 sec)

4.数据库软件连接及创建

使用Navicat进行连接

图片[3]-安装MySQL8.4-真不错鸭

如果检测连接一直失败,请检查Linux防火墙是否关闭 或者 是否打开3306访问端口

图片[4]-安装MySQL8.4-真不错鸭

创建数据库,utf8mb4是对应UTF-8编码,0900_ai_ci为MySQL8最新排序规则。

图片[5]-安装MySQL8.4-真不错鸭
图片[6]-安装MySQL8.4-真不错鸭
图片[7]-安装MySQL8.4-真不错鸭

© 版权声明
THE END
喜欢就支持一下吧
点赞1 分享