暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

在CentOS8下安装MySQL8.0.31(更新)

数据中心知识 2023-04-26
300

前期写过一篇相同的文章,今天要部署一个MySQL数据库,发现文章中的链接已经无效了,再写一篇更新版,后期自己干活的时候直接复制粘贴就搞定了。

官网更新的链接

写上篇文章的时候,MySQL8的最新版本就是8.0.31,今天登录上去看到最新版本已经到了8.0.33了,之前的链接位置也调整了,这里重新更新一下链接位置。


登录官网主页:https://www.mysql.com/downloads/,选择社区版下载,如下图:

选择MySQL Community Server:

选择Archives:

按照下图步骤,获取下载的IP地址

最终拿到的官网地址为:https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.31-1.el8.x86_64.rpm-bundle.tar

获取 MySQL 8.0.31

进入CentOS系统后,创建一个下载目录,开始下载软件:

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.31-1.el8.x86_64.rpm-bundle.tar

执行结果:

--2023-04-23 09:37:14--  https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.31-1.el8.x86_64.rpm-bundle.tar

Resolving downloads.mysql.com (downloads.mysql.com)... 104.71.161.87, 2600:140b:2:99c::2e31, 2600:140b:2:99d::2e31

Connecting to downloads.mysql.com (downloads.mysql.com)|104.71.161.87|:443... connected.

HTTP request sent, awaiting response... 302 Moved Temporarily

Location: https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.31-1.el8.x86_64.rpm-bundle.tar [following]

--2023-04-23 09:37:15--  https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.31-1.el8.x86_64.rpm-bundle.tar

Resolving cdn.mysql.com (cdn.mysql.com)... 104.86.177.34

Connecting to cdn.mysql.com (cdn.mysql.com)|104.86.177.34|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 879155200 (838M) [application/x-tar]

Saving to: ‘mysql-8.0.31-1.el8.x86_64.rpm-bundle.tar’

mysql-8.0.31-1.el8. 100%[===================>] 838.43M  5.79MB/s    in 1m 55s

 

2023-04-23 09:39:11 (7.28 MB/s) - ‘mysql-8.0.31-1.el8.x86_64.rpm-bundle.tar’ saved [879155200/879155200]



解压:

tar -xvf mysql-8.0.31-1.el8.x86_64.rpm-bundle.tar

执行结果:

mysql-community-client-8.0.31-1.el8.x86_64.rpm

mysql-community-client-debuginfo-8.0.31-1.el8.x86_64.rpm

mysql-community-client-plugins-8.0.31-1.el8.x86_64.rpm

mysql-community-client-plugins-debuginfo-8.0.31-1.el8.x86_64.rpm

mysql-community-common-8.0.31-1.el8.x86_64.rpm

mysql-community-debuginfo-8.0.31-1.el8.x86_64.rpm

mysql-community-debugsource-8.0.31-1.el8.x86_64.rpm

mysql-community-devel-8.0.31-1.el8.x86_64.rpm

mysql-community-icu-data-files-8.0.31-1.el8.x86_64.rpm

mysql-community-libs-8.0.31-1.el8.x86_64.rpm

mysql-community-libs-debuginfo-8.0.31-1.el8.x86_64.rpm

mysql-community-server-8.0.31-1.el8.x86_64.rpm

mysql-community-server-debug-8.0.31-1.el8.x86_64.rpm

mysql-community-server-debug-debuginfo-8.0.31-1.el8.x86_64.rpm

mysql-community-server-debuginfo-8.0.31-1.el8.x86_64.rpm

mysql-community-test-8.0.31-1.el8.x86_64.rpm

mysql-community-test-debuginfo-8.0.31-1.el8.x86_64.rpm

开始安装 MySQL 8.0.31

安装之前,需要先安装net-tools和perl,采用yum安装的方式:

yum -y install net-tools

yum install -y perl

然后开始分6步安装软件:

rpm -ivh mysql-community-common-8.0.31-1.el8.x86_64.rpm

执行结果:

warning: mysql-community-common-8.0.31-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY

Verifying...                          ################################# [100%]

Preparing...                          ################################# [100%]

Updating installing...

   1:mysql-community-common-8.0.31-1.e################################# [100%]


rpm -ivh mysql-community-client-plugins-8.0.31-1.el8.x86_64.rpm

执行结果:

warning: mysql-community-client-plugins-8.0.31-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY

Verifying...                          ################################# [100%]

