mysql 5.7 的安装过程

本文详细介绍在Linux环境下如何通过rpm和yum方式安装MySQL 5.7.25版本,包括关闭防火墙、禁用SELinux、配置hosts文件、卸载旧版本、安装必要组件等步骤,并提供了启动、停止MySQL服务的方法及初始密码的获取途径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

www.oracle.com
下载 bundle 包

为了能做远程访问,先做一下一下基础配置
关闭防火墙:
#2:配置hosts 解析
systemctl stop firewalld
systemctl disable firewalld
systemctl disable firewalld.service
systemctl disable iptable.service

关闭selinux:
sed -i ‘/^SELINUX=/s/=.*/=disabled/’ /etc/selinux/config

cat > /etc/hosts <<EOF
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.106 Mysqlmaster
192.168.1.113 Mysqlnode1
EOF

1.使用 rpm 方式安装

须要的 mysql 组件,有 4 个:分别是 server、client、common、libs

yum install libaio -y
yum install net-tools -y

必须包:
yum install -y perl-Module-Install.noarch

查看旧版本 MySql
卸载系统自带Mariadb
rpm ‐qa | grep mysql
[root@Mysqlmaster ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64

[root@Mysqlmaster ~]# rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64

[root@Mysqlmaster ~]# rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps

‐e ‐‐nodeps
或者执行 一下命令卸载:

[root@Mysqlnode1 ~]# yum remove mariadb -y

rpm 命令安装 MySql 组件 rpm –ivh 安装
rpm ‐e ‐‐nodeps mariadb‐libs‐5.5.52‐1.el7.x86_64

安装顺序 common→libs→client→server
[root@Mysqlnode1 ~]# ll
总用量 198452
-rw-------. 1 root root 1437 4月 24 09:36 anaconda-ks.cfg
-rw-r–r--. 1 root root 25402568 4月 24 09:59 mysql-community-client-5.7.25-1.el7.x86_64.rpm
-rw-r–r--. 1 root root 280904 4月 24 09:59 mysql-community-common-5.7.25-1.el7.x86_64.rpm
-rw-r–r--. 1 root root 2271668 4月 24 09:59 mysql-community-libs-5.7.25-1.el7.x86_64.rpm
-rw-r–r--. 1 root root 2116628 4月 24 09:59 mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
-rw-r–r--. 1 root root 173130520 4月 24 09:59 mysql-community-server-5.7.25-1.el7.x86_64.rpm

使用rpm –ivh 命令安装
rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm

如果安装过程有问题解决不了,可以删除重装:

rpm -e mysql-community-common-5.7.25-1.el7.x86_64.rpm -nodeps

rpm -e mysql-community-libs-5.7.25-1.el7.x86_64.rpm
rpm -e mysql-community-client-5.7.25-1.el7.x86_64.rpm
rpm -e mysql-community-server-5.7.25-1.el7.x86_64.rpm

[root@Mysqlmaster ~]# rpm -qa|grep mysql
mysql-community-libs-5.7.25-1.el7.x86_64
mysql-community-client-5.7.25-1.el7.x86_64

mysql-community-server-5.7.25-1.el7.x86_64
mysql-community-common-5.7.25-1.el7.x86_64

也可以使用yum install 命令安装:

yum install -y mysql-community-common-5.7.25-1.el7.x86_64.rpm
yum install -y mysql-community-libs-5.7.25-1.el7.x86_64.rpm
yum install -y mysql-community-client-5.7.25-1.el7.x86_64.rpm
yum insatll -y mysql-community-server-5.7.25-1.el7.x86_64.rpm

[root@Mysqlnode1 ~]# yum install -y mysql-community-common-5.7.25-1.el7.x86_64.rpm
已加载插件:fastestmirror
正在检查 mysql-community-common-5.7.25-1.el7.x86_64.rpm: mysql-community-common-5.7.25-1.el7.x86_64
mysql-community-common-5.7.25-1.el7.x86_64.rpm 将被安装
正在解决依赖关系
–> 正在检查事务
—> 软件包 mysql-community-common.x86_64.0.5.7.25-1.el7 将被 安装
–> 解决依赖关系完成

启动 MySql

systemctl start mysqld 或 systemctl start mysqld.service

systemctl status mysqld.service 查看 mysql 状态

systemctl stop mysqld.service 关闭 mysql

数据库安装完成后回生产一个密码在/var/log/mysqld.log 文件中 d.h3qas,wn,O

[root@Mysqlmaster ~]# grep password /var/log/mysqld.log
2019-04-24T02:32:01.470540Z 1 [Note] A temporary password is generated for root@localhost: d.h3qas,wn,O

[root@Mysqlmaster ~]# mysql -p
Enter password:

输入密码:
d.h3qas,wn,O

[root@Mysqlmaster ~]# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25

Copyright © 2000, 2019, 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>

日志文件位置:

/var/log/mysqld.log

/var/log/mysqld.log mysql ‐uroot ‐p
禁用密码检测插件

修改配置文件/etc/my.cnf,添加如下内容:
[mysqld]
validate_password=OFF

mysql –p
[root@Mysqlmaster ~]# mysql -p
Enter password: d.h3qas,wn,O
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.25

然后设定新密码:
show variables like ‘validate_password%’;

set password for root@localhost=password(‘123456’);

授予 root 用户远程访问权限:

Use mysql;

select user,host from user;

授权远程登录
grant all privileges on . to root@’%’ identified by ‘123456’;

mysql ‐uroot ‐p123456 ‐h192.168.1.106

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值