docker安装mysql

  1. 创建本地挂载目录
mkdir -p /opt/docker/mysql/conf
mkdir -p /opt/docker/mysql/sql
mkdir -p /opt/docker/mysql/data
  1. 创建my.cnf
vi /opt/docker/mysql/conf/my.cnf
  1. 输入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

  1. 构建容器
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;

修改userupdate user set host ='%' where user ='root' and host='127.0.0.1';

刷新
flush privileges;
posted @   chermye  阅读(59)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示