Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自容器外部的MySQL内部错误_Mysql_Docker - Fatal编程技术网

来自容器外部的MySQL内部错误

来自容器外部的MySQL内部错误,mysql,docker,Mysql,Docker,我构建了一个MySQL服务器映像,可以运行它的容器,我也可以从另一个容器访问它,就在上周的几天里,所有这些都在我的笔记本电脑上运行Docker 17.05.0-ceonUbuntu 16.04。然后,昨天我无法从外部访问MySQL。它开始告诉我错误:error 2013(HY000):在“读取初始通信包”时与MySQL服务器失去连接,系统错误:0“内部错误/检查(非系统错误)” 以下是Dockerfile内容: $ cat mysql/Dockerfile FROM ubuntu:16.04

我构建了一个MySQL服务器映像,可以运行它的容器,我也可以从另一个容器访问它,就在上周的几天里,所有这些都在我的笔记本电脑上运行
Docker 17.05.0-ce
on
Ubuntu 16.04
。然后,昨天我无法从外部访问MySQL。它开始告诉我错误:
error 2013(HY000):在“读取初始通信包”时与MySQL服务器失去连接,系统错误:0“内部错误/检查(非系统错误)”

以下是
Dockerfile
内容:

$ cat mysql/Dockerfile 
FROM ubuntu:16.04

RUN apt-get update \
  && apt-get install -y libncurses-dev \
  && apt-get install -y build-essential \
  && apt-get install -y cmake

COPY mysql-5.6.30.tar.gz /usr/bin/
WORKDIR /usr/bin/
RUN gzip -d mysql-5.6.30.tar.gz \
  && tar -xvf mysql-5.6.30.tar \
  && ln -s mysql-5.6.30 mysql

WORKDIR /usr/bin/mysql/
RUN mkdir install && mkdir install/data && mkdir install/var && mkdir install/etc && mkdir install/tmp

RUN cd /usr/bin/mysql/ \
  && cmake \
  -DCMAKE_INSTALL_PREFIX=/usr/bin/mysql/install \
  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  -DMYSQL_DATADIR=/usr/bin/mysql/install/data \
  -DDOWNLOAD_BOOST=1 \
  -DWITH_BOOST=/usr/bin/mysql/install/boost \
  -DMYSQL_UNIX_ADDR=/usr/bin/mysql/install/tmp/mysql.sock \
  && make \
  && make install \
  && make clean

EXPOSE 3306

COPY startup.sh install/startup.sh

COPY my.cnf install/my.cnf

ENTRYPOINT ["/bin/bash", "install/startup.sh"]
my.cnf
文件内容:

[mysqld]
bind-address    = 0.0.0.0 # Allow client binding from any IP address instead of just 127.0.0.1
port            = 3307
sql_mode        = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION # This is strict mode: NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
socket          = /usr/bin/mysql/install/tmp/mysql.sock
user            = root
basedir         = /usr/bin/mysql/install
datadir         = /usr/bin/mysql/install/data
log-bin         = /usr/bin/mysql/install/mysql.bin.log
log-error       = /usr/bin/mysql/install/mysql.error.log
general-log-file     = /usr/bin/mysql/install/mysql.log
slow-query-log-file  = /usr/bin/mysql/install/mysql.slow.queries.log
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
innodb_flush_method = O_DIRECT
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init-connect = 'SET NAMES utf8mb4'
character-set-client-handshake = FALSE
wait_timeout = 28800 # amount of seconds during inactivity that MySQL will wait before it will close a connection on a non-interactive connection
interactive_timeout = 28800 # same, but for interactive sessions
[client]
socket = /usr/bin/mysql/install/tmp/mysql.sock
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
#!/bin/bash -x

