我正在尝试使用MySQL和Knex进行数据库迁移。错误:拒绝访问用户'''localhost'(使用密码:否)
当我运行命令knex migrate:latest
,我得到
ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO)
我试过的代码库添加密码(以“123”和“NO”),但什么我最困惑的是,正如我在我的数据库文件user: "root"
,错误给出了一个空字符串作为用户...
我分享我想象什么是相关文件:
// mysql_db.js
const knex = require('knex')({
client: 'mysql',
connection: {
host: 'localhost',
user: 'root',
password: '',
database: 'SQL_Data',
},
});
module.exports = knex;
// knexfile.js
const path = require('path');
module.exports = {
development: {
client: 'mysql',
connection: {
filename: '/server/SQL/mysql_db',
},
migrations: {
directory: path.join(__dirname, '/server/SQL/migrations'),
},
seeds: {
directory: path.join(__dirname, '/server/SQL/seeds'),
},
},
};
//knex.js
const environment = proces.env.NODE_ENV || 'development';
const config = require('../../knexfile.js')[environment];
module.exports = require(knex)('config');
// “迁移定义”
exports.up = (knex, Promise) => knex.schema.createTable('sql_table', ((table) => {
table.increments();
table.string('name').notNullable();
table.string('email').notNullable();
table.string('description').notNullable();
table.string('url').otNullable();
}));
exports.down = (knex, Promise) => knex.schema.dropTable('sql_table');
http://perkframework.com/v1/guides/database -migrations-knex.html – Hackerman