作为一个linux领域的专家请帮我编写一个shell脚本:编译安装mysql
时间: 2024-06-10 12:06:52 浏览: 102
Sure,以下是编译安装MySQL的Shell脚本(适用于Ubuntu):
```
#!/bin/bash
# 安装必要的包
sudo apt update
sudo apt install build-essential
sudo apt install cmake
sudo apt install zlib1g-dev
# 下载并解压MySQL源码包
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.23.tar.gz
tar -zxvf mysql-8.0.23.tar.gz
# 进入MySQL源码包目录,编译安装
cd mysql-8.0.23
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
make -j$(grep processor /proc/cpuinfo | wc -l)
sudo make install
# 配置MySQL
sudo groupadd mysql
sudo useradd -r -g mysql -s /bin/false mysql
sudo mkdir -p /usr/local/mysql/data
sudo chown -R mysql:mysql /usr/local/mysql
# 初始化MySQL并设置密码
sudo /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data
sudo /usr/local/mysql/bin/mysql_ssl_rsa_setup
sudo chown -R root:root /usr/local/mysql
sudo chmod -R 755 /usr/local/mysql
sudo bash -c 'echo PATH=/usr/local/mysql/bin:$PATH >> /etc/environment'
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> ~/.bashrc
source ~/.bashrc
# 启动MySQL
sudo systemctl start mysql
```
希望对您有帮助!
阅读全文