if [ ! -f /usr/bin/mysql/install/data/ibdata1 ]; then
  chmod 755 /usr/bin/mysql/install/scripts/mysql_install_db
  sleep 1 # Needed to avoid running the script when this mysql_install_db file has not yet been released by the permissions change
  /usr/bin/mysql/install/scripts/mysql_install_db \
    --no-defaults \
    --explicit_defaults_for_timestamp \
    --basedir=/usr/bin/mysql/install \
    --datadir=/usr/bin/mysql/install/data \
    --tmpdir=/usr/bin/mysql/install/tmp \
    --lc-messages-dir=/usr/bin/mysql/install/share

  /usr/bin/mysql/install/bin/mysqld_safe --defaults-file=/usr/bin/mysql/install/my.cnf &
  sleep 10s
  echo "GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; FLUSH PRIVILEGES" | /usr/bin/mysql/install/bin/mysql
  tail -f /etc/hosts
else
  /usr/bin/mysql/install/bin/mysqld_safe --defaults-file=/usr/bin/mysql/install/my.cnf
fi
startup.sh
文件内容:

[mysqld]
bind-address    = 0.0.0.0 # Allow client binding from any IP address instead of just 127.0.0.1
port            = 3307
sql_mode        = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION # This is strict mode: NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
socket          = /usr/bin/mysql/install/tmp/mysql.sock
user            = root
basedir         = /usr/bin/mysql/install
datadir         = /usr/bin/mysql/install/data
log-bin         = /usr/bin/mysql/install/mysql.bin.log
log-error       = /usr/bin/mysql/install/mysql.error.log
general-log-file     = /usr/bin/mysql/install/mysql.log
slow-query-log-file  = /usr/bin/mysql/install/mysql.slow.queries.log
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
innodb_flush_method = O_DIRECT
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init-connect = 'SET NAMES utf8mb4'
character-set-client-handshake = FALSE
wait_timeout = 28800 # amount of seconds during inactivity that MySQL will wait before it will close a connection on a non-interactive connection
interactive_timeout = 28800 # same, but for interactive sessions
[client]
socket = /usr/bin/mysql/install/tmp/mysql.sock
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
#!/bin/bash -x

if [ ! -f /usr/bin/mysql/install/data/ibdata1 ]; then
  chmod 755 /usr/bin/mysql/install/scripts/mysql_install_db
  sleep 1 # Needed to avoid running the script when this mysql_install_db file has not yet been released by the permissions change
  /usr/bin/mysql/install/scripts/mysql_install_db \
    --no-defaults \
    --explicit_defaults_for_timestamp \
    --basedir=/usr/bin/mysql/install \
    --datadir=/usr/bin/mysql/install/data \
    --tmpdir=/usr/bin/mysql/install/tmp \
    --lc-messages-dir=/usr/bin/mysql/install/share

  /usr/bin/mysql/install/bin/mysqld_safe --defaults-file=/usr/bin/mysql/install/my.cnf &
  sleep 10s
  echo "GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; FLUSH PRIVILEGES" | /usr/bin/mysql/install/bin/mysql
  tail -f /etc/hosts
else
  /usr/bin/mysql/install/bin/mysqld_safe --defaults-file=/usr/bin/mysql/install/my.cnf
fi
我可以用以下命令运行它:

docker run -d -p 3307:3306 -v /home/stephane/dev/php/learnintouch/docker/mysql/data:/usr/bin/mysql/install/data --name mysql stephaneeybert/mysql:5.6.30
我可以看到端口处于打开状态:

nmap -p 3307 localhost
我可以进入它的bash shell:

docker exec -it mysql bash
而且,在容器中,我可以很好地登录:

/usr/bin/mysql/install/bin/mysql -u root -p
但如果我想从主机登录:

cd programs/install/mariadb/; bin/mysql -h localhost -P 3307 --protocol=tcp -u root -p
这给了我一个信息:

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"

集装箱暴露端口3306

FROM ubuntu:16.04
# ...
EXPOSE 3306
# ...
mysql正在侦听容器中的端口3307,这里应该是3306

[mysqld]
bind-address    = 0.0.0.0
port            = 3307
然后docker将集装箱端口3306转发到主机3307

docker run -d -p 3307:3306

集装箱暴露端口3306

FROM ubuntu:16.04
# ...
EXPOSE 3306
# ...
mysql正在侦听容器中的端口3307,这里应该是3306

[mysqld]
bind-address    = 0.0.0.0
port            = 3307
然后docker将集装箱端口3306转发到主机3307

docker run -d -p 3307:3306