Linux下载、配置MySQL8.0

本文档详细介绍了如何在Linux系统中卸载Mariasdb,下载并安装MySQL8.0,包括解决依赖问题,初始化数据库,设置root用户密码,以及开启和配置远程访问。同时,提到了通过防火墙设置允许3306端口访问,以便于本地数据库管理软件的远程连接。

Linux下载、配置MySQL8.0

基础的环境都搭好了,现在搭一下数据库,用的是mysql

1. 查看Linux自带的数据库mariadb并删除

​ 这个数据库是mysql一个分支,不需要它给删除

[root@cx ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@cx ~]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
[root@cx ~]# rpm -qa|grep mariadb
[root@cx ~]# 

​ 可以看到已经删了,下面就开始下载MySQL

​ 进入下载页:https://downloads.mysql.com/archives/community/

​ 查看Linux版本

[root@cx ~]# uname -a
Linux cx 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

​ 然后就知道要下载的版本了,下载这个:mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar

切记切记切记,下载的是centos7,看准了版本


2. 在服务器上使用wget下载MySQL

[root@cx software-install]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar

​ 等下载完成,查看一下目录下文件

[root@cx software-install]# ls
jdk-8u221-linux-x64.rpm  mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar  node-v14.3.0-linux-x64.tar.gz  Python-3.6.3.tgz

​ 可以看到已经下载成功了

3. 安装mysql

[root@cx software-install]# tar -xvf mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar -C /opt/temp/
[root@cx temp]# ls
mysql-community-client-8.0.21-1.el7.x86_64.rpm           mysql-community-libs-8.0.21-1.el7.x86_64.rpm
mysql-community-common-8.0.21-1.el7.x86_64.rpm           mysql-community-libs-compat-8.0.21-1.el7.x86_64.rpm
mysql-community-devel-8.0.21-1.el7.x86_64.rpm            mysql-community-server-8.0.21-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.21-1.el7.x86_64.rpm  mysql-community-test-8.0.21-1.el7.x86_64.rpm

​ 依次安装MySQL数据库的mysql common、mysql libs、mysql client软件包,和server

[root@cx temp]# rpm -ivh mysql-community-common-8.0.21-1.el7.x86_64.rpm 
[root@cx temp]# rpm -ivh mysql-community-libs-8.0.21-1.el7.x86_64.rpm 

​ --nodeps:安装不检查依赖问题

​ --force:强制安装

[root@cx temp]# rpm -ivh mysql-community-client-8.0.21-1.el7.x86_64.rpm 
[root@cx temp]# rpm -ivh mysql-community-server-8.0.21-1.el7.x86_64.rpm 
warning: mysql-community-server-8.0.21-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	libaio.so.1()(64bit) is needed by mysql-community-server-8.0.21-1.el7.x86_64
	libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.21-1.el7.x86_64
	libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.21-1.el7.x86_64

​ 执行出现以上错误,离线安装的mysql缺少libaio.so.1文件

​ 文件地址:https://pkgs.org/download/libaio.so.1

​ 我们要下载的具体文件的下载页面:https://centos.pkgs.org/7/centos-x86_64/libaio-0.3.109-13.el7.x86_64.rpm.html

​ 具体文件地址:http://mirror.centos.org/centos/7/os/x86_64/Packages/libaio-0.3.109-13.el7.x86_64.rpm

[root@cx software-install]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libaio-0.3.109-13.el7.x86_64.rpm
[root@cx software-install]# ls
jdk-8u221-linux-x64.rpm           mysql-8.0.21-1.el8.x86_64.rpm-bundle.tar  Python-3.6.3.tgz
libaio-0.3.109-13.el7.x86_64.rpm  node-v14.3.0-linux-x64.tar.gz

​ 进入/opt/software-install目录下,进行下载

[root@cx software-install]# rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm
[root@cx software-install]# whereis libaio.so.1
libaio.so: /usr/lib64/libaio.so.1

​ 安装libaio并查看是否安装成功

​ 重新执行安装server的命令

[root@cx temp]# rpm -ivh mysql-community-server-8.0.21-1.el7.x86_64.rpm 

