拉取mysql
docker pull mysql
運行docker容器
docker run -di --name wangjinlong_mysql -p 4406:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
其中4406纔是我們連接的端口,3306是內部端口
進入bash
docker exec -it wangjinlong_mysql /bin/bash
登錄mysql
mysql -u root -p 123456
docker inspect wangjinlong_mysql 運行狀態
設置遠程登錄
grant all privileges on *.* to 'root'@'%';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
很多文檔裏這麼寫,親測是錯誤的:
GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "rw";
flush privileges;