MySQL 源码阅读 —— 问题 CMake:SSL version must be at least 1.1.1

问题描述

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
/Users/jioby/Applications/CLion.app/Contents/bin/cmake/mac/aarch64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/Users/jioby/Applications/CLion.app/Contents/bin/ninja/mac/aarch64/ninja -DWITH_DEBUG=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=boost -DDOWNLOAD_BOOST_TIMEOUT=60000 -DCMAKE_INSTALL_PREFIX=build_out -DMYSQL_DATADIR=build_out/data -DSYSCONFDIR=build_out/etc -DMYSQL_TCP_PORT=3307 -DMYSQL_UNIX_ADDR=mysql-debug.sock -G Ninja -S /Users/jioby/code/mysql-annotated-5.7.35 -B /Users/jioby/code/mysql-annotated-5.7.35/cmake-build-debug
CMake Deprecation Warning at CMakeLists.txt:30 (CMAKE_MINIMUM_REQUIRED):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

···

-- suffixes <.a;.so;.dylib;.tbd>
-- OPENSSL_INCLUDE_DIR = /opt/homebrew/include
-- OPENSSL_LIBRARY = /opt/homebrew/lib/libssl.a
-- CRYPTO_LIBRARY = /opt/homebrew/lib/libcrypto.a
-- OPENSSL_MAJOR_VERSION = 
-- OPENSSL_MINOR_VERSION = 
-- OPENSSL_FIX_VERSION = 
CMake Error at cmake/ssl.cmake:247 (MESSAGE):
  SSL version must be at least 1.1.1
Call Stack (most recent call first):
  CMakeLists.txt:568 (MYSQL_CHECK_SSL)


-- Configuring incomplete, errors occurred!

Homebrew 安装指定版本的三种方式

方式一:官方多版本 formula

以 MySQL 为例

先搜索软件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
brew search mysql
```shell

```shell
==> Formulae
automysqlbackup          mysql-client             mysql-sandbox            mysql@5.7 ✔
mysql                    mysql-client@5.7         mysql-search-replace     mysqltuner
mysql++                  mysql-connector-c++      mysql@5.6                qt-mysql

==> Casks
mysql-connector-python            mysqlworkbench                    sqlpro-for-mysql
mysql-shell                       navicat-for-mysql

发现可用的版本有 mysqlmysql@5.7mysql@5.6,那么我们可以安装的就是这几个大版本:

1
brew install mysql@5.7

缺点:多数软件是没有提供历史版本专属 formula,且每个都是大版本、无法具体版本号。

macOS Big Sur 解决系统文件不可修改

起因

本是为了删除 macOS 11.4 自带的 PHP,经历了一下步骤:

  • 先关闭 SIP
1
csrutil disable
  • 再删除 PHP 相关文件
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
cd /private/etc/ && sudo rm -rf php-fpm.conf.defaultphp.ini php.ini.default

cd /usr/bin/ && sudo rm -rf php php-config phpdoc phpize

cd /usr/include && sudo rm -rf php  // 10.14之后没有此目录

cd /usr/lib && sudo rm -rf php

cd /usr/sbin && sudo rm -rf php-fpm

cd /usr/share && sudo rm -rf php

cd /usr/share/man/man1 && sudo rm -rf php-config.1 php.1 phpize.1

cd /usr/share/man/man8 && sudo rm -rf php-fpm.8

Mac 开光指南 [2023.03.01更新]

💻 一份新 macOS 快速食用方法,普适新 Mac 或重装系统。 本指南基于 MBP 14寸 12.5 系统(主)和 MBP 13寸 11.4 系统。 系统和软件的更新频繁,本项目不一定及时更新,故操

分析解决本地开发 Java 项目启动速度慢

启动日志

以下是个 Spring Boot 项目启动日志(已刨除无关部分)

1
2
3
4
5
...
10:30:10.110 INFO  [background-preinit] org.hibernate.validator.internal.util.Version --- HV000001: Hibernate Validator 5.4.1.Final
10:30:15.135 WARN  [main] org.springframework.boot.StartupInfoLogger --- InetAddress.getLocalHost().getHostName() took 5001 milliseconds to respond. Please verify your network configuration (macOS machines may need to add entries to /etc/hosts).
10:30:20.142 INFO  [main] com.example.test.Application --- Starting Application on jioby.local with PID 67279 (/XXX/target/classes started by jioby in /XXX)
...

