Some checks failed
Publish to Confluence / confluence (push) Failing after 11m37s
155 lines
4.7 KiB
Markdown
155 lines
4.7 KiB
Markdown
# 数据库管理
|
||
|
||
## Postgresql
|
||
### 安装
|
||
Ubuntu 默认支持,直接使用以下命令安装
|
||
```shell
|
||
apt install postgresql
|
||
```
|
||
- 详细教程可参考 [Postgresql安装教程](https://www.postgresql.org/download/linux/ubuntu/)
|
||
|
||
### 配置
|
||
#### 开放访问
|
||
- 查找配置文件位置
|
||
```shell
|
||
su postgres
|
||
psql
|
||
postgres=# SHOW config_file;
|
||
```
|
||
- 编辑 `postgresql.conf`
|
||
```shell
|
||
vi postgresql.conf
|
||
```
|
||
```properties
|
||
# 修改 listen_addresses 为 *
|
||
listen_addresses = '*'
|
||
```
|
||
- 编辑 `pg_hba.conf`
|
||
```properties
|
||
# 在文件末尾增加一行
|
||
host all all 0.0.0.0/0 md5
|
||
```
|
||
- 重启服务
|
||
```shell
|
||
sudo systemctl restart postgresql
|
||
# 或者在某些系统上可能是
|
||
sudo service postgresql restart
|
||
```
|
||
|
||
#### 创建用户和数据库
|
||
- 进入 `postgres`
|
||
```shell
|
||
su postgres
|
||
```
|
||
- 配置
|
||
```sql
|
||
# 采用命令行工具登陆 PostgreSQL
|
||
psql
|
||
|
||
# 创建数据库
|
||
postgres=# CREATE DATABASE dolphinscheduler;
|
||
# 修改 {user} 和 {password} 为你希望的用户名和密码
|
||
postgres=# CREATE USER {user} PASSWORD {password};
|
||
postgres=# ALTER DATABASE dolphinscheduler OWNER TO {user};
|
||
# 退出 PostgreSQL
|
||
postgres=# \q
|
||
```
|
||
- 配置开放访问(可选:开放访问步骤已经配置)
|
||
```shell
|
||
|
||
# 上面已经配置了,不需要配置
|
||
# 在终端执行如下命令,向配置文件新增登陆权限,并重载 PostgreSQL 配置,替换 {ip} 为对应的 DS 集群服务器 IP 地址段
|
||
echo "host dolphinscheduler {user} {ip} md5" >> $PGDATA/pg_hba.conf
|
||
|
||
# 重启服务
|
||
sudo systemctl restart postgresql
|
||
# 或者在某些系统上可能是
|
||
sudo service postgresql restart
|
||
```
|
||
|
||
#### 测试连接
|
||
- 配置完毕后,从外部客户端尝试连接,以验证配置是否生效。
|
||
|
||
|
||
## Mysql
|
||
|
||
### 安装
|
||
Ubuntu 默认支持,直接使用以下命令安装
|
||
```shell
|
||
apt install mysql
|
||
```
|
||
- 详细教程可参考 [Mysql安装](https://dev.mysql.com/doc/refman/8.4/en/linux-installation-apt-repo.html)
|
||
|
||
### 配置
|
||
#### 开放访问
|
||
- 找到并编辑MySQL配置文件
|
||
- MySQL默认配置文件通常位于 `/etc/mysql/my.cnf` 或 `/etc/my.cnf`,
|
||
实际需要修改的配置文件可能为 `/etc/mysql/mysql.conf.d/mysqld.cnf`,
|
||
具体路径取决于操作系统和MySQL版本。
|
||
- 使用文本编辑器打开配置文件,找到bind-address参数。
|
||
```properties
|
||
bind-address = 0.0.0.0
|
||
```
|
||
- 重启 mysql
|
||
```shell
|
||
systemctl restart mysql
|
||
```
|
||
#### 创建用户
|
||
- 检查创建用户时密码校验条件。在创建用户前,确认下密码验证规则,一般必须大于等于8位
|
||
```sql
|
||
#显示创建用户的验证条件
|
||
mysql> SHOW VARIABLES LIKE 'validate_password%';
|
||
```
|
||
- 创建用户
|
||
```sql
|
||
#创建用户
|
||
mysql> CREATE USER '用户名'@'%或者IP' IDENTIFIED BY '密码';
|
||
|
||
mysql> FLUSH PRIVILEGES;
|
||
# 有的文章,在该句末尾加上了with grant option,一般不用写
|
||
# 下面一段话引用自:with grant option作用_玉溪人在昌平的博客-CSDN博客
|
||
# with grant option的意思是:权限赋予/取消是关联的,
|
||
# 如将with grant option用于对象授权时,被授予的用户也可把此对象权限授予其他用户或角色,
|
||
# 不同的是但管理员收回用with grant option授权的用户对象权限时,权限会因传播而失效,
|
||
# 如grant select on table with grant option to A,A用户把此权限授予B,
|
||
# 但管理员收回A的权限时,B的权限也会失效,但管理员不可以直接收回B的SELECT ON TABLE 权限。
|
||
```
|
||
- 授予权限
|
||
```sql
|
||
# 授权某个用户所有数据库所有权限
|
||
mysql> GRANT ALL PRIVILEGES ON *.* TO "用户名"@"IP/localhost/%";
|
||
|
||
mysql> FLUSH PRIVILEGES;
|
||
```
|
||
#### 创建数据库
|
||
- mysql 5.6 / 5.7:
|
||
```sql
|
||
mysql -uroot -p
|
||
|
||
mysql> CREATE DATABASE dolphinscheduler DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;
|
||
|
||
## 可选步骤
|
||
## 修改 {user} 和 {password} 为你希望的用户名和密码
|
||
# mysql> GRANT ALL PRIVILEGES ON dolphinscheduler.* TO '{user}'@'%' IDENTIFIED BY '{password}';
|
||
# mysql> GRANT ALL PRIVILEGES ON dolphinscheduler.* TO '{user}'@'localhost' IDENTIFIED BY '{password}';
|
||
|
||
mysql> flush privileges;
|
||
```
|
||
- 对于mysql 8:
|
||
```sql
|
||
mysql -uroot -p
|
||
|
||
mysql> CREATE DATABASE dolphinscheduler DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;
|
||
|
||
## 可选步骤
|
||
## 修改 {user} 和 {password} 为你希望的用户名和密码
|
||
# mysql> CREATE USER '{user}'@'%' IDENTIFIED BY '{password}';
|
||
# mysql> GRANT ALL PRIVILEGES ON *.* TO '{user}'@'%';
|
||
mysql> FLUSH PRIVILEGES;
|
||
```
|
||
|
||
|
||
## 参考文档
|
||
- [DolphinScheduler数据源配置](https://github.com/apache/dolphinscheduler/blob/3.2.2-release/docs/docs/zh/guide/howto/datasource-setting.md)
|
||
- [Mysql创建用户](https://blog.csdn.net/qq_41566366/article/details/121763099)
|
||
- [Mysql授权问题](https://blog.csdn.net/weixin_54061333/article/details/117458996) |