MySQL and Postgres command equivalents (mysql vs psql)
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).
MySQL (using mysql) Postgres (using psql) Notes
| \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 and Postgres command equivalents (mysql vs psql)的更多相关文章
- # mysql -u root -p -bash: mysql: command not found
[root@jboss ~]# mysql -u root -p-bash: mysql: command not found 需要安装mysql # yum install mysql之后就行 了
- MySQL 5.7 Command Line Client输入密码后闪退和windows下mysql忘记root密码的解决办法
MySQL 5.7 Command Line Client输入密码后闪退的问题: 问题分析: 1.查看mysql command line client默认执行的一些参数.方法:开始->所有程序 ...
- Uber从Postgres切换到MySQL
Uber工程师在官方博客上描述了他们为什么要从 Postgres 切换到 MySQL 数据库.Uber的早期架构是由 Python编写的后端应用构成,使用了 Postgres 数据库.但此后,Uber ...
- MySQL中MySQL X.X Command Line Client一闪而过的问题
问题介绍:我安装完MySQL(我安装的是5.5)后,使用MySQL 5.5 Command Line Client,每次点击,总是一闪而过.解决方法如下: 首先进入cmd 切入MySQL的安 ...
- 转:为什么Uber宣布从Postgres切换到MySQL?
转: http://mp.weixin.qq.com/s?__biz=MzAwMDU1MTE1OQ==&mid=2653547609&idx=1&sn=cbb55ee823dd ...
- Mac os安装MySQL数据库,系统提示mysql: command not found该怎么办
当我们安装好MySQL后,在终端输入mysql命令,发现并不能看到自己安装的数据库,这是因为你没有配置环境变量. 在os系统中安装MySQL数据库默认保存在/usr/local/mysql 那么我们应 ...
- MySQL中 MySQL X.X Command Line Client 一闪而过
问题介绍:我安装完MySQL(我安装的是5.5)后,使用MySQL 5.5 Command Line Client,每次点击,总是一闪而过. 从网上我查了下,都是暂时的解决的方法,不能够解决使点击 M ...
- 创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL
创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL 用惯.NET的研发人员都习惯性地使用SQLServer作为数据库.然而.NET Core ...
- linux下安装MySQL出错file /usr/share/mysql/charsets/latin2.xml from install of MySQL-......
linux64 red hat 6.3企业版 开始错误装了32位mysql最后怎么也装不上64mysql了,折腾了一番最后全部卸载搞定: file /etc/init.d/mysql from ins ...
随机推荐
- android夜间模式实现
一.概述 android夜间模式实现分为两大类 重启activity的实现 不重启activity的实现 二.正文 1.重启activity实现夜间模式[在界面文件中的实现部分] 1.1在attrs. ...
- Codeforces Round #192 (Div. 2)
吐槽一下,这次的CF好简单啊. 可是我为什么这么粗心这么大意这么弱.把心沉下来,想想你到底想做什么! A 题意:O(-1) 思路:O(-1) #include <iostream> #in ...
- phpexcel的写操作将数据库中的数据导入到excel中
这个版本据说是可以支持excel2007,但是我使用2007编辑的xlsx是无法获得该库的支持.于是乎我就将它转化为2003.感觉支持地很好. 下面介绍一下具体的使用: require_once('. ...
- mongodb备忘
1.远程拷贝数据库 db.copyDatabase(fromdb, todb, fromhost, [dbuser, dbpassword]) 2.数据库备份/恢复(导出/导入) mongoexpor ...
- php初学第一课
php:强大的脚本语言 B/S:brower:浏览器 server:服务器 C/S: client:客户端 server:服务器 一.php嵌入页面的标记 1. <?php ?> # ...
- response的Writer输出数据的问题
package cn.itcast.response; import java.io.IOException; import java.io.OutputStream; import java.io. ...
- Empire C:Basic 3
首先我们定义一个表示年龄的指针: int* page: 这就是定义了一个指针,和定义普通变量就多了一个*符号而已. 为什么变量名用了p开头,这里引用了英文pointer(指向),表示它是一个指针,而非 ...
- Yii源码阅读笔记(二十一)——请求处理流程
Yii2请求处理流程: 首先:项目路径/web/index.php (new yii\web\Application($config))->run();//根据配置文件创建App实例,先实例化y ...
- iOS开发-Masonry简易教程
关于iOS布局自动iPhone6之后就是AutoLayOut,AutoLayOut固然非常好用,不过有时候我们需要在页面手动进行页面布局,VFL算是一种选择,如果对VFL不是很熟悉可以参考iOS开发- ...
- chomre常用快捷键
Ctrl+T 打开新标签页. 按住 Ctrl 键的同时点击链接.或用鼠标中键(或鼠标滚轮)点击链接. 从后台在新标签页中打开链接. ...