postgresql 入门(PostgreSQL 9.4.5) - createdb 问题汇总

本文详细介绍了在使用PostgreSQL时遇到创建数据库时密码验证失败的常见问题,并提供了通过修改配置文件来解决该问题的方法,包括如何重新加载配置文件以及使用正确的命令创建数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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=#



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值