​ 看到安装成功了

​ 安装完后可以用rpm -qa查看一下

[root@cx temp]# rpm -qa|grep mysql
mysql-community-libs-8.0.21-1.el8.x86_64
mysql-community-server-8.0.21-1.el8.x86_64
mysql-community-common-8.0.21-1.el8.x86_64
mysql-community-client-8.0.21-1.el8.x86_64

4. 初始化mysql数据库

[root@cx temp]# mysqld --initialize;									# 初始化
[root@cx temp]# chown mysql:mysql /var/lib/mysql -R;					# 授权
[root@cx temp]# systemctl start mysqld									# 开启服务
[root@cx temp]# systemctl status mysqld									# 查看服务状态
[root@cx temp]# systemctl enable mysql									# 开机自启

5. 查看密码,重设置密码

​ 查看密码

[root@cx temp]# cat /var/log/mysqld.log | grep password
2021-11-14T05:16:17.754515Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: :Cld9aHkri:Q

​ 登录mysql

[root@cx temp]# 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.21

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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 with mysql_native_password by '密码';
Query OK, 0 rows affected (0.00 sec)

​ 退出重新登录

mysql> exit;
Bye
[root@cx temp]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.21 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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,root是登录账户,%代表任意地址,可以设置你固定的ip地址,密码是远程登录的密码

​ 1. 先创建用户

mysql> create user 'root'@'%' identified with mysql_native_password by '密码';

2. 设置远程访问并用flush privileges;刷新一下
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
mysql> flush privileges;

6. 本地数据库可视化软件连接服务器中的MySQL

​ 先看一下服务器的防火墙关没关

systemctl status firewalld

​ 主要看activate,如果是绿色的表示正在运行,灰色的是关闭的

systemctl stop firewalld


关完后去阿里云的控制台,防火墙规则里添加一个规则,开放MySQL的3306端口
阿里
本地可视化软件连接一下就🆗了
本地

### 如何在Linux系统上下载并安装MySQL 8.0 #### 下载MySQL 8.0 为了获取最新版本的 MySQL 8.0,在官方文档中建议通过 MySQL 的 Yum 存储库来完成这一过程。这能确保获得稳定版软件包以及后续更新的支持。 对于基于 Red Hat 或 CentOS Linux 发行版,可以使用如下命令创建 MySQL Yum Repository 文件 `/etc/yum.repos.d/mysql-community.repo`: ```bash cat <<EOF | sudo tee /etc/yum.repos.d/mysql-community.repo [mysql-connectors-community] name=MySQL Connectors Community baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/\$basearch/ enabled=1 gpgcheck=1 gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql [mysql-tools-community] name=MySQL Tools Community baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/\$basearch/ enabled=1 gpgcheck=1 gpgkey=https://repo.mysql.com/RPM-KEY-mysql [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/\$basearch/ enabled=0 gpgcheck=1 gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql [mysql80-community] name=MySQL 8.0 Community Server baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/\$basearch/ enabled=1 gpgcheck=1 gpgkey=https://repo.mysql.com/RPM-KEY-mysql EOF ``` 上述脚本配置了针对 MySQL 8.0 社区服务器的 yum 源,并启用了该源以便于下一步操作[^1]。 #### 安装MySQL 8.0服务 一旦成功设置了存储库,则可以通过 `yum` 命令轻松地安装 MySQL 8.0 服务端组件: ```bash sudo yum -y install mysql-community-server ``` 这条指令会自动解析依赖关系并将必要的文件部署到目标机器上。 #### 初始化数据库实例和服务启动设置 初次运行前需初始化数据目录结构,赋予初始权限给 root 用户账户,并随机生成临时密码用于首次登录验证;之后更改所属组为 mysql 并给予适当读写访问权限,最后开启 mysqld 服务进程及其开机自启功能: ```bash mysqld --initialize; chown mysql:mysql /var/lib/mysql -R; systemctl start mysqld.service; systemctl enable mysqld; ``` 这些步骤确保了新安装的服务能够正常运作并且安全可靠[^2]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值