我正在使用'postgres'超级用户进行全新的postgresql安装.登录通过:
sudo -u postgres psql
postgres=# createdb database
postgres-# \list
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |
template0 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres
: postgres=CTc/postgres
Run Code Online (Sandbox Code Playgroud)
没有错误,但没有创建表.有任何想法吗?
Sad*_*ida 176
createdb是一个命令行实用程序,您可以从bash运行而不是从psql运行.要从psql创建数据库,请使用如下create database语句:
create database [databasename];
Run Code Online (Sandbox Code Playgroud)
注意:请务必始终使用SQL语句结束 ;
a_h*_*ame 62
迟到了,但接受的答案并没有解释为什么没有显示错误.由于这是Postgres新成员经常偶然发现的事情,我想补充一点.
TL/TR:总是用你的SQL语句结束 ;
因为createdb database没有结束; psql认为声明没有完成并等待更多的输入.这表示提示从更改postgres=#为postgres-#.一个非常微妙的变化,我希望psql做的不同(更"突出").
通过输入元命令\list,"当前"SQL语句被"中止"而不执行它.
如果createdb已经结束;了输出将是:
postgres=> createdb foobar;
ERROR: syntax error at or near "createdb"
LINE 1: createdb foobar;
^
postgres=>
清楚地表明出现了问题.
在 PostgreSQL 中创建新数据库非常简单,在 Linux 上执行以下命令(CentOS 7 示例):
sudo -u postgres psql -c "create database MyDb;"
Run Code Online (Sandbox Code Playgroud)
小智 5
使用节点终端,我必须运行:
psql -U postgres
Run Code Online (Sandbox Code Playgroud)
[输入您的密码]
然后 ...
CREATE DATABASE dbadmin;
Run Code Online (Sandbox Code Playgroud)
令人困惑的是,我之前输入了这些相同的命令,但它不起作用。只有在注销并重新登录后,我才能使用文档中的这个标准命令:https : //www.postgresql.org/docs/10/tutorial-createdb.html
| 归档时间: |
|
| 查看次数: |
47229 次 |
| 最近记录: |