重启机器后mysql容器启动后连接不上。
连接容器查询mysql状态。
root@9a89569f13ea:/var/lib/mysql# mysqld stop --user=root
2022-08-27T06:25:03.929374Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-27T06:25:03.936640Z 0 [Note] mysqld (mysqld 5.7.31-log) starting as process 145 ...
2022-08-27T06:25:03.947011Z 0 [Note] InnoDB: PUNCH HOLE support available
2022-08-27T06:25:03.947094Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-08-27T06:25:03.947118Z 0 [Note] InnoDB: Uses event mutexes
2022-08-27T06:25:03.947137Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2022-08-27T06:25:03.947192Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-08-27T06:25:03.947225Z 0 [Note] InnoDB: Using Linux native AIO
2022-08-27T06:25:03.948982Z 0 [Note] InnoDB: Number of pools: 1
2022-08-27T06:25:03.949161Z 0 [Note] InnoDB: Using CPU crc32 instructions
2022-08-27T06:25:03.951334Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2022-08-27T06:25:03.961632Z 0 [Note] InnoDB: Completed initialization of buffer pool
2022-08-27T06:25:03.964365Z 0 [Note] InnoDB: page_cleaner coordinator priority: -20
2022-08-27T06:25:03.977720Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2022-08-27T06:25:03.977812Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2022-08-27T06:25:03.977838Z 0 [Note] InnoDB: Retrying to lock the first data file
2022-08-27T06:25:04.978110Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2022-08-27T06:25:04.978345Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2022-08-27T06:25:05.978708Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2022-08-27T06:25:05.978937Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2022-08-27T06:25:06.979395Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2022-08-27T06:25:06.979524Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2022-08-27T06:25:07.980828Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2022-08-27T06:25:07.980947Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
解决方式:
删除容器:
$ docker-compose down
然后进入数据目录:
data$ mv ibdata1 ibdata1.bak
data$ mv ib_logfile0 ib_logfile0.bak
data$ mv ib_logfile1 ib_logfile1.bak
data$ cp -a ibdata1.bak ibdata1
data$ cp -a ib_logfile0.bak ib_logfile0
data$ cp -a ib_logfile1.bak ib_logfile1
创建容器
$ docker-compose up -d
使用工具连接,OK