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

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

祝君好运

相关推荐
openinstall全渠道统计2 小时前
免填邀请码工具:赋能六大核心场景,重构App增长新模型
android·ios·harmonyos
双鱼大猫3 小时前
一句话说透Android里面的ServiceManager的注册服务
android
双鱼大猫3 小时前
一句话说透Android里面的查找服务
android
双鱼大猫3 小时前
一句话说透Android里面的SystemServer进程的作用
android
双鱼大猫3 小时前
一句话说透Android里面的View的绘制流程和实现原理
android
双鱼大猫4 小时前
一句话说透Android里面的Window的内部机制
android
双鱼大猫4 小时前
一句话说透Android里面的为什么要设计Window?
android
双鱼大猫4 小时前
一句话说透Android里面的主线程创建时机,frameworks层面分析
android
苏金标5 小时前
android 快速定位当前页面
android
雾里看山8 小时前
【MySQL】内置函数
android·数据库·mysql