简体   繁体   中英

Connect to mysql from node.js app, error: “dyld: lazy symbol binding failed: Symbol not found: _mysql_init”

I use OSX 10.6.8 and MySQL from XAMPP.

When I run this node.js app (app.js):

var mysql = require('mysql-libmysqlclient');
var conn = mysql.createConnectionSync();
conn.connectSync('127.0.0.1', 'root', '', 'database_name');

I see this output:

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

Already tried couple solutions after googling. Added mysql libs from XAMPP directory to include path this way:

export DYLD_LIBRARY_PATH=/Applications/XAMPP/xamppfiles/lib/mysql:$DYLD_LIBRARY_PATH

tried to install mysql5-devel using MacPorts, but no luck, building failed:

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>

There is log file if you want to see: http://dl.dropbox.com/u/1875424/main.log

This is because of a config issue on Mac OS X Lion (10.7): lib/libmysqlclient.18.dylib (mysql 5.5 and above).

Step 1:

Make sure you set the path in ~/.profile

export ARCHFLAGS=-arch x86_64
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

Step 2:

I am using rvm so, I used the following command:

rvmsudo ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config --with-opt-lib=/usr/local/mysql/lib 

which has solved the issues with rails application on Mac lion and mysql x86_64.

I futzed around with this for a ton of time including setting the DVLD library path and copying the library into /usr/lib.

sudo cp /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib

Heck, anything to get it working. Finally I tried clearing the default for 64 vs 32 bit and it worked!

defaults delete com.apple.versioner.perl

Not sure if my perl is 64 or 32 bit, but my db is 64 bit and just using the default default seems to work better ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM