前言

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架构的程序。

拉取镜像

  1. docker pull mysql/mysql-server:8.0

创建并启动容器

  1. anin@anin ~ % docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql/mysql-server:8.0
  2. 3af7b3a37f3fb902a13cff7c564e55b06212daf651cafaeaa331080e010b7f58

一般会将数据文件、配置、日志等挂载出来

  1. 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

  1. anin@anin ~ % docker exec -it mysql bash
  2. bash-4.4# mysql -u root -p
  3. Enter password:
  4. Welcome to the MySQL monitor. Commands end with ; or \g.
  5. Your MySQL connection id is 12
  6. Server version: 8.0.28 MySQL Community Server - GPL

创建用户

  1. mysql> create user 'anin'@'%' identified by '123456';
  2. Query OK, 0 rows affected (0.00 sec)

给创建好的用户赋予远程登录权限

  1. mysql> grant all on *.* to 'anin'@'%' with grant option;
  2. Query OK, 0 rows affected (0.02 sec)

查看user列表

  1. mysql> SELECT DISTINCT(`user`),host FROM user;
  2. +------------------+-----------+
  3. | user | host |
  4. +------------------+-----------+
  5. | anin | % |
  6. | healthchecker | localhost |
  7. | mysql.infoschema | localhost |
  8. | mysql.session | localhost |
  9. | mysql.sys | localhost |
  10. | root | localhost |
  11. +------------------+-----------+
  12. 6 rows in set (0.00 sec)

修改用户密码

  1. mysql> ALTER USER 'anin'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

刷新权限

  1. mysql> flush privileges;