CentOS 安装 MySQL

本文详细指导如何下载并安装MySQL 8.0社区版,包括解压、各组件安装、配置过程,如初始化、设置防火墙、iptables规则,以及连接数据库的方法。最后演示了数据库安全设置,如修改密码和远程访问权限。
摘要由CSDN通过智能技术生成

下载 MySQL 安装包

MySQL :: Download MySQL Community Server

image-20211023141928418

安装 MySQL

解压安装包

rpm -ivh mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar

mysql/mysql_install_package.png · 阿洋/pictures - 码云 - 开源中国 (gitee.com)

安装

安装 mysql-community-common-8.0.27-1.el7.x86_64.rpm

rpm -ivh mysql-community-common-8.0.27-1.el7.x86_64.rpm

mysql/common.png · 阿洋/pictures - 码云 - 开源中国 (gitee.com)

安装 mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm

mysql/client_plugin.png · 阿洋/pictures - 码云 - 开源中国 (gitee.com)

安装 mysql-community-libs-8.0.27-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-8.0.27-1.el7.x86_64.rpm

mysql/libs.png · 阿洋/pictures - 码云 - 开源中国 (gitee.com)

安装 mysql-community-client-8.0.27-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-8.0.27-1.el7.x86_64.rpm

mysql/client.png · 阿洋/pictures - 码云 - 开源中国 (gitee.com)

安装 mysql-community-server-8.0.27-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-8.0.27-1.el7.x86_64.rpm

mysql/server.png · 阿洋/pictures - 码云 - 开源中国 (gitee.com)

数据库配置

初始化 MySQL

# 初始化数据库及相关配置
mysqld --initialize; 
chown mysql:mysql /var/lib/mysql -R;
systemctl start mysqld.service;
systemctl enable mysqld;
# 查看数据库密码
cat /var/log/mysqld.log |grep password

修改密码

使用上一步查询到的密码登录数据库,修改密码

alter uer 'root'@'localhost' identified with mysql_native_password by '你的密码';

允许远程访问

create user 'root'@'%' identified with mysql_native_password by '你的密码';
grant all privileges on '*' to 'root'@'%' with grant option;
flush privileges;

修改加密规则

alter user 'root'@'localhost' identified by '你的密码' PASSWORD EXPIRE NEVER;
flush privileges;

开放 3306 端口

关闭 firewall

systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl mask firewalld.service

安装 iptables

yum install -y iptables-services

配置 iptables

# 启动
systemctl enable iptables
systemctl start iptables

开放 3306 端口

vim /etc/sysconfig/iptables
  • iptables 添加 3306 端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
  • 重启 iptables
service iptables restart

使用 DBeaver 连接 MySQL

mysql/dbeaver_link_type.png · 阿洋/pictures - 码云 - 开源中国 (gitee.com)

mysql/dbeaver_link_test.png · 阿洋/pictures - 码云 - 开源中国 (gitee.com)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值