mysql

OpenHalo 内核,提供 MySQL 协议与语法兼容能力

mysql 配置模板使用 OpenHalo 数据库内核替代原生 PostgreSQL,提供 MySQL 线缆协议与 SQL 语法兼容能力。


配置概览

  • 配置名称: mysql
  • 节点数量: 单节点
  • 配置说明:OpenHalo MySQL 兼容内核配置
  • 适用系统:el8, el9
  • 适用架构:x86_64
  • 相关配置:meta

启用方式:

./configure -c mysql [-i <primary_ip>]

配置内容

源文件地址:pigsty/conf/mysql.yml

all:
  children:
    infra: { hosts: { 10.10.10.10: { infra_seq: 1 }} ,vars: { repo_enabled: false }}
    etcd:  { hosts: { 10.10.10.10: { etcd_seq: 1  }} ,vars: { etcd_cluster: etcd  }}

    #----------------------------------------------#
    # OpenHalo MySQL Compatible Cluster
    #----------------------------------------------#
    pg-meta:
      hosts:
        10.10.10.10: { pg_seq: 1, pg_role: primary }
      vars:
        pg_cluster: pg-meta
        pg_users:
          - {name: dbuser_meta ,password: DBUser.Meta   ,pgbouncer: true ,roles: [dbrole_admin]    ,comment: pigsty admin user }
          - {name: dbuser_view ,password: DBUser.Viewer ,pgbouncer: true ,roles: [dbrole_readonly] ,comment: read-only viewer }
        pg_databases:
          - {name: meta ,baseline: cmdb.sql ,comment: pigsty meta database ,schemas: [pigsty]}
        pg_hba_rules:
          - {user: dbuser_view , db: all ,addr: infra ,auth: pwd ,title: 'allow grafana access'}
        node_crontab: [ '00 01 * * * postgres /pg/bin/pg-backup full' ]

        # OpenHalo 专用配置
        pg_mode: mysql                    # MySQL 兼容模式
        pg_packages: [ openhalo, pgsql-common ]  # 安装 OpenHalo 内核
        pg_default_services:              # MySQL 端口 3306 服务路由
          - { name: primary ,port: 5433 ,dest: 3306  ,check: /primary   ,selector: "[]" }
          - { name: replica ,port: 5434 ,dest: 3306  ,check: /read-only ,selector: "[]" , backup: "[? pg_role == `primary` || pg_role == `offline` ]" }
          - { name: default ,port: 5436 ,dest: postgres ,check: /primary   ,selector: "[]" }
          - { name: offline ,port: 5438 ,dest: postgres ,check: /replica   ,selector: "[? pg_role == `offline` || pg_offline_query ]" , backup: "[? pg_role == `replica` && !pg_offline_query]" }

  vars:
    version: v4.0.0
    admin_ip: 10.10.10.10
    region: default
    infra_portal:
      home : { domain: i.pigsty }

    nodename_overwrite: false
    node_repo_modules: node,infra,pgsql
    node_tune: oltp

    pg_version: 14                      # OpenHalo 基于 PostgreSQL 14
    pg_conf: oltp.yml

    #----------------------------------------------#
    # PASSWORD
    #----------------------------------------------#
    grafana_admin_password: pigsty
    grafana_view_password: DBUser.Viewer
    pg_admin_password: DBUser.DBA
    pg_monitor_password: DBUser.Monitor
    pg_replication_password: DBUser.Replicator
    patroni_password: Patroni.API
    haproxy_admin_password: pigsty
    minio_secret_key: S3User.MinIO
    etcd_root_password: Etcd.Root

配置解读

mysql 模板使用 OpenHalo 内核,让您可以使用 MySQL 客户端工具连接 PostgreSQL。

关键特性

  • 使用 MySQL 协议(端口 3306),兼容 MySQL 客户端
  • 支持 MySQL SQL 语法子集
  • 保留 PostgreSQL 的 ACID 特性和存储引擎
  • 同时支持 PostgreSQL 和 MySQL 两种协议连接

连接方式

# 使用 MySQL 客户端
mysql -h 10.10.10.10 -P 3306 -u dbuser_meta -pDBUser.Meta

# 同时保留 PostgreSQL 连接能力
psql postgres://dbuser_meta:DBUser.Meta@10.10.10.10:5432/meta

适用场景

  • 从 MySQL 迁移到 PostgreSQL
  • 需要同时支持 MySQL 和 PostgreSQL 客户端的应用
  • 希望利用 PostgreSQL 生态同时保持 MySQL 兼容性

注意事项

  • OpenHalo 基于 PostgreSQL 14,不支持更高版本特性
  • 部分 MySQL 语法可能存在兼容性差异
  • 仅支持 EL8/EL9 系统
  • 不支持 ARM64 架构

最后修改 2025-12-21: udpate conf structure (2cd7d6e)