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
搜了一下, 很多人都碰上这个问题啊, 共同点是: 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.