从零开始: CentOS 7安装配置MySql数据库(MariaDB)

2年前 (2022) 程序员胖胖胖虎阿
262 0 0

文章目录

  • 介绍
  • 一、CentOS 7安装与配置
    • 1.安装系统
    • 2.配置系统
  • 二、安装及配置MariaDB
    • 1. 安装MariaDB
    • 2. 配置MariaDB
  • 三、外部访问系统或数据库
    • 1.访问系统
    • 2.访问数据库
  • THE END

介绍

Web项目的服务和数据库一般都部署在Linux服务器上, 本文介绍用虚拟机软件VMware安装CentOS 7操作系统, 以及安装和配置数据库.
(注: 之所以这里安装的是MariaDB数据库而非MySql, 是因为在CentOS 7中MySql不再免费,取而代之在CentOS 7内部集成了MariaDB, MariaDB是MySql的一个分支, 推荐使用)
需要: VMware WorkStation 16 Pro(VMbox也是可以的); CentOS 7 x64.


一、CentOS 7安装与配置

本文使用最小化安装的方式.

1.安装系统

step 1:
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 2: 选择自定义(高级)
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 3: 下一步
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 4: 选择稍后安装操作系统
从零开始: CentOS 7安装配置MySql数据库(MariaDB)

step 5: 选择Linux -> CentOS 7 64位
从零开始: CentOS 7安装配置MySql数据库(MariaDB)

step 6: 选择安装位置
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 7: 配置处理器数量
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 8: 配置虚拟机内存
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 9: 添加网络 -> 这里使用网络地址转换(NAT)
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 10: 直接使用推荐配置
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 11: 下一步
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 12: 下一步
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 13: 分配磁盘大小
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 14: 下一步
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 16: ①点击自定义硬件;②选择新CD/DVD;③选择你本地的ISO镜像文件, 最后关闭, 然后点击完成
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 17: 点击 开启此虚拟机, 开始安装
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 18: 选择Install CentOS 7
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 19: 语言选择英语, 点击continue
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 20: 设置时区(选择shanghai)
从零开始: CentOS 7安装配置MySql数据库(MariaDB)

从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 21: 选择安装硬盘
从零开始: CentOS 7安装配置MySql数据库(MariaDB)

从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 22: 连接网络
从零开始: CentOS 7安装配置MySql数据库(MariaDB)

从零开始: CentOS 7安装配置MySql数据库(MariaDB)
注: 如果你连接不上网络(正常如果连接上网络会如step 22图一所示: Wired(ens33)connected).
连接不上请参考这篇博文:

https://blog.csdn.net/m0_55667633/article/details/120694353

step 23: 配置root密码用户(建议设同一个密码), 然后等待下方安装完成即可
从零开始: CentOS 7安装配置MySql数据库(MariaDB)

step 24: 点击reboot, 系统会重启
从零开始: CentOS 7安装配置MySql数据库(MariaDB)

step 25: 输入设置的用户名和密码, 登录系统(推荐使用root身份登录)
从零开始: CentOS 7安装配置MySql数据库(MariaDB)

至此, 安装成功

2.配置系统

step 1: 更新yum, 查看是否可以使用yum, 输入以下命令:

yum update

出现以下结果代表网络畅通, yum可以使用, 输入y开始更新
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
继续输入y
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
成功后结果如下图所示:
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 2: 永久关闭Linux防火墙(注: 如果有需要可以自行设置出入站规则, 这里为了方便直接关闭了防火墙. 如果不关闭防火墙会导致外部无法访问数据库)
输入:

systemctl stop firewalld.service  

再输入:

systemctl status firewalld.service

即可永久关闭防火墙

二、安装及配置MariaDB

1. 安装MariaDB

step 1: 输入命令

yum install -y mariadb-server

安装成功如下图所示:
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 2: 启动服务

systemctl start mariadb.service

step 3: 添加到开机启动

systemctl enable mariadb.service

step 4: 进行初始化配置

mysql_secure_installation

此时没有密码, 直接按enter
-> Set Root password? 输入: Y 输入两遍你要设置的新密码
-> Remove anonymous users? 输入: Y
-> Disallow root login remotely? 输入: n
-> Remove test database and access to it? 输入: Y
-> Reload privilege tables now? 输入: Y
出现下图所示即代表初始化配置成功:
从零开始: CentOS 7安装配置MySql数据库(MariaDB)

2. 配置MariaDB

step 1: 登录MariaDB
输入:

mysql -uroot -p

输入你的密码后出现如下图所示则代表成功登录数据库
从零开始: CentOS 7安装配置MySql数据库(MariaDB)

step 2: 配置远程访问
在登录状态依次输入如下命令:

use mysql;
select User,authentication_string,Host from user;

注意这里最后输入的是你自己设定的密码

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码';
flush privileges;

三、外部访问系统或数据库

1.访问系统

这里使用Xshell演示连接到系统
step 1: 获取系统的IP地址
输入:

ifconfig

ip地址如图所示:
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 2: 使用Xshell建立连接
新建会话 -> 输入名称和拿到的IP地址 -> 点击连接 -> 接受并保存主机密钥 -> 输入用户名和密码
从零开始: CentOS 7安装配置MySql数据库(MariaDB)

2.访问数据库

这里使用idea集成的数据库演示(使用sqlyog操作是一样的)
step 1: 打开idea, 随便选一个项目
选择Database, 点击添加
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 2: 选择MariaDB
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
step 3: 配置连接属性
输入虚拟机IP地址 -> 输入用户名密码 -> (如果Test Connection上方显示没有依赖需要先安装) -> 测试连接 -> 连接成功
从零开始: CentOS 7安装配置MySql数据库(MariaDB)
从零开始: CentOS 7安装配置MySql数据库(MariaDB)


THE END

版权声明:程序员胖胖胖虎阿 发表于 2022年9月25日 下午2:24。
转载请注明:从零开始: CentOS 7安装配置MySql数据库(MariaDB) | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...