我是一个postgreSQL新手,我找不到任何有用的使用psql命令的介绍。至少我认为这是我想要使用的命令。
在postgreSQL中,是否可以简单地连接到服务器,然后列出、创建、使用和检查数据库?
我希望能够使用psql对MySQL做类似的事情(我已经删除了许多额外的行):
在不指定数据库的情况下连接-我似乎不能用psql做到这一点:
$ mysql -u root -prootpassword
Welcome to the MySQL monitor. Commands end with ; or \g.
Server version: 5.5.28 MySQL Community Server (GPL)我可以用mysql列出数据库,但posgreSQL命令SHOW似乎不能做到这一点。
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| ocdp |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.04 sec)我可以切换数据库。
mysql> use ocdp;
Database changed我不能理解psql中的这个命令:
mysql> show tables;
+---------------------------------+
| Tables_in_ocdp |
+---------------------------------+
| OCAddresses |
| OCStreets |
+---------------------------------+
2 rows in set (0.00 sec)我想我可以在psql中使用'createdb‘和'dropdb’命令做到这一点:
mysql> create database foo;
Query OK, 1 row affected (0.00 sec)
mysql> drop database foo;
Query OK, 0 rows affected (0.03 sec)我使用\退出
mysql> quit
Bye对于了解postgreSQL的人来说,回答这些问题应该只需要几分钟的时间,但是我在任何地方都找不到说明如何执行这些简单操作的文档。也许我根本不应该为此使用psql?
发布于 2013-02-06 03:34:55
连接到服务器:
$ mysql -u root -prootpassword
$ su - postgres
$ psql列出数据库:
mysql> show databases;
postgres=# \l交换机数据库:
mysql> use ocdp;
postgres=# \c ocdp显示表:
mysql> show tables;
postgres=# \dt创建数据库:
mysql> create database foo;
postgres=# create database foo;删除数据库:
mysql> drop database foo;
postgres=# drop database foo;退出:
mysql> quit
postgres=# \q发布于 2015-12-18 14:22:53
如果您正在使用Mac-OS-X和postgres 9.4,请尝试使用此命令
psql --列表
发布于 2016-11-22 12:44:44
带终端的Postgresql
进入postgresql
sudo -u postgres psql在postgresql中查找数据库列表
$ \l通过以下命令连接到数据库
$ \c databasename按以下方式查看数据库中的模型
$ \dt现在,将显示数据库中存在的表列表,并对这些表执行如下操作
$ select * from table;https://stackoverflow.com/questions/14714953
复制相似问题