在docker的mysql.cnf文件中增加如下配置:
- [client]
- port = 3306
- default-character-set = utf8mb4
-
- [mysqld]
- user = mysql
- port = 3306
- sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
- default-storage-engine = InnoDB
- default-authentication-plugin = mysql_native_password
- character-set-server = utf8mb4
- collation-server = utf8mb4_unicode_ci
- init_connect = 'SET NAMES utf8mb4'
- skip-character-set-client-handshake
- explicit_defaults_for_timestamp
- slow_query_log
- long_query_time = 3
- slow-query-log-file = /var/log/mysql/mysql.slow.log
- log-error = /var/log/mysql/mysql.error.log
- default-time-zone = '+8:00'
-
- skip-log-bin //增加这一行配置,表示去掉binlog功能。
- [mysql]
- default-character-set = utf8mb4
然后删除掉原有的mysql容器和镜像,
docker rm mysql-id
docker rmi mysql-image-id
然后重新composer up,此时我出现了如下报错
- mysql | [Entrypoint] MySQL Docker Image 8.0.28-1.2.7-server
- mysql | [Entrypoint] Initializing database
- mysql | 2022-08-01T13:33:52.923435Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 17
- mysql | 2022-08-01T13:33:52.924552Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
- mysql | 2022-08-01T13:33:52.924557Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
- mysql | 2022-08-01T13:33:52.924618Z 0 [ERROR] [MY-010119] [Server] Aborting
- mysql | 2022-08-01T13:33:52.924714Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.28) MySQL Community Server - GPL.
- mysql | [Entrypoint] MySQL Docker Image 8.0.28-1.2.7-server
此时需要删除掉docker文件内的data目录下的mysql目录【慎】。
重新compose up, SUCCESS!