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

Reading Time: < 1 minute

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",
};

      
    


About the author

Andrés Canavesi
Andrés Canavesi

Software Engineer with 15+ experience in software development, specialized in Salesforce, Java and Node.js.


Join 22 other subscribers

Leave a Reply

Discover more from javaniceday.com

Subscribe now to keep reading and get access to the full archive.

Continue reading