linux安装mysql数据库一键脚本
时间: 2023-09-27 19:05:29 浏览: 153
以下是一个简单的一键安装脚本,可以在Linux系统上安装MySQL数据库:
```bash
#!/bin/bash
# 安装MySQL依赖
yum install -y wget
yum install -y gcc
yum install -y gcc-c++
yum install -y cmake
yum install -y ncurses-devel
# 下载MySQL源码包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.28.tar.gz
# 解压源码包
tar zxvf mysql-5.7.28.tar.gz
cd mysql-5.7.28
# 编译安装MySQL
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost
make && make install
# 创建MySQL配置文件
cat > /etc/my.cnf <<EOF
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/mysql.pid
log-error = /usr/local/mysql/mysql.err
EOF
# 初始化MySQL
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql
# 设置MySQL系统服务
cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig mysql on
# 启动MySQL服务
service mysql start
# 配置MySQL环境变量
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile
```
通过运行该脚本,将会自动下载、编译和安装MySQL,同时创建MySQL配置文件、初始化MySQL和设置MySQL系统服务。
阅读全文