前言
m1 直接docker pull mysql 报:
MacBook-Pro ~ % docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
no matching manifest for linux/arm64/v8 in the manifest list entries
Docker Hub上没有适用于arm64架构的mysql镜像。
M1芯片是arm64架构,也称作aarch64架构,只能运行arm64/aarch64架构的程序。
拉取镜像
docker pull mysql/mysql-server:8.0
创建并启动容器
anin@anin ~ % docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql/mysql-server:8.0
3af7b3a37f3fb902a13cff7c564e55b06212daf651cafaeaa331080e010b7f58
一般会将数据文件、配置、日志等挂载出来
docker run -d -v ~/install/tools/mysql/conf:/etc/my.cnf.d -v ~/install/tools/mysql/logs:/log -v ~/install/tools/mysql/data:/var/lib/mysql -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=root mysql/mysql-server:8.0
开启访问权限
登陆mysql
anin@anin ~ % docker exec -it mysql bash
bash-4.4# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.28 MySQL Community Server - GPL
创建用户
mysql> create user 'anin'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
给创建好的用户赋予远程登录权限
mysql> grant all on *.* to 'anin'@'%' with grant option;
Query OK, 0 rows affected (0.02 sec)
查看user列表
mysql> SELECT DISTINCT(`user`),host FROM user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| anin | % |
| healthchecker | localhost |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
6 rows in set (0.00 sec)
修改用户密码
mysql> ALTER USER 'anin'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
刷新权限
mysql> flush privileges;