PostgreSQL 中创建用户
root@ThinkPad:~# su - postgres
postgres@ThinkPad:/$ which createuser
/usr/bin/createuser
postgres@ThinkPad:/$ createuser UserName
Shall the new role be a superuser? (y/n) y
=#
建立数据库 dbname
psql
postgres=#
另外, 为安全起见, 建立普通用户 haifeng, 密码为 Passwd, 但不能创建数据库.
postgres=# create user "haifeng" with password 'Passwd' nocreatedb;
利用管理员 postgres 为用户 haifeng 创建数据库 dbname
createdb DATABASE "dbname" with owner="haifeng";
(上面一行中 createdb 应改为 create)
使用用户名 haifeng 登录数据库 dbname,
root@ThinkPad:~# psql -h 127.0.0.1 -U haifeng -d dbname
Password for user haifeng: (输入密码Passwd)
从sql文件导入到数据库
/usr/local/pgsql/bin/psql -h localhost -U haifeng -d dbname -f /tmp/dbname.sql
备注:
如果将 create 和 database 放在一行上输入会有问题
create
database
会有问题