Docker - zsh: command not found: mysql - mysql

I am running WordPress with wp-env and docker configuration,
I want to connect to mysql via cli but I keep getting this error:
zsh: command not found: mysql
I have tried: mysql -h 127.0.0.1:3308 -u root -p and in post 3306 as well
this is my docker-compose.yaml file
phpmyadmin works great
version: '3.1'
services:
mysql:
image: mysql:5.7
ports:
- 3308:3306
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress_test
phpmyadmin:
depends_on:
- mysql
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: mysql
volumes:
testsuite:
`

What I did was to execute the following command:
docker exec -it {container name} bash -l

Related

How to connect to mariadb from host with docker-compose

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.

How can I connect docker node with docker mysql to write a seed ts to mysql in docker build?

I want to insert a initial data in docker mysql that it generate with a seeder in typescript that I have in a docker but this not work because when docker node try to connect to docker mysql this fail but when i try to run docker mysql only and after i run node command it work.
This is my docker-compose-yml
version: "3.1"
services:
mysql:
image: mysql
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
volumes:
- ./mysqlDb:/var/lib/mysql
- ./init:/docker-entrypoint-initdb.d
adminer:
image: adminer
ports:
- 8080:8080
links:
- mysql
node:
build:
context: .
dockerfile: Dockerfile
container_name: serverJS
volumes:
- ./:/usr/app/
ports:
- 3000:3000
depends_on:
- mysql
These are the script that i want to run 1 time only before the node express run server
"db:drop": "ts-node node_modules/.bin/typeorm schema:drop",
"db:create": "ts-node node_modules/.bin/typeorm migration:run",
"db:seed": "ts-node ./node_modules/typeorm-seeding/dist/cli.js seed"
but I only do it if these script run always it start but i want run only in the first run

Can't Connect to MySQL Database using Adminer and docker-compose

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>

Connecting Python and MySQL in docker / docker-compose

Before, I created named volume and database: 'mysql-db1' using other mysql container.
I can't connect to database from python.
My .yml file :
version: '3.6'
services:
python:
image: python:latest
ports:
- '80:80'
volumes:
- type: bind
source: .
target: /scripts
command: tail -f /dev/null
links:
- 'mysql'
mysql:
image: mysql/mysql-server:latest
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- type: volume
source: mysql-db1
target: /var/lib/mysql
volumes:
mysql-db1:
external: true
My simply python code:
import mysql.connector
cnx = mysql.connector.connect(user='root', password='root', host='mysql', database='test1')
cnx.close()
I can enter the database using:
$ docker-compose exec mysql bash
# mysql -uroot -proot -Dtest1
Error:
mysql.connector.errors.DatabaseError: 1130 (HY000): Host '172.18.0.3' is not allowed to connect to this MySQL server
Where is a problem?
root user is not allowed to access the db externally by default. Use image environment variables to create a user and use that:
db:
restart: always
image: mariadb
container_name: myapp_db
environment:
- MYSQL_USER=myuser
- MYSQL_PASSWORD=mypass
- MYSQL_DATABASE=mydb
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
ports:
- 3306:3306

Error in connecting to docker container from sql-client of Host network

I am triggering mysql with compose file:
version: "3"
services:
my-sql:
image: mysql
container_name: my-sql
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: passw0rd
MYSQL_USER: dbuser
MYSQL_PASSWORD: pass1234
MYSQL_DATABASE: connect_test
On find IPAdress of container in following manner:
root#sevenos:~# docker inspect my-sql | grep IPAddress
"SecondaryIPAddresses": null,
"IPAddress": "",
"IPAddress": "172.18.0.2",
When i am connecting with my-sql client outside the container,I am getting error as follows:
root#sevenos:~# mysql -uroot -ppassw0rd -h 172.18.0.2 -P 3306
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be
loaded: /usr/lib/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
You can init docker with the command to load default authentication plugin as follow:
mysql:
image: mysql
container_name: mysql
command: mysqld --default-authentication-plugin=mysql_native_password
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
volumes_from:
- mysql-data
ports:
- "3306:3306"
And before you run it you must remove all mysql volumes:
docker-compose rm
docker volume rm list_of_your_volumes
docker-compose up
You can take a look at for more details: https://github.com/passbolt/passbolt_docker/issues/103