im getting the error on docker:
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251
sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client',
sqlState: '08004'
Im trying to send data from client to server, from server to mysql db
and see it using phpAdmin.
It looks like that the datawas successfully sent to the server from the client,
but not sent from the server to the db.
There is no data in the table after send it.
I think the problem is something with the env but I dont get it...
docker-compose.yml
version: "3.9"
x-common-variables: &common-variables
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: shimshon
MYSQL_HOST_IP: localhost
REACT_APP_SERVER_PORT: 3001
services:
mysql:
image: mysql:8.0
restart: unless-stopped
command: --default-authentication-plugin=mysql_native_password
environment:
<<: *common-variables
MYSQL_HOST: mysql
ports:
- 3306:3306
volumes:
- ./db/sample.sql:/docker-entrypoint-initdb.d/sample.sql
phpmyadmin:
depends_on:
- mysql
image: phpmyadmin/phpmyadmin
environment:
<<: *common-variables
PMA_HOST: mysql
links:
- mysql:mysql
ports:
- 8080:80
restart: always
server:
build: ./server
depends_on:
- mysql
expose:
- 3001
environment:
<<: *common-variables
MYSQL_HOST_IP: mysql
ports:
- 3001:3001
volumes:
- ./server:/app
links:
- mysql
command: npm run devStart
client:
build: ./client
environment:
<<: *common-variables
NODE_PATH: src
expose:
- 3000
ports:
- 3000:3000
volumes:
- ./client/src:/app/src
links:
- server
command: npm start
server.js:
...
const db = mysql.createConnection({
host: process.env.MYSQL_HOST_IP,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_ROOT_PASSWORD,
database: process.env.MYSQL_DATABASE,
port : 3306
});
...
Related
I have been trying to setup docker-compose for my application written in flask and connect it to msql database. Both containers are seems to be working fine and aplication starts properrly, but whenever there is any request to database, I am getting following error from my flask-app comtainer:
sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)")
For me it looks like my containers don't see each other. I am new to Docker, but I thought that my current docker-compose should work
version: '3.9'
networks:
backend:
volumes:
mysqldb:
services:
app:
restart: "no"
container_name: flask-app
build:
context: ./AEH_PAP
dockerfile: ./Dockerfile
ports:
- "9000:9000"
networks:
- backend
environment:
DATABASE_URI: mysql://user:password#db:9000/library3
links:
- 'db'
depends_on:
- db
volumes:
- /var/lib/mysql/mysql.sock:/mysql.sock
db:
container_name: mysql-db
image: "mysql:8.0.31"
ports:
- '3307:3306'
restart: "no"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: library3
MYSQL_USER: user
MYSQL_PASSWORD: password
volumes:
- "mysqldb:/var/lib/mysql"
- "./init.sql:/docker-entrypoint-initdb.d/init.sql"
networks:
- backend
mysql-db logs
flask-app logs
Also I have been trying to connect to mysql-db container from flask-app container with command mysql --host localhost --port 3306 -u user -p but still getting the same error.
My Docker knowledge is very limited but should I have msql server installed also on flask-app?
I have this docker-compose file:
version: "3"
services:
mariadb:
image: mariadb:latest
container_name: mariadb
command: --default-authentication-plugin=mysql_native_password
restart: unless-stopped
env_file: .env
volumes:
- db-data:/var/lib/mysql
networks:
- internal
drupal:
image: drupal:9.3.9-fpm-alpine
container_name: drupal
depends_on:
- mariadb
restart: unless-stopped
networks:
- internal
- external
volumes:
- /var/www/html/:/var/www/html/
webserver:
image: nginx:latest
container_name: webserver
depends_on:
- drupal
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- /var/www/html/:/var/www/html/
- ./nginx-conf:/etc/nginx/conf.d
networks:
- external
networks:
external:
driver: bridge
internal:
driver: bridge
volumes:
db-data:
I run docker-compose up -d and everything works fine, but I can not access to the mariadb server from host, I tried these
# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
# mysql -uroot -p -h mariadb
Enter password:
ERROR 2005 (HY000): Unknown MySQL server host 'mariadb' (-2)
# mysql -uroot -p -h 127.0.0.1
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)
Edit:
.env file:
MYSQL_ROOT_PASSWORD=abc1234
MYSQL_DATABASE=my_db
MYSQL_USER=drupal
MYSQL_PASSWORD=cdf1234
From MariaDB Docker Library documentation;
One of MARIADB_ROOT_PASSWORD, MARIADB_ALLOW_EMPTY_ROOT_PASSWORD, or
MARIADB_RANDOM_ROOT_PASSWORD (or equivalents, including *_FILE), is
required. The other environment variables are optional.
This is for the initialization of the db-data volume. Once initialized, these environment variables are optional.
I'm trying to reproduce a MAMP environment with Docker-Compose, but I can't connect the phpmyadmin service to my mariaDB database!
I have done a lot of testing, and nothing has been conclusive, at best phpmyadmin does not recognize user and password and I get the following message:
mysqli_real_connect(): (HY000/1045): Access denied for user 'root'#'172.25.0.3' (using password: YES)
Here is the docker-compose file:
version: '3'
services:
php-apache:
build:
context: ./php-apache
container_name: cbx-webserver
ports:
- 80:80 # Le port dédié à ce service
restart: always
volumes:
- ./DocumentRoot:/var/www/html
links:
- mariadb
mariadb:
image: mariadb:10.1
container_name: db-mysql
ports:
- 3306:3306
restart: always
volumes:
- ./mariadb:/docker-entrypoint-initdb.d/
- mariadb:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_ROOT_USER: root
MYSQL_HOST: mariadb
MYSQL_DATABASE: mydb
myadmin:
image: phpmyadmin/phpmyadmin:4.8.1
container_name: cbx-phpmyadmin
ports:
- 8081:80
restart: always
links:
- mariadb:mysql
environment:
PMA_HOST: mydb
PMA_PORT: 3306
PMA_USER: root
PMA_PASSWORD: root
depends_on:
- mariadb
volumes:
mariadb:
and the actual error message
I'm trying to connect to my running Docker SQL database on my machine through Sequel Pro, unfortunately appears that connecting to it is failing/isn't possible through this method?
My docker-compose.yml file is:
version: "3.7"
services:
app:
build:
args:
user: user
uid: 1000
context: ./
dockerfile: Dockerfile
image: brand
container_name: brand-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- brand
db:
image: mysql:5.7
container_name: brand-db
restart: unless-stopped
ports:
- 3306:3306
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./docker-compose/mysql:/docker-entrypoint-initdb.d
networks:
- brand
nginx:
image: nginx:alpine
container_name: brand-nginx
restart: unless-stopped
ports:
- 8000:80
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d/
networks:
- brand
networks:
brand:
driver: bridge
And I'm trying to connect using:
127.0.0.1
root
root
port 3306
which appears to fail... not sure how to connect
I've got docker-compose up running, and my containers are all running
I encounter this question too.
the why of dealing with this problem is to change your database_host to the name you had given in docker-compose.yml
for example:
this.connection = mysql.createConnection({
host: 'db' || '127.0.0.1',
user: 'root',
password: '123',
database: 'CHIRINOS',
port: 3306
});
here db in host is your database name of docker container
This solution fixed the issue for me.
Looks like Sail uses MySQL 8 by default, which means that you won't be able to use Sequel Pro with Sail. You can try using nightly builds or try Sequel Ace - Sequel Pro's fork.
This is the source of the solution
I'm trying to connect to my mysql database using official adminer and mysql images from docker hub.
Here is my docker-compose.yml file configuration:
version: '3'
services:
mysql:
image: mysql
restart: always
volumes:
- mysql:/var/lib/mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD= 1
- MYSQL_DATABASE= db
ports:
- 3306:3306
- 33060:33060
adminer:
image: adminer
restart: always
ports:
- 8080:8080
depends_on:
- mysql
volumes:
mysql:
Whenever I want to login to the MySQL using Adminer I face with the following problem:
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
SQLSTATE[HY000] [2002] No such file or directory
Here is the inputs I've used trying to connect to MySQL from Adminer interface:
#first try
System: MySQL
Server: localhost
Username: root
Database: db
#second try
System: MySQL
Server: mysql #container-name
Username: root
Database: db
You have to add the default authentication plugin in compose file
command: --default-authentication-plugin=mysql_native_password
Here is the complete docker-compose.yml
services:
mysql:
image: mysql
restart: always
command: --default-authentication-plugin=mysql_native_password
volumes:
- mysql:/var/lib/mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD= 1
- MYSQL_DATABASE= db
ports:
- 3306:3306
- 33060:33060
adminer:
image: adminer
restart: always
ports:
- 8080:8080
depends_on:
- mysql
volumes:
mysql:
In adminer
System: MySQL <DB System to connect>
Server: mysql <should match the starting tag before image tag > (in your case mysql but you can change it to any name )
Username: root <username>
Password: <password>
Database: db <database name>