Reputation: 11
So .. i know this might be a dumb question because it was asked and answered before but i really wanna understand everything about it.
Currently i use docker
to build a website. In my docker-compose
i have 2 services: mysqldb
and node
(which is the api).
Now.. in order to connect to my sql database using api, it takes some time so that MySql can be started up.. For that i use an execute.sh
script that makes me able to run it manually. Beside that i have a db_schema.js
that i run manually and it creates the tables in database.
That's how i connect:
const mysql = require('mysql');
const connection = mysql.createConnection({
host: "mysqldb",
user: "root",
password: "password",
database: "database",
});
connection.connect();
let createScoresTable = "CREATE TABLE IF NOT EXISTS scores (" +
"team_a VARCHAR(100) NOT NULL," +
"team_a_score INT UNSIGNED NOT NULL," +
"team_b_score INT UNSIGNED NOT NULL," +
"team_b VARCHAR(100)" +
")"
connection.query(createScoresTable)
connection.end();
But as the title says, i have problem with authentication.
I know that i can do this manually by entering in database and running an ALTER
command, but it's not so comfortable to run it everytime with every docker-compose down
i execute..
My question is how can i fix that without using ALTER
?
Thanks in advance.
Upvotes: 1
Views: 386
Reputation: 10757
You need to add the following to your MYSQL service in docker-compose:
command: --default-authentication-plugin=mysql_native_password
Upvotes: 1