From: http://blog.endpoint.com/2009/12/mysql-and-postgres-command-equivalents.html
Posted by Greg Sabino Mullane |December 24, 2009
Users toggling between MySQL and Postgres are often confused by the equivalent commands to accomplish basic tasks. Here's a chart listing some of the differences between the command line client for MySQL (simply called mysql
), and the command line client for Postgres (called psql
).
\c Clears the buffer | \r (same) | |
\d string Changes the delimiter | No equivalent | |
\e Edit the buffer with external editor | \e (same) | Postgres also allows \e filename which will become the new buffer |
\g Send current query to the server | \g (same) | |
\h Gives help - general or specific | \h (same) | |
\n Turns the pager off | \pset pager off (same) | The pager is only used when needed based on number of rows; to force it on, use \pset pager always |
\p Print the current buffer | \p (same) | |
\q Quit the client | \q (same) | |
\r [dbname] [dbhost] Reconnect to server |
\c [dbname] [dbuser] (same) |
|
\s Status of server | No equivalent | Some of the same info is available from the pg_settings table |
\t Stop teeing output to file | No equivalent | However, \o (without any argument) will stop writing to a previously opened outfile |
\u dbname Use a different database | \c dbname (same) | |
\w Do not show warnings | No equivalent | Postgres always shows warnings by default |
\C charset Change the charset | \encoding encoding Change the encoding | Run \encoding with no argument to view the current one |
\G Display results vertically (one column per line) | \x (same) |
Note that \G is a one-time effect, while \x is a toggle from one mode to another. To get the exact same effect as \G in Postgres, use \x\g\x
However, you can enable \G mysql style formatting on a per-query basis in psql by putting the following in ~/.psqlrc(windows: %appData%/Roaming/postgresql/psqlrc.conf), and replace ";" with ":G" at the end of each query:
|
\P pagername Change the current pager program | Environment variable PAGER or PSQL_PAGER | |
\R string Change the prompt | \set PROMPT1 string (same) | Note that the Postgres prompt cannot be reset by omitting an argument. A good prompt to use is:\set PROMPT1 '%n@%m:%> %/%R%#%x%x%x ' |
\T filename Sets the tee output file | No direct equivalent | Postgres can output to a pipe, so you can do: \o | tee filename |
\W Show warnings | No equivalent | Postgres always show warnings by default |
\? Help for internal commands | \? (same) | |
\# Rebuild tab-completion hash | No equivalent | Not needed, as tab-completion in Postgres is always done dynamically |
\! command Execute a shell command | \! command (same) | If no command is given with Postgres, the user is dropped to a new shell (exit to return to psql) |
\. filename Include a file as if it were typed in | \i filename (same) | |
Timing is always on | \timing Toggles timing on and off | |
No equivalent | \t Toggles 'tuple only' mode | This shows the data from select queries, with no headers or footers |
show tables; List all tables | \dt (same) | Many also use just \d, which lists tables, views, and sequences |
desc tablename; Display information about the given table | \d tablename (same) | |
show index from tablename; Display indexes on the given table | \d tablename (same) | The bottom of the \d tablename output always shows indexes, as well as triggers, rules, and constraints |
show triggers from tablename; Display triggers on the given table | \d tablename (same) | See notes on show index above |
show databases; List all databases | \l (same) | |
No equivalent | \dn List all schemas | MySQL does not have the concept of schemas, but uses databases as a similar concept |
select version(); Show backend server version | select version(); (same) | |
select now(); Show current time | select now(); (same) | Postgres will give fractional seconds in the output |
select current_user; Show the current user | select current_user; (same) | |
select database(); Show the current database | select current_database(); (same) | |
show create table tablename; Output a CREATE TABLE statement for the given table | No equivalent | The closest you can get with Postgres is to use pg_dump --schema-only -t tablename |
show engines; List all server engines | No equivalent | Postgres does not use separate engines |
CREATE object ... Create an object: database, table, etc. | CREATE object ... Mostly the same | Most CREATE commands are similar or identical. Lookup specific help on commands (for example: \h CREATE TABLE) |
If there are any commands not listed you would like to see, or if there are errors in the above, please let me know. There are differences in how you invoke mysql
and psql
, and in the flags that they use, but that's a topic for another day.
Updates: Added PSQL_PAGER and \o |tee filename, thanks to the Davids in the comments section. Added \t back in, per Joe's comment.
相关推荐
MySQL到PostgreSQL的数据迁移工具——mysql2postgres 在数据库管理领域,经常遇到需要将数据从一个数据库系统迁移到另一个的情况。比如,从MySQL迁移到PostgreSQL。这时,`mysql2postgres`工具就能派上用场。它是一...
MySQL到PostgreSQL的迁移是一项常见的任务,特别是在企业级应用中,由于PostgreSQL的特性或业务需求,可能需要将数据从MySQL迁移到PostgreSQL。在这个过程中,`MysqlToPostgresUtil`工具扮演着重要的角色,它能帮助...
mysql-to-postgres-MySQL至PostgreSQL数据转换 支持MRI或jruby。 master分支支持的最低Ruby版本是2.1.7 ,下一个发行版将具有相同的要求。 使用经过修改的Rails database.yml配置,您可以将mysql-to-postgres集成...
“mysql postgres convert tool”是一款专为Windows平台设计的实用工具,旨在帮助用户轻松实现MySQL与PostgreSQL数据库之间的数据迁移。通过其简洁的界面和高效的操作流程,使得即使是对技术不太熟悉的用户也能顺利...
本项目是一款基于MySQL、Postgres、sqlite和dqlite数据库的Kubernetes运行设计源码,采用Go语言开发,并融入Python和Shell脚本。项目包含84个文件,其中包括42个Go源文件、6个YAML配置文件、3个Markdown文档、2个...
数据库环境:mysql5.6 postgres9.6 数据库表结构文件:db目录下postgres下的main.sql文件 数据库测试数据文件:db目录下的data.sql文件 python环境: python2.7 pip install tornado pip install psycopg2 pip ...
MySQL 迁移到 PostgreSQL 之 Navicat 篇 MySQL 是目前最流行的开源关系数据库管理系统之一,而 PostgreSQL 是另一个功能强大且广泛使用的关系数据库管理系统。在实际工作中,我们经常需要将 MySQL 数据库迁移到 ...
本资源提供了MyBatis Generator 1.3.5版本,包含了针对MySQL、Oracle和PostgreSQL数据库的配置XML以及对应的驱动包。 在使用MyBatis Generator时,首先要了解其核心概念: 1. **配置文件(generatorConfig.xml)**...
《pgloader异构迁移MySQL到PostgreSQL详解》 数据库迁移是一项复杂且重要的任务,尤其是在企业级应用中,数据的安全性和完整性是至关重要的。pgloader作为一款强大的异构数据库迁移工具,特别适用于将MySQL数据库的...
oracleweb 版 linux(终端[终端回放] 文件 脚本 进程 计划任务)、数据库(mysql postgres oracle sqlserver 达梦 高斯 sqlite)、redis(单机 哨兵 集群)、mongo 等集工单流程审批于一体的统一管理操作平web 版 linux...
安装完成后,使用 `postgres` 用户身份启动 `psql`: ```bash sudo -u postgres psql ``` 二、创建用户 在 PostgreSQL 中,用户实际上被称为角色。以下是如何创建新角色的命令: ```sql CREATE USER username ...
passenger-stack, 用于 Apache,乘客,Memcached,Git,Mysql或者Postgres的宋体 ,five分钟至英雄用于 Sprinkle的脚本,提供工具观看演示屏幕铸造的乘客堆栈。如何让你的sprinkle:获取一个品牌打击新片/主机( ...
国外大牛写的一个mysql数据库转换postgresql的脚本。亲试可以无错误运行。
xorm, 面向 Go,支持 mysql,postgres,tidb,sqlite3,sql,oracle的简单和强大的ORM 中文Xorm是一个简单而强大的Go 。 特性结构 <->-表映射支持可以链接的api事务支持ORM和原始SQL操作支持同步数据库架构支持查询...
m2p.set_mysql_config(host='mysql_host', user='mysql_user', password='mysql_password', db='mysql_db') m2p.set_postgresql_config(host='postgresql_host', user='postgresql_user', password='postgresql_...
MYSQL、ORACLE、SQLSERVER、Postgres、Redis数据库等保测评作业指导书V1.1 本文档旨在提供一个综合的数据库等保测评作业指导书,涵盖MYSQL、ORACLE、SQLSERVER、Postgres、Redis等多种数据库管理系统。该指导书旨在...
Create reusable components that bring Bootstrap and Angular together and effectively use materialized views for caching within Postgres. Get your front end working with Webpack, use Postgres' ...
MySQL2PostgreSQLPro.msi
MYSQL、ORACLE、SQLSERVER、Postgres、Redis数据库等保测评作业指导书