现在的位置: 首页 > 综合 > 正文

数据库无法创建触发器,无法识别到mysql的一些函数–解决过程

2018年04月14日 ⁄ 综合 ⁄ 共 3260字 ⁄ 字号 评论关闭

如果让TCSQL从MySQL同步数据需要编译安装三个MySQL UDF函数扩展

json、urlencode、http_post
查看数据库,
Show create function json_object,发现此函数不存在,说明函数扩展没有安装
一,安装:
wget http://mirrors.xoyo.com/xoyo/tcsql/mysql_to_tcsql_udf.tar.gz
tar zxvf mysql_to_tcsql_udf.tar.gz
cd mysql_to_tcsql_udf/lib_mysqludf_json/
make
make install
cd ../lib_mysqludf_urlencode/
echo "/usr/local/webserver/mysql/lib/mysql/" > /etc/ld.so.conf.d/mysql.Conf
/sbin/ldconfig
./configure --prefix=/usr/local/webserver/mysql/lib/mysql/plugin/ --with-mysq=/usr/local/webserver/mysql --with-mysql_config=/usr/local/webserver/mysql/bin/mysql_config --with-mysql-include=/usr/local/webserver/mysql/include
make && make install
cp -f /usr/local/webserver/mysql/lib/mysql/plugin/lib/* /usr/local/webserver/mysql/lib/mysql/plugin/
make
make install
cd ../lib_mysqludf_http_post/
make
make install
查看 函数是否存在
show create function json_array;
show create function json_members;
show create function json_object;
show create function json_values;
show create function http_post;
show create function urlencode;

 
drop function lib_mysqludf_json_info;
drop function json_array;
drop function json_members;
drop function json_object;
drop function json_values;
drop function http_post;
drop function urlencode;

创建函数
create function lib_mysqludf_json_info returns string soname 'lib_mysqludf_json.so';
create function json_array returns string soname 'lib_mysqludf_json.so';
create function json_members returns string soname 'lib_mysqludf_json.so';
create function      returns string soname 'lib_mysqludf_json.so';
create function json_values returns string soname 'lib_mysqludf_json.so';
create function http_post returns string soname 'lib_http_post.so';
create function urlencode returns string soname 'libmysqludf_urlencode.so';
如果均显示ok,证明已创建成功
具体事项参看宴哥博客http://blog.s135.com/tcsql/

二,虽然函数创建成功,但开发人员测试后,发现总是报错
测试方法:
SELECT http_get('http://m.baidu.com/s?word=xoyo&pn=0'); 
SELECT http_post('http://m.baidu.com/s','word=xoyo&pn=0');
错误:
ERROR 1123 (HY000): Can't initialize function 'http_post'; Wrong arguments to ht
无法初始化http_post
很是头疼,头疼。。。。mysql找不到这个函数啊。。
函数是有了,但是没法调用,看到宴哥博客,需要安装Mysql-udf-http客户端

http://blog.s135.com/mysql-udf-http/

Mysql-udf-http 是一款简单的MySQL用户自定义函数(UDF, User-Defined Functions),具有http_get()、http_post()、http_put()、http_delete()四个函数,可以在 MySQL数据库中利用HTTP协议进行REST相关操作。
安装过程:
ulimit -SHn 65535
wget http://curl.haxx.se/download/curl-7.21.1.tar.gz
tar zxvf curl-7.21.1.tar.gz
cd curl-7.21.1/
./configure --prefix=/usr
make && make install
cd ../

echo "/usr/local/webserver/mysql/lib/mysql/" > /etc/ld.so.conf.d/mysql.conf
/sbin/ldconfig
wget http://mysql-udf-http.googlecode.com/files/mysql-udf-http-1.0.tar.gz
tar zxvf mysql-udf-http-1.0.tar.gz
cd mysql-udf-http-1.0/
./configure--prefix=/usr/local/webserver/mysql--with-mysql=/usr/local/webserver/mysql/bin/mysql_ config

编译时提示找不到libcurl
安装:yum install libcurl*

make && make install
cd ../
创建自定义函数
进程mysql
drop function http_post;
create function http_get returns string soname 'mysql-udf-http.so';
create function http_post returns string soname 'mysql-udf-http.so'; 
create function http_put returns string soname 'mysql-udf-http.so';
create function http_delete returns string soname 'mysql-udf-http.so';
三,测试:SELECT http_post('http://m.baidu.com/s','word=xoyo&pn=0');发现问题依然,查看mysql的函数位置:
show variables like '%plugin%';
显示是在/usr/local/webserver/mysql/lib/mysql/plugin
进入该目录,发现并没有mysql-udf-http.so,回退上级目录,发现mysql-udf-http.so.0.0.0在lib/      下,将其拷贝到plugin下,并做软链接
Ln –s mysql-udf-http.so.0.0.0 mysql-udf-http.so

重新进入mysql,测试成功。

抱歉!评论已关闭.