centos7编译安装mysql8
时间: 2024-02-03 20:10:32 浏览: 138
CentOS编译安装MYSQL5.6.17
编译安装MySQL 8在CentOS 7上需要以下步骤:
1. 安装必要的依赖:
```
sudo yum install -y gcc-c++ cmake make bison ncurses-devel
```
2. 下载MySQL源代码:
```
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.26.tar.gz
```
3. 解压源代码包:
```
tar -zxvf mysql-8.0.26.tar.gz
```
4. 进入解压后的目录:
```
cd mysql-8.0.26
```
5. 创建一个用于安装MySQL的目录:
```
sudo mkdir /usr/local/mysql
```
6. 配置编译选项:
```
sudo 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_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci
```
7. 编译并安装MySQL:
```
sudo make && sudo make install
```
8. 初始化MySQL数据目录:
```
sudo /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
```
9. 设置MySQL服务:
```
sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
sudo chmod +x /etc/init.d/mysql
sudo chkconfig --add mysql
```
10. 启动MySQL服务:
```
sudo service mysql start
```
11. 运行安全脚本以提高MySQL的安全性:
```
sudo /usr/local/mysql/bin/mysql_secure_installation
```
12. 完成安装后,您可以使用以下命令登录到MySQL:
```
/usr/local/mysql/bin/mysql -u root -p
```
这样就完成了在CentOS 7上编译安装MySQL 8的过程。
阅读全文