第一:上命令行
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
如果外挂配置文件和数据库文件:
docker run -v /data/mysql/data:/var/lib/mysql -v /data/mysql/conf:/etc/mysql/conf.d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
补充说明: /data/mysql/data /data/mysql/conf 记得 给权限,否则按匿名外挂
运行后:查看下外挂情况:docker inspect ffe09e3879b3 这才正常。
第二:进入容器
docker exec -it mysql bash//
第三:进入mysql
root@f34783868e58:/# mysql uroot -p
出现如下:
root@f34783868e58:/# mysql uroot -p
Enter password:
ERROR 1049 (42000): Unknown database 'uroot'
继续:
root@f34783868e58:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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>