Loading

【三】pig4cloud项目一键build -- Mysql创建新用户,并外网访问

Mysql 默认用户root是禁止外网访问的,而且使用root外网访问权限太大,不安全, 而且pig4cloud 程序里面默认配置的是root,那这里我们把root用户作为程序运行的账户,我们新创建一个developer账户作为开发人员使用的账户。

进入容器,并切换mysql数据库

# 1、进入容器
docker exec -it mysql /bin/bash


# 2、容器内使用root登录mysql, 账户密码默认都是root

bash-4.4#  mysql -u root -proot

mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 708
Server version: 8.0.27 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_native_password,否则在用native登录的时候会提示caching_sha2_password,需要再去修改用户配置

# 创建一个新用户
create user 'developer'@'%' identified with mysql_native_password by '123456';

授权

这里为了图方便,开放了所有权限,正常情况下,是按照账户角色开对应的数据库权限

# 授予所有权限
grant all on *.* to developer@'%';


* :具体的可参考
https://blog.csdn.net/wwppp987/article/details/123983250

刷新配置

# 刷新
FLUSH PRIVILEGES;

客户端连接测试

posted @ 2022-07-21 15:47  jesn  阅读(306)  评论(0编辑  收藏  举报