docker启动mysql并打开远程连接
1. 获取mysql:拉去mysql镜像docker pull mysql:8.02. 启动mysql# --name指定容器名字 -v目录挂载 -p指定端口映射-e设置mysql参数 -d后台运行docker run --name mysql -v /usr/local/mysql/data:/var/lib/mysql -v /usr/local/mysql:/etc/mysql/conf.d
·
1. 获取mysql:拉去mysql镜像
docker pull mysql:8.0
2. 启动mysql
# --name指定容器名字 -v目录挂载 -p指定端口映射 -e设置mysql参数 -d后台运行
docker run --name mysql -v /usr/local/mysql/data:/var/lib/mysql -v /usr/local/mysql:/etc/mysql/conf.d -v /usr/local/mysql/log:/var/log/mysql -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -d mysql:8.0
3. 进入mysql容器
docker exec -it 容器名称|容器id bin/bash
4. 登录mysql,并打开远程访问授权
//1.登录mysql
mysql -uroot -p
//2.进行授权
GRANT ALL ON *.* TO 'root'@'%';
//3.刷新权限
flush privileges;
//4.加密规则
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
//5.更新root密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
//6.刷新权限
flush privileges;
5. 使用远程登录进行测试
更多推荐
已为社区贡献1条内容
所有评论(0)