XiaoMi / Gaea

Gaea is a mysql proxy, it's developed by xiaomi b2c-dev team.
Apache License 2.0
2.62k stars 423 forks source link

dc connection handshake failed with mysql #212

Open dongzl opened 2 years ago

dongzl commented 2 years ago

本地启动 Gaea OK,启动后使用 mycli 连接报如下错误:

(1105, 'unknown error: dc connection handshake failed with mysql')

mycli 连接:

mycli -h0.0.0.0 -utest -p1234 -P13306 db_kingshard

配置:

{
    "name": "test_kingshard_hash",
    "online": true,
    "read_only": false,
    "allowed_dbs": {
        "db_kingshard": true
    },
    "default_phy_dbs": {
        "db_kingshard": "db_kingshard"
    },
    "slow_sql_time": "1000",
    "black_sql": [
        ""
    ],
    "allowed_ip": null,
    "slices": [
        {
            "name": "slice-0",
            "user_name": "root",
            "password": "123456",
            "master": "127.0.0.1:3307",
            "slaves": [],
            "statistic_slaves": null,
            "capacity": 12,
            "max_capacity": 24,
            "idle_timeout": 60
        }
    ],
    "shard_rules": [
        {
            "db": "db_kingshard",
            "table": "shard_hash",
            "type": "hash",
            "key": "id",
            "locations": [
                2
            ],
            "slices": [
                "slice-0"
            ]
        }
    ],
    "users": [
        {
            "user_name": "test",
            "password": "1234",
            "namespace": "test_kingshard_hash",
            "rw_flag": 2,
            "rw_split": 1,
            "other_property": 0
        }
    ],
    "default_slice": "slice-0",
    "global_sequences": null
}
xiyangxixian commented 2 years ago

这个需要检查一下,后端数据库连接是否有权限连上呢

dongzl commented 2 years ago

这个需要检查一下,后端数据库连接是否有权限连上呢

你好,感谢回复,后端数据库没有问题,可以直接连接,我这里只有一个库,不分库只分表,不知道上面的配置是否有问题?

doubility commented 2 years ago

换个有主从配置的数据库

Leadrive commented 2 years ago

可能是mysql连接数不够造成的,增加max_connections

hokyoDan commented 2 years ago

我也遇到这个问题了,请问这个问题解决了吗

julianzlzhang commented 1 year ago

我也遇到这个问题,日志显示: [2023-06-03 21:15:15] [gaea_proxy] [Julian-M1-Pro.local] [WARN] [900000001] [github.com/XiaoMi/Gaea/proxy/server.(Session).Handshake:session.go:138] handleHandshakeResponse error, connId: 10005, err: ERROR 1045 (28000): Access denied for user 'admin'@'127.0.0.1:62258' (using password: Yes) [2023-06-03 21:15:15] [gaea_proxy] [Julian-M1-Pro.local] [WARN] [900000001] [github.com/XiaoMi/Gaea/proxy/server.(Server).onConn:server.go:128] [server] onConn error: ERROR 1045 (28000): Access denied for user 'admin'@'127.0.0.1:62258' (using password: Yes) [2023-06-03 21:17:20] [gaea_proxy] [Julian-M1-Pro.local] [WARN] [900000001] [github.com/XiaoMi/Gaea/backend.(Slice).GetConn:slice.go:84] get connection from slave failed, try to get from master, error: dc connection handshake failed with mysql [2023-06-03 21:17:20] [gaea_proxy] [Julian-M1-Pro.local] [WARN] [900000001] [github.com/XiaoMi/Gaea/backend.(Slice).GetConn:slice.go:92] get connection from backend failed, error: dc connection handshake failed with mysql [2023-06-03 21:17:20] [gaea_proxy] [Julian-M1-Pro.local] [WARN] [900000001] [github.com/XiaoMi/Gaea/proxy/server.(SessionExecutor).ExecuteSQL:executor.go:796] getUnShardConns failed: dc connection handshake failed with mysql [2023-06-03 21:17:20] [gaea_proxy] [Julian-M1-Pro.local] [WARN] [900000001] [github.com/XiaoMi/Gaea/proxy/server.(SessionExecutor).doQuery:executor_handle.go:107] execute select: dc connection handshake failed with mysql [2023-06-03 21:17:20] [gaea_proxy] [Julian-M1-Pro.local] [WARN] [900000001] [github.com/XiaoMi/Gaea/proxy/server.(*Manager).RecordSessionSQLMetrics:manager.go:333] session error SQL, namespace: test_namespace_1, sql: select @@version_comment limit 1, cost: 33 ms, err: dc connection handshake failed with mysql 这里'admin'@'127.0.0.1:62258'是个啥?也没有用admin用户呀。

Yinogi commented 1 year ago

有同样的问题,我有两个namespace,一个后端数据库是5.6,另一个是5.7,都是单个服务没有主从,通过代理访问的时候5.6的报错了,writeHandshakeResponse41()执行完之后收到后端的响应头代码是ErrHeader(255),报错同1楼 后端5.7版本的数据库无任何问题,怀疑是版本兼容问题,本人golang不熟对MySQL协议研究也不深,楼主可以参考升级数据库,希望开发者能验证并确认下是否是版本兼容的问题

Yinogi commented 1 year ago

图片 抓包看了下然后去查了下,网上说应该是版本兼容问题,但是不用代理可以直连,估计是代理的版本支持问题,不确定,希望有大佬指教 MySQL server 版本5.6.50

Switch-vov commented 11 months ago

我这边是8.0.22版本。打了断点看了下,MySQL报错Client does not support authentication protocol requested by server; consider upgrading MySQL client

因为MySQL8.0之后,PLUGIN_AUTH默认是caching_sha2_password。 我把PLUGIN_AUTH改成mysql_native_password就能正常访问了。

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
ryeLearnMore commented 2 weeks ago

我也遇到了这个问题。但是应用接入后,只是偶尔报这种错,并不是直接拦截。看上面说是版本问题,那我这种零星报这种错误是什么原因呢?