docker run -p 3307:3306 --name change-mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql
查询mysql容器id
MacbookdeMacBook-Pro:dnmp macbookpro$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a825464de0c7 mysql "docker-entrypoint.s…" 31 minutes ago Up 58 seconds 33060/tcp, 0.0.0.0:3307->3306/tcp change-mysql
进入mysql容器
MacbookdeMacBook-Pro:dnmp macbookpro$ docker exec -it a825464de0c7 /bin/bash
root@a825464de0c7:/# 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 22
Server version: 8.0.15 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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> grant all PRIVILEGES on *.* to root@'%' WITH GRANT OPTION;
mysql> ALTER user 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
mysql> ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
mysql> FLUSH PRIVILEGES;