我使用来自XAMPP的OSX 10.6.8和MySQL。
当我运行node.js应用程序(app.js)时:
var mysql = require('mysql-libmysqlclient');
var conn = mysql.createConnectionSync();
conn.connectSync('127.0.0.1', 'root', '', 'database_name');
我看到这个输出:
Airs0urce:nodejs airs0urce$ node app.js
dyld: lazy symbol binding failed: Symbol not found: _mysql_init
Referenced from: /Applications/XAMPP/xamppfiles/htdocs/myproject/nodejs/node_modules/mysql-libmysqlclient/build/Release/mysql_bindings.node
Expected in: dynamic lookup
dyld: Symbol not found: _mysql_init
Referenced from: /Applications/XAMPP/xamppfiles/htdocs/myproject/nodejs/node_modules/mysql-libmysqlclient/build/Release/mysql_bindings.node
Expected in: dynamic lookup
Trace/BPT trap
在谷歌搜索之后已经尝试了一些解决方案。
从XAMPP目录添加mysql libs以包含以下路径:
export DYLD_LIBRARY_PATH=/Applications/XAMPP/xamppfiles/lib/mysql:$DYLD_LIBRARY_PATH
尝试使用MacPorts安装
mysql5-devel
,但运气不佳,生成失败:Airs0urce:~ airs0urce$ sudo port install mysql5-devel
---> Computing dependencies for mysql5-devel
---> Building mysql5-devel
Error: Target org.macports.build returned: shell command failed (see log for details)
Log for mysql5-devel is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_mysql5-devel/mysql5-devel/main.log
Error: Status 1 encountered during processing.
To report a bug, see <http://guide.macports.org/#project.tickets>
如果要查看,则有日志文件:http://dl.dropbox.com/u/1875424/main.log
最佳答案
这是因为Mac OS X Lion(10.7):lib/libmysqlclient.18.dylib
(mysql 5.5及以上版本)上的配置问题。
步骤1:
确保在~/.profile
中设置路径
export ARCHFLAGS=-arch x86_64
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
步骤2:
我使用的是rvm,所以,我使用了以下命令:
rvmsudo ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config --with-opt-lib=/usr/local/mysql/lib
它解决了Mac lion和mysql x86_64上rails应用程序的问题。
关于mysql - 从node.js应用程序连接到mysql,错误:“dyld:惰性符号绑定(bind)失败:找不到符号:_mysql_init”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8156024/