Linux下源码安装MySQL 8.0

MySQL 8.0源码安装

  • 环境准备
  • 步骤

环境准备

  1. Linux环境,本文基于CentOS 8

  2. MySQL安装包,本文基于MySQL 8.1,以下为带boost MySQL 8.1源码下载地址:
    https://dev.mysql.com/get/Downloads/MySQL-8.1/mysql-boost-8.1.0.tar.gz

步骤

  1. 解压
    tar -zxvf mysql-boost-8.1.0.tar.gz -C /data/mysql
  2. 创建安装路径,如install目录为安装路径
    mkdir /data/install
  3. 编译安装
    (1) 创建临时编译目录,mkdir /data/tmp_build; cd /data/tmp_build
    (2) cmake ../mysql -DWITH_SSL=system -DCMAKE_BUILD_TYPE=Debug -DWITH_BOOST=/data/mysql/boost -DCMAKE_INSTALL_PREFIX=/data/install
    此时可能出现安装缺少依赖报错,缺什么装什么即可,报错信息中都有提示。
    如本次测试环境缺少的包通过以下方式安装:
    yum install cmake bison-devel gcc-toolset-12 openssl openssl-devel ncurses ncurses-devel libaio-devel rpcgen
    (3) make -j64
    (4) make install
  4. 配置文件
    在/etc/下添加my.cnf配置文件,内容根据自己需要来,例如:
[mysql]
port = 3306
default-character-set = utf8mb4
socket = /data/install/data/mysql.sock
prompt = (\u@\h)[\d]>\_

[mysqld]
port = 3306
character_set_server = utf8mb4
socket = /data/install/data/mysql.sock
basedir = /data/install
server_id = 12345678
binlog_format = row
pid_file = /data/install/data/mysql.pid
datadir = /data/install/data
tmpdir = /data/install/tmp
user = mysql
log_error = /data/install/data/error.log
log_bin = /data/install/data/mysql-bin
sync_binlog = 1
  1. 安装启动
    MySQL官网有详细教程,如下:官网安装启动文档
    具体步骤入下:
# 添加用户和用户组
groupadd mysql
useradd -r -g mysql -s /bin/false mysql

# 创建数据目录
mkdir /data/install/data

# 创建临时表目录
mkdir /data/install/tmpdir

# 赋权
chown -R mysql:mysql /data/install

ln -s /data/install /usr/local/mysql
export PATH=$PATH:/usr/local/mysql/bin

# 初始化服务
mysqld --initialize --user=mysql
mysql_ssl_rsa_setup

# 启动服务,这里设置 systemctl start/stop mysqld 进行服务开启/关闭
cp ../support-files/mysql.server /etc/init.d/mysql.server  # 用于mysql.server start/stop 启动方式
cp /etc/init.d/mysql.server /etc/init.d/mysqld   # 用于 systemctl 启动方式
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
systemctl start mysqld

你可能感兴趣的:(linux,mysql)