卸载原mysql
root@localhost mysql_conf]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 8.0.30 dbaea59d1b41 2 years ago 449MB
[root@localhost mysql_conf]# docker rmi bbaf881cbf45
Error response from daemon: No such image: bbaf881cbf45:latest
[root@localhost mysql_conf]# docker rmi dbaea59d1b41
Untagged: mysql:8.0.30
Untagged: mysql@sha256:3c1aab708f6e57fc4dccafe36baccc7219acfb4ec450f3fb6d370ea89409e906
Deleted: sha256:dbaea59d1b4194257138a6434ec0820a13097dd7e900135e78daf9759fe2407a
Deleted: sha256:e507fd966e8388339d4024e698d2d9000eece41c497a8857774c9f0f1f17c3de
Deleted: sha256:239ac15e65c3efa92872682fdfcbf177735fba69a3bb236f7acfb230319f8b9f
Deleted: sha256:944a10fce07786f698ca86bb6781f004e9f1fa22fad021ec57132d77e231a165
Deleted: sha256:6acb95708216880feed67b390e3855ec9c48947904a1f97900584c9bedafca14
Deleted: sha256:28945f2a92f5ff073346724641d6e82464dd61dc903ab71f18eb975503a1a5d1
Deleted: sha256:a1e4e03c3de2361aedf9cea34b0477dc80a7de3dce128ac450a1aa8b4202ea7f
Deleted: sha256:8f063e9b29c9e6fca010e488a7972826483aa87364fee8005d30ac5809d539df
Deleted: sha256:714888f3d7e50ce4819618162cf60f0d6899e556b4cfc83edce10750117bcbaf
Deleted: sha256:3b0f259c919a98067a2debaa2bc9c405250fc9c468ceabc9a0ebe51eb36d2e7e
Deleted: sha256:2047a833bd7438a2271051138d5d599d01374b615a7f77f6ef2b199ff917f6cb
Deleted: sha256:553b196ea5e8358e8b819253dc8fb9af6cf5711df6c83e594b4c2109c61eda18
[root@localhost mysql_conf]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
拉取mysql镜像
[root@localhost mysql_conf]# docker pull mysql:8.2.0
8.2.0: Pulling from library/mysql
558b7d69a2e5: Pull complete
599b67b0dd6a: Pull complete
50314d46ce2b: Pull complete
494babc92263: Pull complete
02548e6f2dbf: Pull complete
a9e5e2637e0d: Pull complete
657b198fe6b7: Pull complete
215a2b0eabbf: Pull complete
377a4c7a89c5: Pull complete
4bfe599fe218: Pull complete
Digest: sha256:212fe73edca5df6ff14826d5eb975c914bfb91f82a2e923f9050568f99525da1
Status: Downloaded newer image for mysql:8.2.0
docker.io/library/mysql:8.2.0
[root@localhost mysql_conf]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 8.2.0 bc861cf238f2 11 months ago 619MB
运行mysql 注意参数–lower_case_table_names=1 忘加会导致查询时表名区分大小写
[root@localhost mysql_conf]# docker run -d --name mysql -p 3306:3306 -v mysql_data:/data/mysql_data -v mysql_conf:/etc/mysql --restart=always --privileged=true -e MYSQL_ROOT_PASSWORD=root mysql:8.2.0 --lower_case_table_names=1
1fe5cd533b8e70195d01c4dcb2d8cdc374b78d0e323e649ef96f8444330b09bc
[root@localhost mysql_conf]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1fe5cd533b8e mysql:8.2.0 "docker-entrypoint.s…" 9 seconds ago Up 8 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
进入docker容器连上msyql修改msyql root用户权限,开放远程操作权限
[root@localhost mysql_conf]# docker exec -it mysql bash
bash-4.4# mysql -u root -p
Enter password:
mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> EXIT
Bye
bash-4.4# EXIT
bash: EXIT: command not found
bash-4.4# exit
exit
[root@localhost mysql_conf]#
1737

被折叠的 条评论
为什么被折叠?



