目前最新版本为8.0.31
docker pull mysql:8.0.31
mkdir -p /root/mysql/data /root/mysql/logs /root/mysql/conf
docker run -p 3306:3306 --name mysql -v /root/mysql/conf:/etc/mysql/conf.d -v /root/mysql/logs:/logs -v /root/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.31
docker restart mysql
docker start mysql
mysql8.x默认是只允许命令行连接客户端,所以使用Navicat连接的时候会报2059 - authentication plugin caching_sha2_password
docker exec -it mysql bash
mysql -uroot -p123456
alter user 'root'@'%' identified by '123456' password expire never;
alter user 'root'@'%' identified with mysql_native_password by '123456';
flush privileges;
完成,重新登录即可!