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

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

祝君好运

相关推荐
yuanManGan20 小时前
走进Linux的世界:初识操作系统(Operator System)
android·linux·运维
叶羽西20 小时前
Android15跟踪函数调用关系
android
消失的旧时光-19431 天前
webView 的canGoBack/goBack 回退栈
android·webview
SHEN_ZIYUAN1 天前
Flow 责任链模式图解
android
沐怡旸1 天前
【底层机制】LeakCanary深度解析:从对象监控到内存泄漏分析的完整技术体系
android·面试
又菜又爱coding1 天前
Android + Flutter打包出来的APK体积太大
android·flutter
LiuYaoheng1 天前
【Android】Drawable 基础
android·java
Jerry1 天前
构建 Compose 界面
android
Y多了个想法1 天前
Linux驱动开发与Android驱动开发
android·linux·驱动开发
2501_916007471 天前
从零开始学习iOS App开发:Xcode、Swift和发布到App Store完整教程
android·学习·ios·小程序·uni-app·iphone·xcode