【Centos】yum 安装mariaDB

本文介绍如何在Linux系统中使用yum命令搜索并安装Mariadb服务及其客户端所需的库文件,并提供了启动及登录Mariadb的方法。
[dream361@za ~]$ sudo yum search mariadb  #查找需安装的包
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients #mariadb客户端
mariadb-server.x86_64 : The MariaDB server and related files  #mariadb服务
[dream361@za ~]$ sudo yum install -y mariadb-server.x86_64 mariadb-libs.x86_64  #安装搜索到的正确的包
[dream361@za ~]$ systemctl start mariadb #启动mariadb
[dream361@za ~]$ systemctl status mariadb #查看是否启动
[dream361@za ~]$ mysql_secure_installation #安装数据库实例
[dream361@za ~]$ sudo mysql -uroot -p1 #登录mysql

 

转载于:https://www.cnblogs.com/zhengwenqiang/p/6804573.html

### 编写 Shell 脚本以在 CentOS 7 上通过 Yum 安装 MariaDB 为了实现自动化部署,可以创建一个名为 `install_mariadb.sh` 的 Bash 脚本来完成此操作。该脚本会执行必要的预处理工作并调用 yum安装 MariaDB。 #### 关闭 SELinux 和防火墙设置 考虑到安全性和网络访问的需求,建议先调整 SELinux 设置以及清理 iptables 规则以便允许数据库服务正常运行: ```bash #!/bin/bash # 备份原始配置文件以防恢复 cp /etc/selinux/config /etc/selinux/config.bak # 修改SELinux状态为禁用 sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config # 清除现有iptables规则 iptables -F service iptables save ``` 上述命令修改了 `/etc/selinux/config` 文件中的 SELinux 配置选项,并清除了所有的 IP 表规则[^3]。 #### 使用 Yum 安装 MariaDB 及其开发工具包 接下来的部分负责实际的软件包安装过程,这里不仅限于服务器组件还包括客户端和其他可能需要用到的支持库: ```bash # 更新系统仓库缓存 yum makecache fast # 安装MariaDB服务器及相关依赖项 yum install -y mariadb-server mariadb-devel # 启动MariaDB服务并将它设为开机自启 systemctl start mariadb.service systemctl enable mariadb.service echo "MariaDB 已成功安装" ``` 这段代码片段利用 yum 命令来获取最新的元数据信息,接着指定要安装的具体软件包名称列表,最后启动新安装的服务程序并且将其加入到系统的初始化进程中去[^1][^2]。 完整的 shell 脚本如下所示: ```bash #!/bin/bash # Backup original config file before making changes cp /etc/selinux/config /etc/selinux/config.bak # Disable SELinux by modifying its configuration file sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config # Clear existing iptables rules to allow database service operation iptables -F service iptables save # Update system repository cache yum makecache fast # Install MariaDB server along with development packages yum install -y mariadb-server mariadb-devel # Start MariaDB service and set it up as a boot-starting service systemctl start mariadb.service systemctl enable mariadb.service echo "MariaDB has been successfully installed." ``` 保存以上内容至 `.sh` 文件后赋予可执行权限即可随时用来快速搭建环境。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值