centos7 源码安装mysql8.0
时间: 2023-10-09 16:11:02 浏览: 139
安装 MySQL 8.0 源码需要以下步骤:
1. 安装必要的依赖项
```bash
sudo yum install -y gcc gcc-c++ ncurses-devel cmake make bison openssl-devel
```
2. 下载 MySQL 8.0 源码
```bash
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.26.tar.gz
```
3. 解压并进入源码目录
```bash
tar -zxvf mysql-8.0.26.tar.gz
cd mysql-8.0.26
```
4. 创建一个新的用户和组
```bash
sudo groupadd mysql
sudo useradd -r -g mysql -s /bin/false mysql
```
5. 配置 MySQL
```bash
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_BOOST=boost
```
6. 运行 make 命令进行编译和安装
```bash
make
sudo make install
```
7. 初始化 MySQL
```bash
sudo /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
```
8. 启动 MySQL
```bash
sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &
```
9. 设置 MySQL root 用户的密码
```bash
sudo /usr/local/mysql/bin/mysql_secure_installation
```
10. 配置 MySQL 自启动
```bash
sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
sudo chmod +x /etc/init.d/mysql
sudo chkconfig --add mysql
sudo chkconfig --level 345 mysql on
```
现在,你已经成功地从源码安装了 MySQL 8.0。
阅读全文