#!/bin/bash # MariaDB安装脚本 _info() { echo -e "\e[32m$1\e[0m" } _error() { echo -e "\e[31m错误: $1\e[0m" exit 1 } _error_detect() { if ! eval "$1"; then _error "执行命令 ($1) 失败" fi } install_mariadb() { _info "开始安装MariaDB" _error_detect "apt update" _error_detect "apt install -yq mariadb-server" _error_detect "systemctl start mariadb" _error_detect "systemctl enable mariadb" _info "MariaDB安装完成" } configure_database() { read -r -p "请输入新数据库名称: " database_name read -r -p "请输入新数据库用户密码: " mysql_password cat >/tmp/.add_mysql.sql<