Preparing...                          ################################# [100%]

Updating installing...

   1:mysql-community-client-plugins-8.################################# [100%]


rpm -ivh mysql-community-libs-8.0.31-1.el8.x86_64.rpm

执行结果:

warning: mysql-community-libs-8.0.31-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY

Verifying...                          ################################# [100%]

Preparing...                          ################################# [100%]

Updating installing...

   1:mysql-community-libs-8.0.31-1.el8################################# [100%]


rpm -ivh mysql-community-client-8.0.31-1.el8.x86_64.rpm

执行结果:

warning: mysql-community-client-8.0.31-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY

Verifying...                          ################################# [100%]

Preparing...                          ################################# [100%]

Updating installing...

   1:mysql-community-client-8.0.31-1.e################################# [100%]


rpm -ivh mysql-community-icu-data-files-8.0.31-1.el8.x86_64.rpm

执行结果:

warning: mysql-community-icu-data-files-8.0.31-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY

Verifying...                          ################################# [100%]

Preparing...                          ################################# [100%]

Updating installing...

   1:mysql-community-icu-data-files-8.################################# [100%]


rpm -ivh mysql-community-server-8.0.31-1.el8.x86_64.rpm

执行结果:

warning: mysql-community-server-8.0.31-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY

Verifying...                          ################################# [100%]

Preparing...                          ################################# [100%]

Updating installing...

   1:mysql-community-server-8.0.31-1.e################################# [100%]


MySQL安装完的验证


上面的6个软件包装完后,MySQL就已经安装完成。可以做如下验证操作:

查看软件包

rpm -qa | grep -i mysql

执行结果:

mysql-community-common-8.0.31-1.el8.x86_64

mysql-community-icu-data-files-8.0.31-1.el8.x86_64

mysql-community-client-plugins-8.0.31-1.el8.x86_64

mysql-community-client-8.0.31-1.el8.x86_64

mysql-community-libs-8.0.31-1.el8.x86_64

mysql-community-server-8.0.31-1.el8.x86_64

查看安装的文件情况:

find / -name mysql

执行结果:

/etc/logrotate.d/mysql

/var/lib/selinux/targeted/active/modules/100/mysql

/var/lib/mysql

/usr/bin/mysql

/usr/lib64/mysql

/usr/share/selinux/targeted/default/active/modules/100/mysql

/soft/mysql

查看安装的软件版本:

mysql -V

执行结果:

mysql  Ver 8.0.31 for Linux on x86_64 (MySQL Community Server - GPL)


最后就是启动服务,并将服务写入开机自启中,并查看服务状态:

systemctl enable mysqld && systemctl start mysqld && systemctl status mysqld

执行结果:

mysqld.service - MySQL Server

   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor pres>

   Active: active (running) since Sun 2023-04-23 10:02:45 CST; 5h 22min ago

     Docs: man:mysqld(8)

           http://dev.mysql.com/doc/refman/en/using-systemd.html

  Process: 1098 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0>

 Main PID: 1145 (mysqld)

   Status: "Server is operational"

    Tasks: 38 (limit: 23507)

   Memory: 439.1M

   CGroup: /system.slice/mysqld.service

           └─1145 /usr/sbin/mysqld


Apr 23 10:02:42 MySQL systemd[1]: Starting MySQL Server...

Apr 23 10:02:45 MySQL systemd[1]: Started MySQL Server.


MySQL初始化

MySQL安装完成后,需要做一些初始化操作,比方说更改默认密码等:

查看临时密码:

grep "temporary password" /var/log/mysqld.log

执行结果:

[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: j-Sk87LZ,?!j

 通过临时密码登录MySQL命令行

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.31

 

Copyright (c) 2000, 2022, 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.


更改root账号的密码:

alter user root@localhost identified by 'Zqx9876@54';

执行结果:

Query OK, 0 rows affected (0.00 sec)


更改数据库

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


更新root账号的登录范围

update user set Host='%' where User='root' and Host='localhost';

执行结果:

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0


刷新权限

flush privileges;


退出

exit


至此,数据库安装配置就算成功了,后面就只剩指定路径及导入数据库的工作了。


感谢各位的阅读,本公众号会持续分享实际的服务案例,若感兴趣请关注该公众号。

需要作者分享内容的资源,请关注此公众号,后台发送 【共享资源】 获取下载链接


需要上门解决问题时,请及时联系我们

更多案例文章,请点击!



文章转载自数据中心知识,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论