Mysql clion 源碼編譯調試 MacOS

Abstract

本文會記錄如何在macos上使用clion debug mysql源代碼.

環境

MACOS, CLION 2019.2

步驟

  1. 下載源碼官方GITHUB , 我clone的 防止代碼後續有變化.

  2. 在clion中Import as new cmake project.
    然後默認編譯完成後 遇到如下錯誤:

Make Error at cmake/boost.cmake:104 (MESSAGE):
  You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>

  This CMake script will look for boost in <directory>.  If it is not there,
  it will download and unpack it (in that directory) for you.

  You can also download boost manually, from
  https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz

  If you are inside a firewall, you may need to use an https proxy:

  export https_proxy=http://example.com:80
  1. 手動下載boost https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz

  2. 在源碼目錄新建如下目錄AbuildDownloaded臨時目錄, 然後把boost下載的文件放進去.
    boost在AbuildDownloaded新建my.cnf文件內容如下(目錄按照自身環境修改, 這裏使用了額外的端口33070, 保證不與本地的mysql衝突):

[mysqld]
port=33070
transaction_isolation=READ-COMMITTED
basedir=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded/
datadir=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded/datadir
socket=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded/mysql.sock
[mysql]
sql_mode=ONLY_FULL_GROUP_BY,NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  1. 修改cmake配置
    在這裏插入圖片描述添加CMake options 設置boost路徑:
    在這裏插入圖片描述
-DWITH_BOOST=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded/

自動編譯完成的界面:
在這裏插入圖片描述

  1. 編譯運行mysqld debug模式和配置mysqld啓動參數
    debug這個main方法:
    在這裏插入圖片描述這一步完成後, 你應該可以看見編譯好的mysqld和 debug欄目, 但是啓動還有報錯:
    在這裏插入圖片描述此時需要, 修改debug模式的啓動參數:
    在這裏插入圖片描述--defaults-file=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded/my.cnf --basedir=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded --datadir=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded/datadir --initialize-insecure

初始化完成後, 再刪除–initialize-insecure重新debug一次.
運行mysqld完成:
在這裏插入圖片描述

  1. 測試mysql
    需要先生成mysql連接客戶端的工具.
    在這裏插入圖片描述執行這個配置debug, 然後folder裏面就有了mysql這個命令:
    在這裏插入圖片描述測試mysql 執行如下命令:
    ./cmake-build-debug/bin/mysql -u root -h 127.0.0.1 -P33070
    在這裏插入圖片描述debug 每個sql語句:
    在這裏插入圖片描述
發佈了78 篇原創文章 · 獲贊 30 · 訪問量 25萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章