参考:https://blog.csdn.net/m0_67402588/article/details/126075186
1、下载镜像,注意这里要下载适配了arm架构的镜像源
docker pull mysql/mysql-server
2、创建容器
docker run --name mysql-local -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql/mysql-server
3、进入到docker容器中修改连接权限,否则只能本地连接
docker exec -it mysql-local bash
# 进入mysql命令行
mysql -uroot -p123456
# 授权
use mysql;
update user set host = "%" where user='root';
# 刷新权限
flush privileges;
实操
frantichow@FrantiChowdeMac-mini homebrew % docker pull mysql/mysql-server
Using default tag: latest
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
frantichow@FrantiChowdeMac-mini homebrew %
frantichow@FrantiChowdeMac-mini homebrew %
frantichow@FrantiChowdeMac-mini homebrew % systemctl start docker.service
zsh: command not found: systemctl
frantichow@FrantiChowdeMac-mini homebrew % docker pull mysql/mysql-server
Using default tag: latest
latest: Pulling from mysql/mysql-server
latest: Pulling from mysql/mysql-server
022417830bcf: Pull complete
fe10b20dcdae: Pull complete
624f2f22548b: Pull complete
0eb07ea8ad2a: Pull complete
8b517dfb74ad: Pull complete
ebef84d68e30: Pull complete
604975d7252e: Pull complete
Digest: sha256:d6c8301b7834c5b9c2b733b10b7e630f441af7bc917c74dba379f24eeeb6a313
Status: Downloaded newer image for mysql/mysql-server:latest
docker.io/mysql/mysql-server:latest
frantichow@FrantiChowdeMac-mini homebrew % cd
frantichow@FrantiChowdeMac-mini ~ % ls
Desktop Downloads Movies Pictures Sunlogin configfile log
Documents Library Music Public Sunlogin Files docker-hue-4.10
frantichow@FrantiChowdeMac-mini ~ % vim docker_mysql.sh
frantichow@FrantiChowdeMac-mini ~ % docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql/mysql-server latest 423da140c8c0 2 weeks ago 507MB
gethue/hue latest 9045fd343f92 4 months ago 1.8GB
frantichow@FrantiChowdeMac-mini ~ %
frantichow@FrantiChowdeMac-mini ~ %
frantichow@FrantiChowdeMac-mini ~ %
frantichow@FrantiChowdeMac-mini ~ % sh docker_mysql.sh
91426d7b0bdc734e690247d861390f1390adbb13c92ea1ceb6f9d9d26e26c5c3
frantichow@FrantiChowdeMac-mini ~ % docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91426d7b0bdc mysql/mysql-server "/entrypoint.sh mysq…" 3 seconds ago Up 2 seconds (health: starting) 0.0.0.0:3306->3306/tcp, 33060-33061/tcp mysql-local
frantichow@FrantiChowdeMac-mini ~ % docker exec -it mysql-local bash
bash-4.4# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> #
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host = "%" where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> #
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>
标签:mini,frantichow,FrantiChowdeMac,server,mac,mysql,docker
From: https://www.cnblogs.com/frantichow/p/17093236.html