---
title: 应用反馈优化
description: "1. 首次编译安装MySQL。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengdevkithistory/hgcc/hist-hgcc/kunpenghgcc_06_0015.html
sourcePath: /source/zh/kunpengdevkithistory/hgcc/hist-hgcc/kunpenghgcc_06_0015.html
indexId: d25fe9c87c4cb629cde438d48dc29bdc7654fe23e67700e18488cc4bc8143df371
---
# 应用反馈优化

1. 首次编译安装MySQL。
  若源码在/home/mysql-8.0.24，在该目录下执行以下命令： 1 2 3 4 5 6 7 #创建profile存储目录 mkdir gcc_build cd gcc_build cmake .. -DCMAKE_INSTALL_PREFIX=/home/mysql-8.0.24/gcc_build/ -DBUILD_CONFIG=mysql_release -DWITH_BOOST=../boost -DCMAKE_CXX_FLAGS="-fcfgo-profile-generate=/home/mysql-8.0.24/gcc_build/mysql_profile/pgo_profile" -DCMAKE_C_FLAGS="-fcfgo-profile-generate=/home/mysql-8.0.24/gcc_build/mysql_profile/pgo_profile" make -j && make install -j

2. 启动MySQL。
  1 /home/mysql-8.0.24/gcc_build/bin/mysqld --defaults-file=/etc/my.cnf &

3. 运行基准测试，此处以sysbench为例。
  1 sysbench ./oltp_write_only.lua --threads=256 --mysql-user=root --mysql-password=123456 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-db=sysbench --forced-shutdown=off --time=120 --report-interval=1 --events=0 --table-size=10000000 --tables=1 run

4. 待基准测试结束后，profile会生成在/home/mysql-8.0.24/gcc_build/mysql_profile/pgo_profile。
  编译优化后

  1 2 3 cmake .. -DCMAKE_INSTALL_PREFIX=/home/mysql-8.0.24/gcc_build_pgoed -DBUILD_CONFIG=mysql_release -DWITH_BOOST=../boost -DCMAKE_CXX_FLAGS="-fcfgo-profile-use=/home/mysql-8.0.24/gcc_build/mysql_profile/pgo_profile -fprofile-correction -Wno-error=coverage-mismatch -Wno-error=missing-profile" -DCMAKE_C_FLAGS="-fcfgo-profile-use=/home/mysql-8.0.24/gcc_build/mysql_profile/pgo_profile -fprofile-correction -Wno-error=coverage-mismatch -Wno-error=missing-profile" make -j && make install -j

  如在安装遇到error: 'SYS_gettid' was not declared in this scope，可以通过以下方式解决: 在 /home/mysql-8.0.24/storage/innobase/buf/buf0buff.cc 开头添加 #include "sys/syscall.h"
