Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL8.0 source build #15

Closed
masayuki14 opened this issue Aug 2, 2018 · 119 comments
Closed

MySQL8.0 source build #15

masayuki14 opened this issue Aug 2, 2018 · 119 comments

Comments

@masayuki14
Copy link
Owner

masayuki14 commented Aug 2, 2018

@masayuki14
Copy link
Owner Author

$ cmake .. -DWITH_DEBUG=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=~/workspace/sandbox/mysql-8.0.12

CMake Deprecation Warning at CMakeLists.txt:57 (CMAKE_POLICY):
  The OLD behavior for policy CMP0045 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.


-- Running cmake version 3.12.0
-- Configuring with MAX_INDEXES = 64U
-- CMAKE_GENERATOR: Unix Makefiles
CMake Error at cmake/os/Darwin.cmake:39 (MESSAGE):
  Clang version 8.0 is known to generate wrong code for MySQL, you should
  upgrade Xcode
Call Stack (most recent call first):
  CMakeLists.txt:251 (INCLUDE)


-- Configuring incomplete, errors occurred!
See also "/Users/morisaki/workspace/sandbox/mysql-8.0.12/build/CMakeFiles/CMakeOutput.log".

OSもHighSierraにしたしXCodeも最新にしたけどうまくいかん 😢

@masayuki14
Copy link
Owner Author

% clang -v
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

8 じゃないんだけどなぁ

@masayuki14
Copy link
Owner Author

改めて始める。
約2年ぶりかぁ。

@masayuki14
Copy link
Owner Author

今回はUbuntuVMでやってみる。

@masayuki14
Copy link
Owner Author

vagrant init bento/ubuntu-20.04 
vagrant up

ubuntu20.04でやってみる。ひさびさにvagrantつかう

@masayuki14
Copy link
Owner Author

MySQL 8.0.20 のソースコードをダウンロード
mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz を選ぶ

https://dev.mysql.com/downloads/mysql/

@masayuki14
Copy link
Owner Author

# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

@masayuki14
Copy link
Owner Author

https://dev.mysql.com/doc/refman/8.0/en/source-installation.html
ソースビルドのドキュメント

@masayuki14
Copy link
Owner Author

闇雲にやる前に5.6日本語ドキュメント読むか。
https://dev.mysql.com/doc/refman/5.6/ja/source-installation.html

@masayuki14
Copy link
Owner Author

とりあえず。

apt update
apt upgrade

@masayuki14
Copy link
Owner Author

masayuki14 commented Jun 22, 2020

ドキュメント読んで、とりあえずなんかピックアップ

the installation step installs files under /usr/local/mysql.

/usr/local/mysql にインストールされる

The component locations under the installation directory are the same as for binary distributions.
https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html#binary-installation-layout

各種ファイルはインストール先はaptとかのバイナリインストールと同じ場所
configure で変えられるけどそのままでいい

CMake でのビルド方法はこっち
https://dev.mysql.com/doc/internals/en/cmake.html

@masayuki14
Copy link
Owner Author

masayuki14 commented Jun 22, 2020

MySQL officially joined GitHub in September, 2014. For more information about MySQL's move to GitHub, refer to the announcement on the MySQL Release Engineering blog:

ソースコードはGitHubからcloneすればいいのだったー
https://github.com/mysql/mysql-server

@masayuki14
Copy link
Owner Author

https://dev.mysql.com/doc/refman/8.0/en/source-installation-prerequisites.html
ソースビルドするための要件

こんなところ。

@masayuki14
Copy link
Owner Author

一つずつインストールする

@masayuki14
Copy link
Owner Author

root@vagrant:~# apt install cmake
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-image-unsigned-5.4.0-26-generic linux-modules-5.4.0-26-generic
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  cmake-data gcc gcc-9 libasan5 libatomic1 libcc1-0 libgcc-9-dev libgomp1 libitm1 libjsoncpp1 liblsan0 libquadmath0 librhash0 libtsan0 libubsan1
Suggested packages:
  cmake-doc ninja-build gcc-multilib manpages-dev autoconf automake libtool flex bison gdb gcc-doc gcc-9-multilib gcc-9-doc gcc-9-locales
