Tag: mysql

c9.io – 如何find在node.js平台上build立mysql连接的主机地址

我正尝试在Cloud 9 Server中托pipe我的node.js应用程序。 为了build立一个mysql连接,我需要知道主机地址。 这页在一个非常荒谬的说法(我认为我是对的)的方式: Hostname $IP The same local IP as the application you run on Cloud9 但是我从哪里获得本地IP? 没有在文档中find它。 任何想法 ? 编辑:我使用127.0.0.1,0.0.0.0(在回答中build议在terminalecho $IP )和hostname -I和curl curlmyip.com在terminal的值。 4个不同的IP地址。 没有工作。

续集join非主键

我有两张桌子我需要关联。 表A有一个表B。 我可以在TableA模型中做到这一点: TableA.hasOne( models.TableB, { as: 'TableB', foreignKey: 'someID' } ); 看着SQL,它试图joinTableA.ID和TableB.someID。 我真正想要的是joinTableA.someNonPrimaryKey和TableB.someID。 我怎么能说sequelizejoin一些NonPrimaryKey?

无法使用mysql和节点js返回select查询值

我在节点js新,现在我想设置一个返回值select查询在mysql中使用节点js ….我正在使用node-mysql包… 示例代码 var mysql = require('mysql'); var connection = mysql.createConnection({ host : "localhost", user : "root", password: "root123", database: "testdb" }); var retValue = undefined; var query = connection.query('SELECT * FROM tblData;'); query .on('error', function(err) { // Handle error, an 'end' event will be emitted after this as well }) .on('fields', function(fields) { // […]

MySQLjoin,ORDER BY RAND()然后sortingASC(最好使用Sequelize)

我想帮助这个MySQL查询。 理想情况下,我会使用node.js Sequelize ORM生成它。 这些表格是: Questions: id, question Answers: id, question_id, answer 我的续集代码是: models.questions.findAll({ where: { id: { $notIn: not_in } }, order: [['id','ASC'], [models.answers, 'id', 'ASC']], attributes: ['id', 'question'], include: [{ model: models.answers, attributes: ['id', 'question_id', 'answer'], }] }) 将not_in设置为-1 ,Sequelize会生成以下查询: SELECT `questions`.`id`, `questions`.`question`, `answers`.`id` AS `answers.id`, `answers`.`question_id` AS `answers.question_id`, `answers`.`answer` AS `answers.answer` FROM […]

NodeJS + Mysql与Docker组合2

我正在尝试构build一个docker-compose文件来在本地部署连接到mysql服务器的NodeJS应用程序。 我已经尝试了一切(阅读了很多教程和一些问题在这里在Stackoverflow),但我不断收到ECONNREFUSED错误。 这是来自NodeJS的Dockerfile: ##Nodejs FROM node:latest RUN useradd –user-group –create-home –shell /bin/false app ENV HOME=/home/app COPY package.json npm-shrinkwrap.json $HOME/playerground/ RUN chown -R app:app $HOME/* USER app WORKDIR $HOME/playerground RUN npm cache clean && npm install –silent –progress=false USER root COPY . $HOME/playerground RUN chown -R app:app $HOME/* USER app 这是我的Mysql Dockerfile: FROM mysql:latest ENV MYSQL_ROOT_PASSWORD […]

什么是最好的Node.js MySQL模块连接到MySQL通过SSL?

我已经使用node-mysql构build了我的应用程序。 我只使用AWS RDS服务设置了一个安全可访问的mysql数据库,并已经成功地通过mysql命令行客户端testing了一个SSL连接。 我有亚马逊的公钥.pem文件。 node-mysql似乎没有SSL连接选项的api。 到目前为止,我发现的唯一一个是Node-mysql-libmysqlclient,但是我尝试连接它时出现了错误,关于绑定依赖项为null,所以我不确定是否应该信任它。 build议使用哪个模块/ api? 另外,如果你知道我需要在node-mysql中修改什么,我会愿意修补一下,但它看起来像使用较低级别的套接字来连接到MySQL,所以我不知道有多难,得到已添加SSL部分。

错误:ER_BAD_FIELD_ERROR:节点js中“字段列表”中的未知列“asd123”

当我尝试在phpmyadmin中更新表时收到此错误 谁能告诉我什么是错的请 这是桌子 create table ms_registereduser(userID Varchar(10),socketID Varchar(255)); 这是我的server.js var http = require("http"); var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', user : 'root', password : '', database : 'pushnotificationdb' }); var userID = "1234567890", socketID = "asd123"; http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }).listen(1111); connection.connect(); connection.query('callpushnotificationdb.spUpdateSocketID('+userID+','+socketID+');').on('end',function() { console.log('User […]

严重错误后节点JS Mysql协议ENQUEUE

错误的含义是什么? 此代码在我的testing文件中工作。 function handleDisconnect() { objConn = mysql.createConnection(db_config); // Recreate the connection, since // the old one cannot be reused. objConn.connect(function(err) { // The server is either down if(err) { // or restarting (takes a while sometimes). console.log('error when connecting to db:', err.code); setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect, }else{ […]

Sequelize:如何映射数据透视表中的自定义属性

我有这个数据透视表,它代表了与模型Person和Movie的多对多关系。 事情是,当我打电话给那些关联人的电影时,我想得到这个angular色。 我尝试过,但没有显示angular色: models.Movie.findAll({ include: [{ model: models.Person, as: 'persons', through: {attributes: ["role"]} }] }).then(function(movies) { res.json(movies); }); 我是否必须在role的模型中指定某些内容?

如何使用node.js将csv文件导入到mysql?

现在我正在尝试图书馆fast-csv这样做: var stream = fs.createReadStream("./google.csv"); csv .fromStream(stream, {headers : ["Name","E-mail 1 – Value"], ignoreEmpty: true}) .on("data", function(data){ console.log(data); }) .on("end", function(){ console.log("done"); }); 但它会抛出这个错误:“列标题不匹配预期:2列得到:57” 你知道我怎么能避免这种情况? 我应该使用不同的库/方法吗? 我面临的另一个问题是,我得到的结果是hex的…我怎样才能正确parsing它?