docker-library / mysql

Docker Official Image packaging for MySQL Community Server
https://dev.mysql.com/
GNU General Public License v2.0
2.42k stars 2.18k forks source link

Image 5.7 : my.cnf configuration can not enable bin log #1030

Closed shiack closed 4 months ago

shiack commented 4 months ago

Any help will be appreciated

After the container first runs, it fails to connect to the server:

docker run -d -p 3001:3306 --privileged=true                    \
-v /app/mysql-master/log:/var/log/mysql                         \
-v /app/mysql-master/data:/var/lib/mysql                        \
-v /app/mysql-master/conf:/etc/mysql/conf.d                     \
-e MYSQL_ROOT_PASSWORD=1234                                     \
--name mysql-master1 mysql:5.7

The error encountered:

$ docker exec -it [CONTAINER_ID] mysql -uroot -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

After trying to change the configuration, it can connect:

[mysql]
socket = /var/lib/mysql/mysql.sock
[mysqld]
server_id=101
log-bin=mysql-bin  
...

However, when tried to set replication node:

CREATE USER 'test'@'%' IDENTIFIED BY '1234';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'test'@'%';
flush privileges;

it will still fail :

mysql> show variables like '%log_bin%';
+---------------------------------+-------+
| Variable_name                   | Value |
+---------------------------------+-------+
| log_bin                         | OFF   |
| log_bin_basename                |       |
| log_bin_index                   |       |
| log_bin_trust_function_creators | OFF   |
| log_bin_use_v1_row_events       | OFF   |
| sql_log_bin                     | ON    |
+---------------------------------+-------+

and also, result of following command is emty:

show master status;
tianon commented 4 months ago

There are probably some useful logs on the container that are worth checking. It's also worth noting that you likely don't want to run MySQL with --privileged (that would mean that any compromise of your database container is also a 100% definitely compromised host).

tianon commented 4 months ago

My attempt to reproduce a failure was unsuccessful: :sweat_smile:

$ docker run -d -e MYSQL_ROOT_PASSWORD=1234 --pull=always --name mysql mysql:5.7
5.7: Pulling from library/mysql
20e4dcae4c69: Pull complete 
1c56c3d4ce74: Pull complete 
e9f03a1c24ce: Pull complete 
68c3898c2015: Pull complete 
6b95a940e7b6: Pull complete 
90986bb8de6e: Pull complete 
ae71319cb779: Pull complete 
ffc89e9dfd88: Pull complete 
43d05e938198: Pull complete 
064b2d298fba: Pull complete 
df9a4d85569b: Pull complete 
Digest: sha256:4bc6bc963e6d8443453676cae56536f4b8156d78bae03c0145cbe47c2aad73bb
Status: Downloaded newer image for mysql:5.7
a1f785751f104a9844bfa0a36781b4ea09a110fbda5263d8764731de1d4f976b
$ docker logs --tail=2 mysql
2024-02-21T23:18:21.064228Z 0 [Note] mysqld: ready for connections.
Version: '5.7.44'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
$ docker exec -it mysql mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
shiack commented 4 months ago

I found the missing configuration, now it is working. Very helpful advice

tianon commented 4 months ago

Nice, glad you got it figured!