The following NEW packages will be installed:
  cmake cmake-data gcc gcc-9 libasan5 libatomic1 libcc1-0 libgcc-9-dev libgomp1 libitm1 libjsoncpp1 liblsan0 libquadmath0 librhash0 libtsan0 libubsan1
0 upgraded, 16 newly installed, 0 to remove and 0 not upgraded.
Need to get 17.4 MB of archives.
After this operation, 77.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 cmake-data all 3.16.3-1ubuntu1 [1,612 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 libjsoncpp1 amd64 1.7.4-3.1ubuntu2 [75.6 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal/main amd64 librhash0 amd64 1.3.9-1 [113 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal/main amd64 cmake amd64 3.16.3-1ubuntu1 [3,669 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal/main amd64 libcc1-0 amd64 10-20200411-0ubuntu1 [41.1 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/main amd64 libgomp1 amd64 10-20200411-0ubuntu1 [101 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal/main amd64 libitm1 amd64 10-20200411-0ubuntu1 [26.3 kB]
Get:8 http://archive.ubuntu.com/ubuntu focal/main amd64 libatomic1 amd64 10-20200411-0ubuntu1 [9,284 B]
Get:9 http://archive.ubuntu.com/ubuntu focal/main amd64 libasan5 amd64 9.3.0-10ubuntu2 [395 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal/main amd64 liblsan0 amd64 10-20200411-0ubuntu1 [144 kB]
Get:11 http://archive.ubuntu.com/ubuntu focal/main amd64 libtsan0 amd64 10-20200411-0ubuntu1 [319 kB]
Get:12 http://archive.ubuntu.com/ubuntu focal/main amd64 libubsan1 amd64 10-20200411-0ubuntu1 [136 kB]
Get:13 http://archive.ubuntu.com/ubuntu focal/main amd64 libquadmath0 amd64 10-20200411-0ubuntu1 [146 kB]
Get:14 http://archive.ubuntu.com/ubuntu focal/main amd64 libgcc-9-dev amd64 9.3.0-10ubuntu2 [2,359 kB]
Get:15 http://archive.ubuntu.com/ubuntu focal/main amd64 gcc-9 amd64 9.3.0-10ubuntu2 [8,234 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal/main amd64 gcc amd64 4:9.3.0-1ubuntu2 [5,208 B]
Fetched 17.4 MB in 7s (2,559 kB/s)
Selecting previously unselected package cmake-data.
(Reading database ... 51028 files and directories currently installed.)
Preparing to unpack .../00-cmake-data_3.16.3-1ubuntu1_all.deb ...
Unpacking cmake-data (3.16.3-1ubuntu1) ...
Selecting previously unselected package libjsoncpp1:amd64.
Preparing to unpack .../01-libjsoncpp1_1.7.4-3.1ubuntu2_amd64.deb ...
Unpacking libjsoncpp1:amd64 (1.7.4-3.1ubuntu2) ...
Selecting previously unselected package librhash0:amd64.
Preparing to unpack .../02-librhash0_1.3.9-1_amd64.deb ...
Unpacking librhash0:amd64 (1.3.9-1) ...
Selecting previously unselected package cmake.
Preparing to unpack .../03-cmake_3.16.3-1ubuntu1_amd64.deb ...
Unpacking cmake (3.16.3-1ubuntu1) ...
Selecting previously unselected package libcc1-0:amd64.
Preparing to unpack .../04-libcc1-0_10-20200411-0ubuntu1_amd64.deb ...
Unpacking libcc1-0:amd64 (10-20200411-0ubuntu1) ...
Selecting previously unselected package libgomp1:amd64.
Preparing to unpack .../05-libgomp1_10-20200411-0ubuntu1_amd64.deb ...
Unpacking libgomp1:amd64 (10-20200411-0ubuntu1) ...
Selecting previously unselected package libitm1:amd64.
Preparing to unpack .../06-libitm1_10-20200411-0ubuntu1_amd64.deb ...
Unpacking libitm1:amd64 (10-20200411-0ubuntu1) ...
Selecting previously unselected package libatomic1:amd64.
Preparing to unpack .../07-libatomic1_10-20200411-0ubuntu1_amd64.deb ...
Unpacking libatomic1:amd64 (10-20200411-0ubuntu1) ...
Selecting previously unselected package libasan5:amd64.
Preparing to unpack .../08-libasan5_9.3.0-10ubuntu2_amd64.deb ...
Unpacking libasan5:amd64 (9.3.0-10ubuntu2) ...
Selecting previously unselected package liblsan0:amd64.
Preparing to unpack .../09-liblsan0_10-20200411-0ubuntu1_amd64.deb ...
Unpacking liblsan0:amd64 (10-20200411-0ubuntu1) ...
Selecting previously unselected package libtsan0:amd64.
Preparing to unpack .../10-libtsan0_10-20200411-0ubuntu1_amd64.deb ...
Unpacking libtsan0:amd64 (10-20200411-0ubuntu1) ...
Selecting previously unselected package libubsan1:amd64.
Preparing to unpack .../11-libubsan1_10-20200411-0ubuntu1_amd64.deb ...
Unpacking libubsan1:amd64 (10-20200411-0ubuntu1) ...
Selecting previously unselected package libquadmath0:amd64.
Preparing to unpack .../12-libquadmath0_10-20200411-0ubuntu1_amd64.deb ...
Unpacking libquadmath0:amd64 (10-20200411-0ubuntu1) ...
Selecting previously unselected package libgcc-9-dev:amd64.
Preparing to unpack .../13-libgcc-9-dev_9.3.0-10ubuntu2_amd64.deb ...
Unpacking libgcc-9-dev:amd64 (9.3.0-10ubuntu2) ...
Selecting previously unselected package gcc-9.
Preparing to unpack .../14-gcc-9_9.3.0-10ubuntu2_amd64.deb ...
Unpacking gcc-9 (9.3.0-10ubuntu2) ...
Selecting previously unselected package gcc.
Preparing to unpack .../15-gcc_4%3a9.3.0-1ubuntu2_amd64.deb ...
Unpacking gcc (4:9.3.0-1ubuntu2) ...
Setting up libgomp1:amd64 (10-20200411-0ubuntu1) ...
Setting up libasan5:amd64 (9.3.0-10ubuntu2) ...
Setting up libquadmath0:amd64 (10-20200411-0ubuntu1) ...
Setting up libatomic1:amd64 (10-20200411-0ubuntu1) ...
Setting up libubsan1:amd64 (10-20200411-0ubuntu1) ...
Setting up librhash0:amd64 (1.3.9-1) ...
Setting up cmake-data (3.16.3-1ubuntu1) ...
Setting up libcc1-0:amd64 (10-20200411-0ubuntu1) ...
Setting up liblsan0:amd64 (10-20200411-0ubuntu1) ...
Setting up libitm1:amd64 (10-20200411-0ubuntu1) ...
Setting up libjsoncpp1:amd64 (1.7.4-3.1ubuntu2) ...
Setting up libtsan0:amd64 (10-20200411-0ubuntu1) ...
Setting up libgcc-9-dev:amd64 (9.3.0-10ubuntu2) ...
Setting up cmake (3.16.3-1ubuntu1) ...
Setting up gcc-9 (9.3.0-10ubuntu2) ...
Setting up gcc (4:9.3.0-1ubuntu2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9) ...
root@vagrant:~# cmake --version
cmake version 3.16.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).

@masayuki14
Copy link
Owner Author

root@vagrant:~# apt install make
Reading package lists... Done
Building dependency tree
Reading state information... Done
make is already the newest version (4.2.1-1.2).
make set to manually installed.
The following packages were automatically installed and are no longer required:
  linux-image-unsigned-5.4.0-26-generic linux-modules-5.4.0-26-generic
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

@masayuki14
Copy link
Owner Author

root@vagrant:~# apt install gcc
Reading package lists... Done
Building dependency tree
Reading state information... Done
gcc is already the newest version (4:9.3.0-1ubuntu2).
gcc set to manually installed.
The following packages were automatically installed and are no longer required:
  linux-image-unsigned-5.4.0-26-generic linux-modules-5.4.0-26-generic
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

@masayuki14
Copy link
Owner Author

root@vagrant:~# apt install openssl
Reading package lists... Done
Building dependency tree
Reading state information... Done
openssl is already the newest version (1.1.1f-1ubuntu2).
The following packages were automatically installed and are no longer required:
  linux-image-unsigned-5.4.0-26-generic linux-modules-5.4.0-26-generic
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

@masayuki14
Copy link
Owner Author

ncurses は以下のコマンド群でOKなのかな。全部はいっている

  • captoinfo, a termcap conversion tool
  • clear, utility for clearing the screen
  • infocmp, the terminfo decompiler
  • tabs, set tabs on a terminal
  • tic, the terminfo compiler
  • toe, list (table of) terminfo entries
  • tput, utility for retrieving terminal capabilities in shell scripts
  • tset, to initialize the terminal

@masayuki14
Copy link
Owner Author

# apt install bison
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-image-unsigned-5.4.0-26-generic linux-modules-5.4.0-26-generic
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  m4
Suggested packages:
  bison-doc m4-doc
The following NEW packages will be installed:
  bison m4
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 856 kB of archives.
After this operation, 2,386 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 m4 amd64 1.4.18-4 [199 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 bison amd64 2:3.5.1+dfsg-1 [657 kB]
Fetched 856 kB in 3s (332 kB/s)
Selecting previously unselected package m4.
(Reading database ... 54092 files and directories currently installed.)
Preparing to unpack .../archives/m4_1.4.18-4_amd64.deb ...
Unpacking m4 (1.4.18-4) ...
Selecting previously unselected package bison.
Preparing to unpack .../bison_2%3a3.5.1+dfsg-1_amd64.deb ...
Unpacking bison (2:3.5.1+dfsg-1) ...
Setting up m4 (1.4.18-4) ...
Setting up bison (2:3.5.1+dfsg-1) ...
update-alternatives: using /usr/bin/bison.yacc to provide /usr/bin/yacc (yacc) in auto mode
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for install-info (6.7.0.dfsg.2-5) ...

@masayuki14
Copy link
Owner Author

これでいいかしら。

@masayuki14
Copy link
Owner Author

clone する

git clone https://github.com/mysql/mysql-server.git

@masayuki14
Copy link
Owner Author

重かったからやりなおし

git clone --depth 1  https://github.com/mysql/mysql-server.git

それでもまぁまぁ重かった。

@masayuki14
Copy link
Owner Author

2.9.5 Installing MySQL Using a Development Source Tree
を見ながらビルドするぞ。

@masayuki14
Copy link
Owner Author

$ git branch
* 8.0

デフォルトで8.0になってる。

@masayuki14
Copy link
Owner Author

ビルドのドキュメントじゃなかった。
2.9.7 MySQL Source-Configuration Options

こっちでビルドオプションのことが書いてある。デバッグビルドするにはこれ見ないと行けなさそう。

@masayuki14
Copy link
Owner Author

めっちゃ長いし、めっちゃ多いので、読めそうにない。

@masayuki14
Copy link
Owner Author

debug を含むオプションを見ておく。

@masayuki14
Copy link
Owner Author

  • -DWITH_DEBUG=ON
  • -DWITH_INNODB_EXTRA_DEBUG=ON
  • -DWITH_MSCRT_DEBUG=ON
    • Whether to enable Visual Studio CRT memory leak tracing. The default is OFF.
    • VSCode でも有効になるんだろうか。

たぶんこの3つのオプションをONにしてコンパイルすればいいと思う

@masayuki14
Copy link
Owner Author

masayuki14 commented Jun 24, 2020

2.9.8 Dealing with Problems Compiling MySQL
よくある失敗と対象、的な内容

再構成するときは CMakeCache.txt. を消すべし。

@masayuki14
Copy link
Owner Author

github からソースコードおとす。

@masayuki14
Copy link
Owner Author

masayuki14 commented Jul 15, 2020

$ git clone --depth 1  https://github.com/mysql/mysql-server.git

$ cd mysql-server

$ mkdir bld

$ cd bld

$ cmake .. -DWITH_DEBUG=ON -DWITH_INNODB_EXTRA_DEBUG=ON -G Xcode -DDOWNLOAD_BOOST=1 -DWITH_BOOST=../boost

@masayuki14
Copy link
Owner Author

make しても動かない

% make
make: *** No targets specified and no makefile found.  Stop.

もしや、とおもい

xcodebuild したら動いた。

@masayuki14
Copy link
Owner Author

-G Xcode とはこういうことか。

@masayuki14
Copy link
Owner Author

まぁ Macだし結果オーライですすめるか。

@masayuki14
Copy link
Owner Author

=== BUILD AGGREGATE TARGET ALL_BUILD OF PROJECT MySQL WITH THE DEFAULT CONFIGURATION (Debug) ===

Check dependencies

Write auxiliary files
write-file /Users/morisaki/workspace/mysql-server/bld/MySQL.build/Debug/ALL_BUILD.build/Script-9B7C1DDE18B64EC795AD0A7F.sh
chmod 0755 /Users/morisaki/workspace/mysql-server/bld/MySQL.build/Debug/ALL_BUILD.build/Script-9B7C1DDE18B64EC795AD0A7F.sh

PhaseScriptExecution CMake\ Rules bld/MySQL.build/Debug/ALL_BUILD.build/Script-9B7C1DDE18B64EC795AD0A7F.sh
    cd /Users/morisaki/workspace/mysql-server
    /bin/sh -c /Users/morisaki/workspace/mysql-server/bld/MySQL.build/Debug/ALL_BUILD.build/Script-9B7C1DDE18B64EC795AD0A7F.sh
echo ""

echo Build\ all\ projects
Build all projects

** BUILD SUCCEEDED *

ビルドできた。

@masayuki14
Copy link
Owner Author

mysql-server/ じゃなくて bld/ でXcode開いた。間違った気がしたけどこれでいいぽい。
実行ファイルは bin/ じゃなくて bin/Debug にできていた。
XcodeのIndexingにはけっこう時間がかかりそう。

@masayuki14
Copy link
Owner Author

このままXcodeでもいい気がしてきた。

@masayuki14
Copy link
Owner Author

$HOME/.my.cnf を用意する。

[mysqld]
basedir=/Users/morisaki/workspace/mysql-server/bld
datadir=/Users/morisaki/workspace/mysql-server/bld/data

@masayuki14
Copy link
Owner Author

これを使って初期化する。

$ bin/Debug/mysqld --initialize --defaults-file=$HOME/.my.cnf
2020-07-17T09:51:45.239130Z 0 [System] [MY-013169] [Server] /Users/morisaki/workspace/mysql-server/bld/runtime_output_directory/Debug/mysqld (mysqld 8.0.21-debug) initializing of server in progress as process 25570
2020-07-17T09:51:45.252254Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /Users/morisaki/workspace/mysql-server/bld/data/ is case insensitive
2020-07-17T09:51:45.269045Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-17T09:51:46.141924Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-07-17T09:51:50.262690Z 0 [ERROR] [MY-000067] [Server] unknown variable 'defaults-file=/Users/morisaki/.my.cnf'.
2020-07-17T09:51:50.263686Z 0 [ERROR] [MY-013455] [Server] The newly created data directory /Users/morisaki/workspace/mysql-server/bld/data/ by --initialize is unusable. You can remove it.
2020-07-17T09:51:50.265661Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-07-17T09:51:51.870032Z 0 [System] [MY-010910] [Server] /Users/morisaki/workspace/mysql-server/bld/runtime_output_directory/Debug/mysqld: Shutdown complete (mysqld 8.0.21-debug)  Source distribution.
workspace/mysql-server/bld (git)-[8.0]%

@masayuki14
Copy link
Owner Author

うまく行ってない。けど、 datadir はつくられたっぽい?

@masayuki14
Copy link
Owner Author

data/ を消してもう一度やってみてもだめ。

unknown variable 'defaults-file=/Users/morisaki/.my.cnf' ってどういうこと!?

@masayuki14
Copy link
Owner Author

% bin/Debug/mysqld --initialize --datadir=$(pwd)/data --basedir=$(pwd)
2020-07-17T10:04:22.128238Z 0 [System] [MY-013169] [Server] /Users/morisaki/workspace/mysql-server/bld/runtime_output_directory/Debug/mysqld (mysqld 8.0.21-debug) initializing of server in progress as process 41110
2020-07-17T10:04:22.130043Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /Users/morisaki/workspace/mysql-server/bld/data/ is case insensitive
2020-07-17T10:04:22.138933Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-17T10:04:23.106722Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-07-17T10:04:26.902108Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: o*w5h=lh?F+E
2020-07-17T10:04:33.363249Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.21-debug).

初期化の時は --defaluts-file ではあかんらしい。

@masayuki14
Copy link
Owner Author

--defaults-file でいけるはずなので、どっかで調べよう。

@masayuki14
Copy link
Owner Author

masayuki14 commented Jul 17, 2020

とりあえず初期化できたので起動して接続する。

% bin/Debug/mysqld
2020-07-17T12:11:48.267784Z 0 [System] [MY-010116] [Server] /Users/morisaki/workspace/mysql-server/bld/runtime_output_directory/Debug/mysqld (mysqld 8.0.21-debug) starting as process 80160
2020-07-17T12:11:48.279476Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /Users/morisaki/workspace/mysql-server/bld/data/ is case insensitive
2020-07-17T12:11:48.298166Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-17T12:11:48.633541Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-07-17T12:11:49.565926Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock
2020-07-17T12:11:50.307248Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-07-17T12:11:50.307697Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2020-07-17T12:11:50.444757Z 0 [System] [MY-010931] [Server] /Users/morisaki/workspace/mysql-server/bld/runtime_output_directory/Debug/mysqld: ready for connections. Version: '8.0.21-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution.

basedir datadir の指定がない場合はデフォルトでビルドディレクトリが basedir になるぽい。

% bin/Debug/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21-debug

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

接続できた。

@masayuki14
Copy link
Owner Author

この mysqld をXcodeから起動すればブレイクポイントが使えるんだろうか。

@masayuki14
Copy link
Owner Author

Xcode よくわからんから cmake しなおす。

$ pwd
/Users/morisaki/workspace/mysql-server
$ mkdir bld_make
$ cd bld_make
$ cmake .. -DWITH_DEBUG=ON -DWITH_INNODB_EXTRA_DEBUG=ON -DDOWNLOAD_BOOST=1 -DWITH_BOOST=../boost
$ make -j 8 || make -j 6 || make -j 4 || make

でできる。
データベースファイルは初期化済のやつを使う。

 ./bin/mysqld --defaults-file=$HOME/.my.cnf

でOK。
クライアントからも変更後のパスワードで接続できた。

@masayuki14
Copy link
Owner Author

VSCodeにC/C++拡張を入れる。

@masayuki14
Copy link
Owner Author

launch.json の設定などはUbuntuのときと同じ。

@masayuki14
Copy link
Owner Author

            "program": "/home/masa/mysql/usr/local/mysql/bin/mysqld_safe",
            "args": ["--defaults-file=/home/masa/.my.cnf"],

で、実行するとサーバーが起動する。

@masayuki14
Copy link
Owner Author

sql/sql_parse.cc:1178 の do_command()にブレイクポイントを設定して、クライアントから select 1; を実行したら、デバッガーがちゃんと動いたので、これでソースコードの動きが見たくなったらいつでも見れるようになった。

とはいえ。さっぱりわからん。

@masayuki14
Copy link
Owner Author

人団ランク。

@masayuki14
Copy link
Owner Author

デバッグビルドするとmysql クライアントでできることがあるらしいので調べる。

@masayuki14
Copy link
Owner Author

https://dev.mysql.com/doc/refman/5.6/ja/mysql-command-options.html

  • --debug
  • --debug-check
  • --debug-info

のオプションがある。

デバッグビルドのやつ。

% ./bin/mysql --help | grep debug
  -#, --debug[=name]  Output debug log.
  --debug-check       Check memory and open file usage at exit.
  -T, --debug-info    Print some debug info at exit.
debug                             d:t:o,/tmp/mysql.trace
debug-check                       FALSE
debug-info                        FALSE

Dockerのやつだと使えない。

# mysql --help | grep debug
  -#, --debug[=#]     This is a non-debug version. Catch this and exit.
  --debug-check       This is a non-debug version. Catch this and exit.
  -T, --debug-info    This is a non-debug version. Catch this and exit.

# mysql -T
mysql: [ERROR] mysql: Option '-T' used, but is disabled

これらのオプションで何ができるのか。

@masayuki14
Copy link
Owner Author

masayuki14 commented Jul 18, 2020

  • --debug[=debug_options], -# [debug_options]

デバッグのログを書き込みます。一般的な debug_options 文字列は d:t:o,file_name です。デフォルトは d:t:o,/tmp/mysql.trace です。

  • --debug-check

プログラムの終了時に、デバッグ情報を出力します。

  • --debug-info, -T

プログラムの終了時に、デバッグ情報とメモリーおよび CPU 使用率の統計を出力します。

https://dev.mysql.com/doc/refman/5.6/ja/mysql-command-options.html#option_mysql_debug

@masayuki14
Copy link
Owner Author

masayuki14 commented Jul 18, 2020

  • --debug[=debug_options], -# [debug_options]

Write a debugging log. A typical debug_options string is d:t:o,file_name. The default is d:t:o,/tmp/mysql.trace.

This option is available only if MySQL was built using WITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.

  • --debug-check

Print some debugging information when the program exits.

This option is available only if MySQL was built using WITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.

  • --debug-info, -T
    Print debugging information and memory and CPU usage statistics when the program exits.

This option is available only if MySQL was built using WITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.

https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html#option_mysql_debug

@masayuki14
Copy link
Owner Author

masayuki14 commented Jul 18, 2020

% ./bin/mysql -T  -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.21-debug Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

mysql> ^DBye

User time 0.00, System time 0.00
                              Maximum resident set size 3612672, Integral resident set size 0
Non-physical pagefaults 1092, Physical pagefaults 7, Swaps 0
Blocks in 0 out 0, Messages in 4 out 5, Signals 0
Voluntary context switches 21, Involuntary context switches 40

最後に統計情報が出力されている。

これ

User time 0.00, System time 0.00
                              Maximum resident set size 3612672, Integral resident set size 0
Non-physical pagefaults 1092, Physical pagefaults 7, Swaps 0
Blocks in 0 out 0, Messages in 4 out 5, Signals 0
Voluntary context switches 21, Involuntary context switches 40

@masayuki14
Copy link
Owner Author

% ./bin/mysql -#  -u root -p

/tmp/mysql.trace にログがどーっと出てきた。

@masayuki14
Copy link
Owner Author

接続切ると統計情報も出力された。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant