使用node.js连接mysql数据库,提示dyld: Symbol not found: _mysql_init
发布于 13 年前 作者 mackjoner 9137 次浏览 最后一次编辑是 8 年前

node:0.6.17

mysql:5.5.21

os:lion 10.7.3

var
  //sys = require('sys'),
  mysql = require('/Users/mackjoner/tech/nodejs/node_modules/mysql-libmysqlclient'),
  conn,
  result,
  row,
  rows;

var
  host = "localhost",
  user = "test",
  password = "password",
  database = "db",
  test_table = "users";

conn = mysql.createConnectionSync();
conn.connectSync(host, user, password, database);

//sys.puts("Information:");
//sys.puts(sys.inspect(conn.getInfoSync()) + "\n");

if (!conn.connectedSync()) {
  //sys.puts("Connection error " + conn.connectErrno + ": " + conn.connectError);
  console.log("Connection error " + conn.connectErrno + ": " + conn.connectError);
  process.exit(1);
}

conn.query("SELECT * FROM " + test_table + ";", function (err, res) {
  if (err) {
    throw err;
  }
  
  res.fetchAll(function (err, rows) {
    if (err) {
      throw err;
    }
    
    //sys.puts("Rows in table '" + database + "." + test_table + "':");
    //sys.puts(sys.inspect(rows));
    console.log("Rows in table '" + database + "." + test_table + "':");
    
    // This isn't necessary since v1.2.0
    // See https://github.com/Sannis/node-mysql-libmysqlclient/issues#issue/60
    //res.freeSync();
  });
});

process.on('exit', function () {
  conn.closeSync();
});

提示信息

dyld: lazy symbol binding failed: Symbol not found: _mysql_init
  Referenced from: /Users/yangzhaojie/tech/nodejs/node_modules/mysql-libmysqlclient/build/Release/mysql_bindings.node
  Expected in: flat namespace

dyld: Symbol not found: _mysql_init
  Referenced from: /Users/yangzhaojie/tech/nodejs/node_modules/mysql-libmysqlclient/build/Release/mysql_bindings.node
  Expected in: flat namespace
7 回复

markup

配置环境变量

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

搜了一下, 很多人都碰上这个问题啊, 共同点是: MacOS X 系统上安装MySQL

一下为原文: 大概意思是,你可能装了跟CPU的bit不一致的MySQL版本. 比如你的Mac是64-bit的,你却装了一个32-bit的MySQL… 希望能给你一点帮助… Hi,

Sorry to hear you’re having troubles, but from a quick google it seems like you’re not the only one: http://www.perlmonks.org/?node_id=793727 http://stackoverflow.com/questions/13342…ow-leopard

The general problem seems to be a 32-bit / 64-bit mismatch between MySQL and Perl…

Okay, as you’re installing the 10.6 package of MySQL i’m guessing you’re on Snow Leopard? Does your mac have a 64-bit processor in it (see here for details)?

Then, once you have established whether you should be running 32-bit or 64-bit code (match to your processor), completely remove MySQL from your system, install the appropriate one (I’m guessing you’ll probably need the 64-bit one), then reinstall DBD::MySQL.

Let me know how you get on.

是的,问题就是这个mysql32和64的区别,要和cpu对应。 设置环境变量是 Error: Unable to load shared library 解决这个错误

人类已经无法阻止cnodejs被XSS了!

这个是因为mysql需要的一些库没有在正确的位置, 一楼给的方案可以解决该问题, 最完美的方案是将需要的库安装到指定位置

回到顶部