FreeSWITCH 简单图形化界面30 - 使用MYODBC时可能遇到的错误

FreeSWITCH 简单图形化界面30 - 使用MYODBC时可能遇到的错误

  • 测试环境
  • [1、 MYODBC 3.51.18 or higher](#1、 MYODBC 3.51.18 or higher)
  • 2、分析和解决
    • [2.1 解决1,降级MySQL ODBC](#2.1 解决1,降级MySQL ODBC)
    • [2.2 解决2,修改FreeSWITCH代码](#2.2 解决2,修改FreeSWITCH代码)

测试环境

http://myfs.f3322.net:8020/

用户名:admin,密码:admin

FreeSWITCH界面安装参考:https://blog.csdn.net/jia198810/article/details/137820796

1、 MYODBC 3.51.18 or higher

在编译FreeSWITCH,支持ODBC的时候,启动的时候,可能会遇到以下问题:

bash 复制代码
2020-06-11 07:30:48.559653 [DEBUG] sofia.c:3158 Creating agent for default
2020-06-11 07:30:48.559653 [ERR] switch_odbc.c:522 ERR: [delete from sip_registrations where sub_host is null and hostname='betelgeuse_web_serice1' and network_ip like '%' and network_port like '%' and sip_username like '%' and mwi_user  like '%' and mwi_host like '%' and orig_server_host like '%' and orig_hostname like '%';delete from sip_registrations where sub_host is null and hostname='betelgeuse_web_serice1' and network_ip like '%' and network_port like '%' and sip_username like '%' and mwi_user  like '%' and mwi_host like '%' and orig_server_host like '%' and orig_hostname like '%']
[STATE: 42000 CODE 1064 ERROR: [MySQL][ODBC 8.0(a) Driver][mysqld-8.0.16]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 'delete from sip_registrations where sub_host is null and hostname='betelgeuse_we' at line 1
]
2020-06-11 07:30:48.559653 [ERR] switch_core_sqldb.c:732 [db="ASTPP";type="odbc"user="astpp_odbc";pass="Iuv4_wuHjU6cqMFXn4Hm"] ODBC SQL ERR [STATE: 42000 CODE 1064 ERROR: [MySQL][ODBC 8.0(a) Driver][mysqld-8.0.16]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 'delete from sip_registrations where sub_host is null and hostname='betelgeuse_we' at line 1
]
delete from sip_registrations where sub_host is null and hostname='betelgeuse_web_serice1' and network_ip like '%' and network_port like '%' and sip_username like '%' and mwi_user  like '%' and mwi_host like '%' and orig_server_host like '%' and orig_hostname like '%';delete from sip_registrations where sub_host is null and hostname='betelgeuse_web_serice1' and network_ip like '%' and network_port like '%' and sip_username like '%' and mwi_user  like '%' and mwi_host like '%' and orig_server_host like '%' and orig_hostname like '%'
2020-06-11 07:30:48.559653 [CRIT] sofia_glue.c:2625 GREAT SCOTT!!! Cannot execute batched statements! [STATE: 42000 CODE 1064 ERROR: [MySQL][ODBC 8.0(a) Driver][mysqld-8.0.16]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 'delete from sip_registrations where sub_host is null and hostname='betelgeuse_we' at line 1
]
If you are using mysql, make sure you are using MYODBC 3.51.18 or higher and enable FLAG_MULTI_STATEMENTS
2020-06-11 07:30:48.559653 [CRIT] sofia.c:3161 Cannot Open SQL Database [default]!

2、分析和解决

这是因为可能使用高版本的MySQL ODBC版本所致。

FreeSWITCH 需要 MySQL ODBC 支持批处理,即能够一次性执行多个 SQL 语句(通过分号分隔多个SQL语句)。MySQL ODBC 5.x 版本支持通过在 /etc/odbc.ini 中设置 option=67108864 来启用批处理。FreeSWITCH 可以通过 SQLPrepare() 和 SQLExecute() 执行批处理。但是,MySQL ODBC 8.x 之后的版本不支持 option 这个选项,而是可以通过 SQLExecDirect() 来执行多个 SQL 语句。

MySQL ODBC 官网描述如下:

2.1 解决1,降级MySQL ODBC

要在选定的系统上编译 MySQL ODBC 5.x 版本,并通过设置启动选项 option=67108864 来启用批处理功能。

当前(2024年10月26日)MySQL 官网提供的版本为 mysql-connector-odbc-5.3.13-src.tar.gz。您可以从此链接下载源码包:mysql-connector-odbc-5.3.13-src.tar.gz。下载后,解压并按照官方文档指示进行编译和安装。安装完成后,可以通过在连接字符串中添加 option=67108864 来启用批处理。

编译后生成libmyodbc5w.so模块,/etc/odbc.ini配置文件使用该模块。

bash 复制代码
# /etc/odbc.ini
[freeswitch]
DRIVER   = /usr/lib64/libmyodbc5w.so
SERVER   = localhost
PORT     = 3306
DATABASE = freeswitch
USER     = user
PASSWORD = 123456
OPTION   = 67108864
Socket   = /var/run/mysqld/mysqld.sock
CHARSET  = utf8mb4

2.2 解决2,修改FreeSWITCH代码

科技在发展,时代在进步,不可能一直用MySQL ODBC 5.x,目前MySQL ODBC都到9.x版本了,有的新版操作系统,可能也无法编译MySQL ODBC 5.x,会各种兼容报错,因此只能选用新版本的MySQL ODBC。

如果我们可以使用MySQL8.x,使用MySQL ODBC8.x,那么需要修改一下FreeSWITCH的代码,让其使用SQLExecDirect() 执行SQL。

MySQL ODBC8.x的库为libmyodbc8w.so,/etc/odbc.ini使用此库

修改的FreeSWITCH文件是,源码目录下的src/switch_odbc.c,修改如下图:

重新编译FreeSWITCH可执行文件和库,安装即可。

bash 复制代码
make
make install

再次启动查看是否还有上面的报错。

祝君好运

相关推荐
野生的码农19 小时前
放过自己,降低预期,及时行乐
android·ai编程
huwuhang20 小时前
索尼PS3游戏合集【中文游戏】8.12T 1430个游戏+PS3模拟器
android·游戏·智能手机·游戏机·电视
杨云龙UP21 小时前
mysqldump逻辑备份文件恢复总结:全库恢复、单库恢复,一篇讲明白
linux·运维·服务器·数据库·mysql·adb
ybwycx21 小时前
mysql重置root密码(适用于5.7和8.0)
数据库·mysql·adb
Grackers1 天前
Android Perfetto 系列 5:Android App 基于 Choreographer 的渲染流程
android
踩着两条虫1 天前
AI驱动的Vue3应用开发平台深入探究(十):物料系统之内置组件库
android·前端·vue.js·人工智能·低代码·系统架构·rxjava
sam.li1 天前
JADX MCP 原理与使用部署
android·逆向·jadx
冬奇Lab1 天前
Android 15音频子系统(五):AudioPolicyService策略管理深度解析
android·音视频开发·源码阅读
亚历克斯神1 天前
Flutter for OpenHarmony: Flutter 三方库 mutex 为鸿蒙异步任务提供可靠的临界资源互斥锁(并发安全基石)
android·数据库·安全·flutter·华为·harmonyos
dalancon1 天前
SurfaceControl 的事务提交给 SurfaceFlinger,以及 SurfaceFlinger 如何将这些数据设置到对应 Layer 的完整流程
android