安装
可以略过本步
https://dev.mysql.com/downloads/https://dev.mysql.com/downloads/
镜像查询与安装
先查询:
docker search mysql
明显会报错
Error response from daemon: Get "https://index.docker.io/v1/search?q=mysql&n=25": dial tcp 173.208.182.68:443: i/o timeout
不管三七二十一 docker pull mysql
创建映射文件夹
mkdir -p /home/mysql/log
mkdir -p /home/mysql/data
mkdir -p /home/mysql/conf
vim /home/mysql/conf/my.cnf
参考【10分钟轻松部署,通过Docker部署MySQL8.3.0数据库】_docker mysql-CSDN博客
[client]
#设置客户端默认字符集utf8mb4
default-character-set=utf8mb4
[mysql]
#设置服务器默认字符集为utf8mb4
default-character-set=utf8mb4
[mysqld]
#配置服务器的服务号,具备日后需要集群做准备
server-id = 1
#开启MySQL数据库的二进制日志,用于记录用户对数据库的操作SQL语句,具备日后需要集群做准备
# log-bin=mysql-bin
#设置清理超过30天的日志,以免日志堆积造过多成服务器内存爆满。2592000秒等于30天的秒数
binlog_expire_logs_seconds = 2592000
#解决MySQL8.0版本GROUP BY问题
# sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
#允许最大的连接数
max_connections=1000
# 禁用符号链接以防止各种安全风险
# symbolic-links=0
# 设置东八区时区
default-time_zone = '+8:00'
#不检查赋值目录
secure_file_priv=
赋予权限
chmod -R 755 "/home/mysql/"
创建docker
docker run \
-p 3306:3306 \
--restart=always \
--name mysql \
--privileged=true \
-v /home/mysql/log:/var/log/mysql \
-v /home/mysql/data:/var/lib/mysql \
-v /home/mysql/conf/my.cnf:/etc/mysql/my.cnf \
-e MYSQL_ROOT_PASSWORD=Ykm \
-d mysql
不过上面的-e MYSQL_ROOT_PASSWORD=Ykm \似乎没用
进入容器创建远程连接
docker exec -it 容器ID或名称 bash
docker exec -it mysql /bin/bash
mysql -u root -p
可能输入密码也进不去
也许可以直接使用无密码模式可以进入
mysql -u root
创建一个新账号用于远程连接
CREATE USER 'admin'@'%' IDENTIFIED BY 'tyuueew33IIIOOO88qqq';
赋予权限
GRANT ALL ON *.* TO 'admin'@'%';
FLUSH PRIVILEGES;
断开navicat并重新连接
创建数据库
可以使用navicat图形化界面创建
docker启动失败
docker logs
报错,以下报错显示没有权限,原因是my.cnf需要增加一行
#不检查赋值目录
secure_file_priv=
[root@izwz99kdj07ayo2p6q5ntdz ~]# docker logs aa7f59febb86
2025-04-05 05:44:32+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2025-04-05 05:44:32+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-04-05 05:44:32+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2025-04-05 05:44:32+00:00 [Note] [Entrypoint]: Initializing database files
2025-04-05T05:44:32.848501Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.27) initializing of server in progress as process 42
2025-04-05T05:44:32.860756Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-04-05T05:44:34.426855Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-04-05T05:44:35.789846Z 0 [Warning] [MY-010161] [Server] You need to use --log-bin to make --binlog-expire-logs-seconds work.
2025-04-05T05:44:36.120842Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2025-04-05T05:44:36.120878Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2025-04-05T05:44:36.176636Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2025-04-05 05:44:40+00:00 [Note] [Entrypoint]: Database files initialized
2025-04-05 05:44:40+00:00 [Note] [Entrypoint]: Starting temporary server
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2025-04-05T05:44:40.866038Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2025-04-05 05:44:40+00:00 [ERROR] [Entrypoint]: Unable to start server.
2025-04-05 05:44:41+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2025-04-05 05:44:41+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-04-05 05:44:41+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2025-04-05T05:44:42.114884Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2025-04-05T05:44:42.114931Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-04-05 05:44:42+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2025-04-05 05:44:42+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-04-05 05:44:42+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2025-04-05T05:44:43.422624Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2025-04-05T05:44:43.422667Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-04-05 05:44:44+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2025-04-05 05:44:44+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-04-05 05:44:44+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2025-04-05T05:44:44.921504Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2025-04-05T05:44:44.921553Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-04-05 05:44:46+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2025-04-05 05:44:46+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-04-05 05:44:46+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2025-04-05T05:44:46.785147Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2025-04-05T05:44:46.785198Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-04-05 05:44:48+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2025-04-05 05:44:48+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-04-05 05:44:48+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2025-04-05T05:44:49.483939Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2025-04-05T05:44:49.483989Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-04-05 05:44:53+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2025-04-05 05:44:53+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-04-05 05:44:53+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2025-04-05T05:44:53.743940Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2025-04-05T05:44:53.743989Z 0 [ERROR] [MY-010119] [Server] Aborting
[root@izwz99kdj07ayo2p6q5ntdz ~]# Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
-bash: Failed: command not found