Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server

knex


Sep 07, 2021
featured image
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
      
-- to deal with ER_NOT_SUPPORTED_AUTH_MODE error. Only run this line for local dev
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';


-- create our main user for local dev
CREATE USER IF NOT EXISTS 'my_user'@'%' IDENTIFIED BY 'root';

CREATE DATABASE IF NOT EXISTS `test_container` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON test_container.* TO 'my_user'@'%'  WITH GRANT OPTION;
flush privileges;

      
    
Update client to mysql2
      
require("dotenv-safe").config({ allowEmptyValues: false });

module.exports = {
  client: "mysql2",
  version: process.env.MYSQL_VERSION || "8",
  connection: {
    host: process.env.MYSQL_HOST,
    user: process.env.MYSQL_USERNAME,
    password: process.env.MYSQL_PASSWORD,
    database: process.env.MYSQL_DATABASE,
    port: process.env.MYSQL_PORT || 3306,
  },
  migrations: {
    extension: "ts",
    directory: "./migrations",
  },
  debug: process.env.LOG_LEVEL === "debug",
};

      
    

knex mysql mysql2 dev