1,进入安装目录(要根据自己安装时的情况而定)
[root@localhost bin]# pwd
/opt/PostgreSQL/9.4/bin
[root@localhost bin]# ll *create*
-rwxr-xr-x 1 root daemon 54187 Dec 6 14:39 createdb
-rwxr-xr-x 1 root daemon 63879 Dec 6 14:39 createlang
-rwxr-xr-x 1 root daemon 56901 Dec 6 14:39 createuser
[root@localhost bin]#
2,执行创建数据库命令:(这里要输入安装时输入的密码)
[root@localhost bin]# ./createdb mydb
Password:
Password:
createdb: could not connect to database template1: FATAL: password authentication failed for user "root"
[root@localhost bin]#
3,根据上面输入的情况可以知道root用记没有权限可以通过修改以下的配置文件进行修改。
-bash-3.2$ pwd
/opt/PostgreSQL/9.4/data
-bash-3.2$ ll pg_hba.conf
-rw------- 1 postgres postgres 4214 Dec 19 04:16 pg_hba.conf
-rwxr-xr-x 1 root root 3045 Dec 19 04:16 postgresql-9.4
-bash-3.2$ pwd
/etc/init.d
-bash-3.2$ postgresql-9.4 reload
(重新加载配置 note:这里要切换到用户 postgres执行)
再执行 createdb mydb 创建数据库(这里要输入密码才可以创建)
使用psql 命令进入创建的数据查看(如下)
$ psql mydb
If you do not supply the database name then it will default to your user account name. You already
discovered this scheme in the previous section using createdb.
In psql, you will be greeted with the following message:
psql (9.0.22)
Type "help" for help.
mydb=>
The last line could also be:
mydb=#
hell=# select version();
version
------------------------------------------------------------------------------------------------------
--
PostgreSQL 9.4.5 on i686-pc-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55), 32-bi
t
(1 row)
hell=# select current_date;
date
------------
2015-12-19
(1 row)
hell=#