Egg.js开发实录一

215 阅读1分钟
配置egg-mysql

根据官网上的教程进行配置即可,中间碰到一些配置问题,简单记录一下

1.配置plugin.js
  module.exports = {
      mysql:{
        enable: true,
        package: 'egg-mysql'
      }
    };
2.配置config.default.js
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1723703655578_6282';

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  exports.mysql = {
    // 单数据库信息配置
    client: {
      // host
      host: '127.0.0.1',
      // 端口号
      port: '3306',
      // 用户名
      user: 'root',
      // 密码
      password: 'root',
      // 数据库名
      database: 'loving_data'
    },
    // 是否加载到 app 上,默认开启
    app: true,
    // 是否加载到 agent 上,默认关闭
    agent: false
  };

  return {
    ...config,
    ...userConfig,
  };
};

3.关于Client does not support authentication protocol requested by server; consider upgrading MySQL client报错的问题

客户端不支持服务器请求的身份验证协议;考虑升级MySQL客户端。 这个问题的mysql8.0和navicat16上,是加密方式导致的,需要将mysql的加密方式改成mysql_native_password 通过mysql8.0的Command line Client进入,输入一下代码,密码为本地链接的密码,'root'为本机账户

alter user 'root'@'localhost' identified with mysql_native_password by '密码';