我正在嘗試使用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