docker安装mysql
- 创建本地挂载目录
mkdir -p /opt/docker/mysql/conf
mkdir -p /opt/docker/mysql/sql
mkdir -p /opt/docker/mysql/data
- 创建my.cnf
vi /opt/docker/mysql/conf/my.cnf
- 输入i 编辑,粘贴以下内容。wq! 保存并退出
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Custom config should go here
!includedir /etc/mysql/conf.d/
max_connections = 10000
- 构建容器
docker run -dit \
--net host \
-e MYSQL_ROOT_PASSWORD='密码' \
-v /opt/docker/mysql/conf/my.cnf:/etc/mysql/my.cnf:rw \
-v /opt/docker/mysql/sql/:/opt/docker/mysql/sql/:rw \
-v /etc/localtime:/etc/localtime:ro \
-v /opt/docker/mysql/data/:/var/lib/mysql/:rw \
--name mysql8 \
--restart=always mysql:8.0
注意事项
数据库未打开远程访问权限
进入容器
docker exec -it mysql8 bash
登录mysql
mysql -uroot -p
输入密码
使用mysql库
use mysql;
修改user表
update user set host ='%' where user ='root' and host='127.0.0.1';
刷新
flush privileges;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?