MySQL 和 PostgreSQL 都是非常成熟的开源数据库产品,各自都有着非常成熟的生态体系。PostgreSQL 在可扩展性上优势明显,且采用 PostgreSQL 开源协议,而 MySQL 采用双轨并行的开源许可,局限性大,这是诸多数国产数据库厂商选择基于 PostgreSQL 进行二次开发或者再自研的根本原因。放眼全球,我们很难找到能将 MySQL 和 PostgreSQL 各自优势融为一体的开源数据库产品。openHalo 横空出世,宛如一把“倚天剑”,斩断了 PostgreSQL 与 MySQL 之间的兼容壁垒。
openHalo 是一款基于 PostgreSQL 的开源数据库,通过在内核层面实现 MySQL 协议和语法的兼容,为用户提供了一个同时具备 PostgreSQL 强大功能和 MySQL 简洁易用性的数据库解决方案。2025 年 4 月 1 日,openHalo 正式发布并开源,填补了国际上 PostgreSQL 兼容 MySQL 的空白。
openHalo 的核心设计目标:
1. 内核级兼容
openHalo 直接在 PostgreSQL 内核中实现 MySQL 协议和语法,避免了扩展插件或应用层兼容的性能损耗。运行一个数据库,可以同时提供 PostgreSQL 和 MySQL 两种模式。
2. 功能完整性
完整支持 MySQL 协议,支持 MySQL 的核心特性,如数据类型、SQL 语法、客户端类库等,MySQL 生态工具可直接作用于 openHalo 数据库。
3. 高性能
利用 PostgreSQL 的优化器和存储引擎,提供比 MySQL 更高的性能,尤其在处理复杂 SQL 方面。
4. 平滑迁移
MySQL 应用可以平滑迁移到 openHalo,显著降低迁移成本。从 MySQL 转向 openHalo 的学习成本也降低很多。
PostgreSQL 优良的扩展插件模块设计为兼容异构数据库提供了极大便利,PG 社区除了文章开头提及的 Nextgres 项目,还有另外一种方案。基于 PostgreSQL 的 Citus 集群通过 mysql_fdw 扩展实现 MySQL 兼容,支持数据分片,突破单机性能局限。但这种方案劣势也很明显,要求在 PostgreSQL 侧创建分片表,并映射到 MySQL 中的表,用户在 Citus 主节点上运行查询,该方案性能损耗大,功能覆盖有限。
./configure --prefix=/home/shawnyan/openhalo-1.0 --enable-debug --with-uuid=ossp --with-icu --with-extra-version="-ShawnYan" make && make install cd contrib make && make install
[shawnyan@oc9 ~]$ initdb The files belonging to this database system will be owned by user "shawnyan". This user must also own the server process. The database cluster will be initialized with locale "en_US.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. creating directory /home/shawnyan/data ... ok ... Success. You can now start the database server using: pg_ctl -D /home/shawnyan/data -l logfile start [shawnyan@oc9 ~]$
[shawnyan@oc9 ~]$ diff data/postgresql.conf data/postgresql.conf.org 59c59 < listen_addresses = '*'# what IP address(es) to listen on; --- > #listen_addresses = 'localhost' # what IP address(es) to listen on; 66c66 < unix_socket_directories = '/home/shawnyan/data'# comma-separated list of directories --- > unix_socket_directories = '/var/run/openhalo'# comma-separated list of directories 820d819 < include 'openhalo.mysql.conf'
这里只是方便演示修改几个必要参数,其他配置项这里不多做说明。
5.5. 启动 openHalo
与 PostgreSQL 启动方式一致,通过 pg_ctl 拉起 openHalo 数据库。
[shawnyan@oc9 ~]$ pg_ctl start waiting for server to start....2025-04-01 20:31:14.825 CST [22034] LOG: redirecting log output to logging collector process 2025-04-01 20:31:14.825 CST [22034] HINT: Future log output will appear in directory "diag". done server started
连接到 openHalo 数据库,查看版本信息。
[shawnyan@oc9 ~]$ psql psql (1.0.14.10-ShawnYan) Type "help"forhelp. halo0root=# select version(); version -------------------------------------------------------------------------------------------------------------------------------------------------- openHalo 1.0.14.10-ShawnYan on x86_64-pc-linux-gnu, compiled by gcc (Tencent Compiler 12.3.1.3) 12.3.1 20230912 (OpenCloudOS 12.3.1.3-1), 64-bit (1 row)
到此,openHalo 在 OC 系统上的安装已经完成,接下来我们一起来了解 openHalo 的 MySQL 模式。
06. openHalo 的 MySQL 模式
6.1. 初始化 MySQL 模式
通过 psql 客户端连接到 openHalo,创建 aux_mysql 扩展,初始化 MySQL 模式。
[shawnyan@oc9 ~]$ psql psql (1.0.14.10-ShawnYan) Type "help"forhelp. halo0root=# CREATE EXTENSION aux_mysql CASCADE; NOTICE: installing required extension "uuid-ossp" CREATE EXTENSION halo0root=# \dx List of installed extensions Name | Version | Schema | Description -----------+---------+------------+------------------------------------------------- aux_mysql | 1.4 | public | MySQL Supplementary Extension plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language uuid-ossp | 1.1 | public | generate universally unique identifiers (UUIDs) (3 rows)
通过 MySQL 客户端连接到 openHalo,并查看版本信息。
[shawnyan@oc9 ~]$ mysql -h 127.1 -P 3307 -u shawnyan Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.7.32-log MySQL Server (GPL) Copyright (c) 2000, 2025, Oracle and/or its affiliates. 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'forhelp. Type '\c' to clear the current input statement. mysql> select version(); +-----------------+ | version | +-----------------+ | 5.7.99-shawnyan | +-----------------+ 1 row inset (0.00 sec) mysql> select name,setting,boot_val from pg_settings where name ~ 'mysql_version'; +--------------------------+-----------------+------------+ | name | setting | boot_val | +--------------------------+-----------------+------------+ | mysql.halo_mysql_version | 5.7.99-shawnyan | 5.7.32-log | +--------------------------+-----------------+------------+ 1 row inset (0.00 sec)
创建一张测试表,其中一个字段指定默认值为 unix_timestamp(),这在 MySQL 中会报错,但是在 MariaDB 和 openHalo 中是支持的。
MySQL
mysql> select version(); +-----------+ | version() | +-----------+ | 5.7.32 | +-----------+ 1 row inset (0.00 sec) mysql> CREATE TABLE t ( -> id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ct bigint(20) DEFAULT unix_timestamp() -> ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unix_timestamp() )' at line 3
halo0root=# set password_encryption='mysql_native_password'; SET halo0root=# create user mytest superuser password 'mytest'; CREATE ROLE halo0root=# select * from pg_shadow where usename = 'mytest'; -[ RECORD 1 ]+--------------------------------------------------------------- usename | mytest usesysid | 20793 usecreatedb | f usesuper | t userepl | f usebypassrls | f passwd | mysql_native_password:58f4612c3598d20a3c51a37d7b2643bf15806832 valuntil | useconfig |
在配置文件 pg_hba.conf 中添加访问许可,并重载配置。
echo"host all all samenet md5" >> $PGDATA/pg_hba.conf pg_ctl reload
使用 MySQL 客户端以用户 mytest 连接 openHalo。
[shawnyan@oc9 ~]$ mysql -h 192.168.43.90 -P 3307 -u mytest -p mydb -e 'table hello_openhalo;' Enter password: +------------------+ | a | +------------------+ | Hello, openHalo! | +------------------+
openHalo 的用法和注意事项就先介绍到这里。
未来与展望
openHalo 的设计理念以及行动力是值得称赞的,也标志着开源数据库正提速迈进“深度融合时代”。openHalo 刚刚开源,尚有很多不足之处,比如对 MySQL 的存储过程、分区表等功能的兼容性不足,官方文档尚不完善,欢迎各界大佬来“Halo 吐槽群”畅聊。当前版本的 openHalo 基于 PostgreSQL 14,希望下一个大版本可以升级到基于 PostgreSQL 16-18。openHalo 在 PostgreSQL 和 MySQL 融合方面还可以做出更多探索,比如 MySQL 模式下直接调用 DuckDB,提速数据分析。最后,期待有更多人了解 openHalo,使用 openHalo,共同参与 openHalo 开源项目。
Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。
Sublime Text
Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。