原因分析

上述日志均有个特点,每个涉及 DNS 解析的都会花费 5 秒钟左右。

然后根据日志提示,看看 InetAddress.getLocalHost() 需要执行多久:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import java.net.InetAddress;

public class Demo {

    public static void main(String[] args) {
        System.out.printf("Start: %tT%n", System.currentTimeMillis());
        try {
            System.out.println(InetAddress.getLocalHost());
            System.out.printf("Mid: %tT%n", System.currentTimeMillis());
            System.out.println(InetAddress.getLocalHost());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        System.out.printf("End: %tT%n", System.currentTimeMillis());
    }
}

输出结果:

1
2
3
4
5
Start: 17:27:58
jioby.local/192.168.131.48
Mid: 17:28:03
jioby.local/192.168.131.48
End: 17:28:08

如何不靠运气致富

美国风险投资家 Naval Ravikant 有一个很有名的长推特,一共40条,题目叫做《如何致富,不靠运气》,谈了他的商业观。

Naval Ravikant 后来还有一篇长文,详细解释这些观点。

中文版翻译

以下为和菜头翻译的中文版

  1. Seek wealth, not money or status. Wealth is having assets that earn while you sleep. Money is how we transfer time and wealth. Status is your place in the social hierarchy.

    去寻求财富,而非金钱或地位。财富就是你拥有资产,而资产在你睡觉的时候都还在为你赚钱;金钱是我们转换时间和财富的工具;身份是你在社会等级体系里所处的位置。

  2. Understand that ethical wealth creation is possible. If you secretly despise wealth, it will elude you.

    要明白一件事:一个人完全可以不靠坑蒙拐骗站着赚取财富。如果你在暗中鄙视财富,那么财富也会躲着你。

  3. Ignore people playing status games. They gain status by attacking people playing wealth creation games.

    别去理会那些热衷于玩身份游戏的人,他们通过攻击那些创造财富的人以获得自己的身份。

MySQL 源码阅读 —— macOS VSCode 编译调试 MySQL 5.7

最开始用的 CLion,但电脑扛不住,最终换成 VSCode,世界瞬间清净了😁

macOS + CLion 版本看 这里

环境

  • macOS Big Sur 11.5.2
  • VSCode 1.59.1
  • MySQL 5.7.35

依赖

如果以下软件未安装或版本不符合,使用 brew 安装即可

  • CMake
  • g++
  • openssl 1.1

VSCode 插件

在 VSCode 应用商店搜索并安装以下插件

  • C/C++
  • C/C++ Clang Command Adapter
  • CodeLLDB
  • CMake Tools

MySQL 源码阅读 —— 问题 expanded from macro MYSQL_VERSION_MAJOR

问题描述

在执行 make 构建时可能会报错

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Building C object storage/myisam/CMakeFiles/myisam.dir/mi_rfirst.c.o
In file included from /path/to/mysql-5.7.35/storage/perfschema/cursor_by_account.cc:28:
In file included from /path/to/mysql-5.7.35/include/my_global.h:57:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/math.h:309:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/type_traits:417:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/cstddef:37:
/path/to/mysql-5.7.35/version:1:1: error: expected unqualified-id
MYSQL_VERSION_MAJOR=5
^
/path/to/mysql-5.7.35/include/my_config.h:404:29: note: expanded from macro 'MYSQL_VERSION_MAJOR'
#define MYSQL_VERSION_MAJOR 5
                            ^

MySQL 源码阅读 —— macOS CLion 编译调试 MySQL 5.7

macOS + VSCode 版本看这里

环境信息

  • macOS Big Sur 11.5.2
  • CLion 2021.2
  • MySQL 5.7.35
  • CMake 3.21.1
  • openssl 1.1

2024.06 更新环境

  • macOS Sonama 14.5
  • CLion 2024.1
  • MySQL 5.7.35
  • CMake 3.28.1
  • openssl 1.1.1w

下载源码

官网下载携带 boost 版本源码

下载链接:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.35.tar.gz

也可以从 GitHub 上克隆代码,切换到指定 TAG 或分支。