I use docker compose to run mysql and api server. Once api server is on it use connect to mysql, but I always got a access denied. I have add sql to grant permission but it still not work. Please someone help me.
Error
2018-05-03T05:48:45.868146Z 2 [Note] Access denied for user 'mysql'#'172.18.0.3' (using password: YES)
Here is my docker-compose
version: "3.6"
services:
mysql:
build:
context: ..
dockerfile: docker/Dockerfile-mysql
image: test_mysql:ci-label
container_name: test-mysql-ci-label
labels:
- "CI-TEST=ci-label"
networks:
- ci-network
ports:
- "3306:3306"
license:
build:
context: ..
dockerfile: docker/Dockerfile
image: test_license:ci-label
container_name: test-license-ci-label
environment:
- NODE_ENV=dockertest
- PORT=9502
labels:
- "CI-TEST=ci-label"
networks:
- ci-network
ports:
- "9502:9502"
depends_on:
- mysql
privileged: true
networks:
ci-network:
labels:
- "CI-TEST=ci-label"
name: ci-network
Here is my Dockerfile-mysql
FROM mysql:5.7
LABEL CI-TEST="ci-label"
ENV MYSQL_ALLOW_EMPTY_PASSWORD=yes
MYSQL_USER=mysql \
MYSQL_PASSWORD=test
COPY init.sql docker-entrypoint-initdb.d/01.sql
Here is init.sql
-- Create database.
CREATE SCHEMA IF NOT EXISTS `license` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
-- Create new user.
GRANT ALL PRIVILEGES ON license.* TO 'mysql'#'%' IDENTIFIED BY 'test';
GRANT ALL PRIVILEGES ON license.* TO 'mysql'#'localhost' IDENTIFIED BY 'test';
FLUSH PRIVILEGES;
Related
Using docker compose i have a mysql 5.7 database container, i set the root password and a user password but they don't work, the docker-compose:
version: '3.8'
services:
viprs-proxy:
platform: linux/amd64
image: nginx:alpine
container_name: viprs-proxy
depends_on:
- viprs-website
volumes:
- ./nginx/proxy.conf:/etc/nginx/nginx.conf
ports:
- 80:80
networks:
- viprs-net
viprs-website:
platform: linux/amd64
image: nginx
container_name: viprs-website
depends_on:
- php
- viprs-website-database
volumes:
- ./website/nginx/site.conf:/etc/nginx/conf.d/default.conf
- ./website:/usr/share/nginx/html
- ./website/logs:/var/log/nginx
- viprs-uploads:/usr/share/nginx/html/wp-content/uploads
ports:
- 80
links:
- php
networks:
- viprs-net
php:
platform: linux/amd64
#image: php:7-fpm
image: viprs-php
container_name: php
volumes:
- ./website:/usr/share/nginx/html
ports:
- 9000
networks:
- viprs-net
viprs-website-database:
platform: linux/amd64
image: mysql:5.7
container_name: viprs-db
command: --init-file /usr/share/nginx/website.sql
volumes:
- ./website.sql:/usr/share/nginx/website.sql
- viprs-db:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: testpassword
MYSLQ_DATABASE: viprs
MYSQL_USER: viprs
MYSQL_PASSWORD: testpassword
networks:
- viprs-net
networks:
viprs-net:
volumes:
viprs-uploads:
viprs-db:
Now if i log into bash:
docker exec -it viprs-db bash
and try to log into mysql:
mysql -u root -p
It just says access is denied, it doesn't matter if i am using the root user or the viprs user.
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
If i output $MYSQL_ROOT_PASSWORD it gives:
echo $MYSQL_ROOT_PASSWORD
testpassword
I have seen loads of people with this issue but can't find any solution that works. The environment is set as per the image documentation on docker hub so i'm confused.
In fact, i can log in as root without a password, so something isn't right.
The environment variables are only used if there is no database present when then container starts and MySQL has to create one.
If there already is a database, the users defined in that database are used and no new users are created. Since you have a volume mapping on /var/lib/mysql chances are that you already have a database.
To verify if that's the issue, you can try removing the /var/lib/mysql mapping. That will cause the container to create a new database when it starts using the environment variable values.
I'm using mysql in docker. I can access docker through docker exec terminal. But I can't access it outside through my regular terminal or sequel ace.
What I'm getting in in sequel ace and in regular terminal
Access denied
Unable to connect to host 127.0.0.1 because access was denied.
Double-check your username and password and ensure that access from your current location is permitted.
MySQL said: Access denied for user 'crowdtank'#'localhost' (using password: YES)
Access denied for user 'crowdtank'#'localhost' (using password: YES)
Terminal command and output for access attempt
ERROR 1045 (28000): Access denied for user 'crowdtank'#'localhost' (using password: YES)
My docker code
version: '3'
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8080:80"
volumes:
- ./src:/var/www
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.22
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: crowdtank
MYSQL_USER: crowdtank
MYSQL_PASSWORD: crowdtank
MYSQL_ROOT_PASSWORD: crowdtank
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www
ports:
- "9000:9000"
networks:
- laravel
newbies for airflow and mysql settings here. I am trying to set up airflow in docker-compose with MySQL as backend.
I have my mySQL connection string as sql_alchemy_conn_cmd=mysql://localuser:localpassword#mock_mysql/metastore in airflow.cfg
I have my docker-compose.yml as
version: "3.9"
networks:
airflow:
services:
redis_local:
image: redis:latest
container_name: redis_server
ports:
- 6379:6379
command: redis-server
restart: on-failure
networks:
- airflow
mysql_local:
image: mysql:5.7
container_name: mysql_local
environment:
- MYSQL_ROOT_HOST=%
- MYSQL_USER=localuser
- MYSQL_PASSWORD=localpassword
- MYSQL_ROOT_PASSWORD=localpassword
- MYSQL_DATABASE=metastore
volumes:
- ./script/init.sql:/data/application/init.sql
- ./dbdata:/var/lib/mysql
ports:
- 3306:3306
restart: on-failure
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 1s
retries: 10
command:
--init-file /data/application/init.sql
--explicit_defaults_for_timestamp=1
networks:
- airflow
airflow_init_db:
depends_on:
- redis_local
- mysql_local
container_name: airflow_init_db
image: apache/airflow:2.0.0-python3.8
command: airflow initdb
since it's connecting to the metastore database, it will required to set up the database in mysql when the database is starting. i have my init.sql as
CREATE DATABASE IF NOT EXISTS metastore;
CREATE USER 'localuser'#'localhost' IDENTIFIED BY 'localpassword';
GRANT ALL PRIVILEGES ON metastore . * TO 'localuser'#'localhost';
FLUSH PRIVILEGES;
However from the healthcheck, mysql itself was failing with
mysql_local | 2021-07-06T04:29:04.011037Z 3 [Note] Access denied for user 'root'#'localhost' (using password: NO)
init db and scheduler both failed with
sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (2005, "Unknown MySQL server host 'mock_mysql' (-2)")
I wasn't really sure what are missing at this point.
really appreciate any help!
Thanks
Two problems.
you should use mysql_local as hostname in your connection string not mock_mysql as this is the name of your MySQL container (and this.is the name defined in DNS by docker-compose)
the healthecheck you use assumes password-less authentication, and likely in default db image of MySQL it is.disabled for security. You should pass user/password as.parameters to your healthecheck command or enable root password-less authentication
Trying to use docker compose for my application, so using official mysql images and my own Dockerfile to create my app image. I think some how my initdb.sql is not executed during docker compose up.
Running this as :
docker-compose up --build
But I can not see that initdb.sql is executed.
My docker compose looks like this:
version: "3"
services:
db:
image: mysql:5.7
restart: always
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_DATABASE: "MYDB"
MYSQL_USER: "myuser"
MYSQL_PASSWORD: "mypassword"
MYSQL_ROOT_PASSWORD: "mypassword"
ports:
- "3306:3306"
expose:
- "3306"
volumes:
- my-db:/var/lib/mysql
- ./sqlinit:/docker-entrypoint-initdb.d/initdb.sql
networks:
vpcbr:
ipv4_address: 10.5.0.6
app:
restart: always
build: .
ports:
- 5000:5000
volumes:
- .:/app
depends_on:
- db
networks:
vpcbr:
ipv4_address: 10.5.0.5
volumes:
my-db:
networks:
vpcbr:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
# gateway: 10.5.0.1
As you can see I have my initdb.sql in this directory ./sqlinit and after I login to mysql container I can see this file in /docker-entrypoint-initdb.d/initdb.sql
But looks like is not executed because when I login to my app I can see:
pymysql.err.OperationalError: (1044, "Access denied for user 'myuser'#'%' to database 'MYDB'")
and on container mysql
2019-09-15T13:17:59.361447Z 2 [Note] Access denied for user 'myuser'#'%' to database 'MYDB
Of course I'm doing something wrong, I found some similar problems here but I still haven't fixed my issue
The problem should be in the way you are mapping the volume. You should map the source file into the target file instead of a source folder into a file, like so:
- ./sqlinit/initdb.sql:/docker-entrypoint-initdb.d/initdb.sql
I have installed docker on digitalocean droplet successfully and below shows my docker-compose.yml configurations:
version: '2.1'
services:
mysql:
build:
context: ./docker/mysql
image: mysql:latest
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: root_pass
MYSQL_USER: root
MYSQL_PASSWORD: root_pass
volumes:
- mysqldata:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
links:
- mysql:db
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root_pass
restart: always
ports:
- 8080:80
And once I up the docker services everything works fine as you can see by below screen capture.
And I can access my mysql database inside terminal perfectly with my user credentials.
But the problem is when I try to access phpmyadmin with droplet_ip:8080 its says:
#1045 - Access denied for user 'root'#'172.18.0.4' (using password: YES)
And here I used same username (root) password (root_pass) as well.
Any suggestions regarding this problem would be grateful. Thank you.
The following works for me
version: '3.1'
volumes:
mysql-volume:
services:
mysql:
image: mysql
container_name: mysql
volumes:
- mysql-volume:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: db
MYSQL_USER: user
MYSQL_PASSWORD: supersecret
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
PMA_HOST: mysql
MYSQL_USER: user
MYSQL_PASSWORD: supersecret
ports:
- 80:80
depends_on:
- mysql
don't mix up root user and MySQL user. In my example above I use the MySQL user to login with phpadmin. if you want to login using your root user you don't have to specify MySQL user and it will look like this (you don't need to specify a user for phpmyadmin because it's always root):
version: '3.1'
volumes:
mysql-volume:
services:
mysql:
image: mysql
container_name: mysql
volumes:
- mysql-volume:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: db
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: rootpass
ports:
- 80:80
depends_on:
- mysql
Also very important, remove your mysql volume when you want to recreate the whole setup. (docker volume rm ..). Because maybe your mysql is started with the same volume again after making changes.
I got the access denied error because I had a dollar sign in my password, which the docker compose file parses as variable substitution (I've only seen the ${} syntax) on this page you will read "Both $VARIABLE and ${VARIABLE} syntax are supported."
Therefore if I had for example this as my database password in the docker compose file: hello$world, the world variable would get substituted, of course I don't have a 'world' variable, the password that would be set in that case would be hello, so without knowing the docker compose syntax you would be trying to log in with hello$world, and you'd be denied access.