ubantu 编译安装mysql5.7
时间: 2023-10-28 12:00:16 浏览: 107
编译安装MySQL 5.7在Ubuntu上需要以下步骤:
1. 安装必要的依赖:
```shell
sudo apt-get install build-essential cmake libncurses5-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libssl-dev zlib1g-dev
```
2. 下载MySQL源代码:
```shell
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.35.tar.gz
```
3. 解压源代码包:
```shell
tar -zxvf mysql-5.7.35.tar.gz
cd mysql-5.7.35
```
4. 创建MySQL的编译目录,并切换到该目录:
```shell
mkdir build
cd build
```
5. 运行CMake生成Makefile:
```shell
cmake ..
```
6. 编译MySQL:
```shell
make
```
7. 安装MySQL:
```shell
sudo make install
```
8. 创建MySQL数据目录:
```shell
sudo mkdir /usr/local/mysql/data
```
9. 复制MySQL配置文件模板:
```shell
sudo cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
```
10. 初始化MySQL数据库:
```shell
sudo /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data
```
11. 设置MySQL的用户和组权限:
```shell
sudo chown -R mysql:mysql /usr/local/mysql/data
sudo chown -R mysql:mysql /usr/local/mysql/var
```
12. 启动MySQL服务:
```shell
sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &
```
13. 设置MySQL的环境变量:
```shell
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> ~/.bashrc
source ~/.bashrc
```
现在你应该已经成功编译安装了MySQL 5.7。可以使用命令`mysql -V`来验证安装是否成功。
阅读全文