今天在测试 nodeJs 项目与阿里云 RDS 服务中的 mysql 数据库的通信遇到了以下的问题
ER_SPECIFIC_ACCESS_DENIED_ERROR: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
经常大半天的折腾终于找出了问题的所在地方,今天做下记录,以便以后遇到相同问题时可供参考,问题是出在连接数据库时设置了时区的关系,如下是原来的连接代码。
export const dbClient = require('knex')({ client: 'mysql', connection: { host: mysqlDBHost, database: mysqlDBName.p4p, user: mysqlDBUser, password: mysqlDBPass } pool: { min: 2, max: 10, afterCreate: function (conn, done) { // in this example we use pg driver's connection API conn.query('set global time_zone = "+8:00";', function (err) { if (err) { // first query failed, return error and don't try to make next query done(err, conn); } else { // do the second query... conn.query('select curtime();', function (err, data) { // if err is not falsy, connection is discarded from pool // if connection aquire was triggered by a query the error is passed to query promise // console.log('query', data); done(err, conn); }); } }); } } });
只要将时区的设置去掉就恢复正常的了
export const dbClient = require('knex')({ client: 'mysql', connection: { host: mysqlDBHost, database: mysqlDBName.p4p, user: mysqlDBUser, password: mysqlDBPass } pool: { min: 2, max: 10 } });
转载请注明:隨習筆記 » NodeJs笔记:阿里云RDS-mysql数据库时报错