centos7 源码安装mysql
时间: 2023-11-20 21:59:45 浏览: 184
centos7.x和centos6.x源码安装mysql5.7.30
以下是在CentOS 7上源码安装MySQL的步骤:
1.下载MySQL源码包并解压缩
```shell
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.26.tar.gz
tar -zxvf mysql-8.0.26.tar.gz
```
2.安装必要的依赖项
```shell
yum install -y gcc gcc-c++ ncurses-devel cmake make
```
3.创建MySQL用户和用户组
```shell
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
```
4.编译和安装MySQL
```shell
cd mysql-8.0.26
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=OFF
make && make install
```
5.初始化MySQL
```shell
cd /usr/local/mysql
mkdir data
chown -R mysql:mysql data
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
```
6.启动MySQL服务
```shell
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
systemctl enable mysqld
systemctl start mysqld
```
7.设置MySQL的root用户密码
```shell
./bin/mysql_secure_installation
```
阅读全文