Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ngs/839181 to your computer and use it in GitHub Desktop.
Save ngs/839181 to your computer and use it in GitHub Desktop.
[Sequelize](http://sequelizejs.com/) を使ってアプリを作っているのですが、どうしても、日本語がうまく入りません。

Sequelize は、mysql-native をドライバとして採用しており、こちらをそのまま、以下の様にシンプルに叩いてみても、やはり文字化けします。

https://gist.github.com/839181.js?file=test-mysql-native.js

別のモジュールで、node-mysql を使うとうまくいきます。

https://gist.github.com/839181.js?file=test-mysql.js

参考までに DDL です。

https://gist.github.com/839181.js?file=schema.sql

Sequelize のコードに手を入れるべきか、mysql-native のコードに手を入れるべきか、もし、正しい解決方法をご存知の方がいらっしゃいましたらご教示ください。

CREATE TABLE `test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(256),
`text` text,
`createdAt` datetime,
`updatedAt` datetime,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
#!/usr/bin/env node
var db = require("mysql-native").createTCPClient();
db.auto_prepare = true;
db.auth("test", "root", null);
db.query("INSERT INTO test (title, text, createdAt, updatedAt) VALUES ('あああ','本日は晴天なり','2011-02-23 02:04:59','2011-02-23 02:04:59')");
db.close();
#!/usr/bin/env node
var Client = require('mysql').Client,
client = new Client();
client.user = 'root';
client.connect();
client.query("USE test");
client.query("INSERT INTO test (title, text, createdAt, updatedAt) VALUES ('あああ','本日は晴天なり','2011-02-23 02:04:59','2011-02-23 02:04:59')");
client.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment