1:虚拟机安装 centos7 默认 用户名my ,密码my :CentOS-7-x86_64-DVD-1708.zip
2:复制文件到系统:hgdb6.0.2-enterprise-centos7-x86-64-20210222.rpm(无法拷贝时 使用 MobaXterm_Personal_20.1)
3:安装到opt
rpm -ivh hgdb6.0.2-enterprise-centos7-x86-64-20210222.rpm
4: 新建data
mkdir -p /opt/HighGo6.0.2-cluster/data
5:添加环境变量 到 /home/.bash_profile
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/opt/HighGo6.0.2-cluster/bin
export HG_BASE=/opt/HighGo6.0.2-cluster
export HGDB_HOME=/opt/HighGo6.0.2-cluster
export PGPORT=5866
export PGDATABASE=highgo
export PGDATA=$HGDB_HOME/data
export LD_LIBRARY_PATH=/usr/lib64:/opt/HighGo6.0.2-cluster/lib:$LD_LIBRARY_PATH
export PATH
生效:source /home/.bash_profile
6:初始化数据库
initdb -D /opt/HighGo6.0.2-cluster/data
报错: initdb: error: could not access directory "/opt/HighGo6.0.2-cluster/data": Permission denied
以下是在 CentOS 7 系统上解决此权限问题的步骤:
检查目录权限:
打开终端并输入以下命令来检查 /opt/HighGo6.0.2-cluster/data 目录的当前权限设置。
ls -ld /opt/HighGo6.0.2-cluster/data
确认目录的所有者:
使用以下命令确认该目录的所有者和所属组。
stat -c "%U %G" /opt/HighGo6.0.2-cluster/data
如果所有者或所属组不是预期的数据库用户或组,您需要更改它们。
更改目录所有权:
使用 chown 命令将 /opt/HighGo6.0.2-cluster/data 目录的所有者更改为合适的用户(例如,如果您的数据库用户是 my)。
sudo chown my: my /opt/HighGo6.0.2-cluster/data
设置适当的目录权限:
数据库数据目录通常需要较严格的权限设置。使用以下命令为目录设置仅所有者可读写执行的权限。
sudo chmod 700 /opt/HighGo6.0.2-cluster/data
重新初始化:(root 下用my账户)
sudo -u my /opt/HighGo6.0.2-cluster/bin/initdb -D /opt/HighGo6.0.2-cluster/data
然后输入复杂的密码完成:提示如下:(密码需要是大写小写数字和符号的组合。。。。。密码My123@)
The files belonging to this database system will be owned by user "my".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
Data encryption is disabled.
Enter new superuser password:
Enter it again:
fixing permissions on existing directory /opt/HighGo6.0.2-cluster/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... America/Los_Angeles
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "md5" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/opt/HighGo6.0.2-cluster/bin/pg_ctl -D /opt/HighGo6.0.2-cluster/data -l logfile start
[root@localhost HighGo6.0.2-cluster]#
7: 启动(使用my用户)
./pg_ctl -D /opt/HighGo6.0.2-cluster/data -l logfile start
报错:
waiting for server to start..../bin/sh: logfile: Permission denied stopped waiting pg_ctl: could not start server Examine the log output.
修改后启动:(sudo u my ./pg_ctrl …..)
./pg_ctl -D /opt/HighGo6.0.2-cluster/data -l /tmp/logfile start
8:登录数据库进行编辑,命令
/opt/HighGo6.0.2-cluster/bin/psql -U my -d postgres
提示:psql: error: could not connect to server: FATAL: database "postgres" does not exist
然后新加一个database(这条命令将以用户 " my" 创建一个新的 "postgres" 数据库。如果你无法连接到任何数据库,你可能需要首先以 "template1" 连接)
/opt/HighGo6.0.2-cluster/bin/psql -U my -d template1 -c "CREATE DATABASE postgres;"
重新进入:
9: 参照pdf,设置如下
修改文件 pg_hba.conf文件
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 0.0.0.0/0 md5
同时修改 postgresql.conf 文件如下:
listen_addresses = '*'# what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5866# (change requires restart)
修改完重启
/opt/HighGo6.0.2-cluster/bin/pg_ctl reload -D /opt/HighGo6.0.2-cluster/data
提示:server signaled
/opt/HighGo6.0.2-cluster/bin/pg_ctl stop -D /opt/HighGo6.0.2-cluster/data
提示:waiting for server to shut down.... done
server stopped
/opt/HighGo6.0.2-cluster/bin/pg_ctl start -D /opt/HighGo6.0.2-cluster/data
提示:waiting for server to start....2024-01-15 17:30:25.645 PST [100989] LOG: starting HighGo Database 6 Release 6.0.2-64-bit Production
2024-01-15 17:30:25.646 PST [100989] LOG: listening on IPv4 address "0.0.0.0", port 5866
2024-01-15 17:30:25.646 PST [100989] LOG: listening on IPv6 address "::", port 5866
2024-01-15 17:30:25.648 PST [100989] LOG: listening on Unix socket "/tmp/.s.PGSQL.5866"
2024-01-15 17:30:25.673 PST [100989] LOG: This is a trial edition, validate until 2025-01-14 02:43:56.
2024-01-15 17:30:25.694 PST [100990] LOG: database system was shut down at 2024-01-15 17:30:18 PST
2024-01-15 17:30:25.704 PST [100989] LOG: database system is ready to accept connections
done
server started
登录数据库
/opt/HighGo6.0.2-cluster/bin/psql -U my -d postgres
提示输入密码(My123@):
Password for user my:
psql (HighGo Database 6 Release 6.0.2-64-bit Production)
PSQL: Release HighGo Database 6 Release 6.0.2-64-bit Production
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------+----------+-------------+-------------+-------------------
highgo | my | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | my | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | my | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/my +
| | | | | my=CTc/my
template1 | my | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/my +
| | | | | my=CTc/my
(4 rows)
postgres=#
命令行可以输入命令,建立库表:
创建数据源:create database test
查询数据库 \l
连接到数据库:\c test
创建表 :create table student(
Name varchar(10),
age int );
查看所有表:\dt
添加数据:insert into student values(“ zs” , 10);
查看数据:select * from student;
10 :设置完成之后 使用 Navicat Premium11 远程连接数据库;
新建连接,测试连接失败,需要关闭虚拟机中的防火墙;如下输入设置,重新连接,连接成功。
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service
#systemctl stop NetworkManager.service
#systemctl disable NetworkManager.service
#systemctl status NetworkManager.service
#systemctl start NetworkManager.service