MySql 和 PostGres 对照表

MySql 和 PostGres 对照表

初始化数据库

$prefix/bin/mysql_install_db --ldata=XXX --user=mysql

mkdir XXX; $prefix/bin/initdb [-D $prefix/wdb] -W XXX

启动|停止 数据库服务器

$prefix/share/mysql/mysql.server start|stop

pg_ctl -w -D XXX -l $prefix/wdb/xpg_log start|stop

进入命令行

# mysql

# psql postgres

添加用户

mysql$ grant all privileges on *.* to zhangsan@"%" identified by "123"

postgres=# create user ajian with password ‘123’

以某用户身份进入命令行

# mysql -u zhangsan -p

# psql -h 127.0.0.1 -U zhangsan YYY

创建数据库

mysql$ create database YYY;

postgres=# create database YYY

显示数据库

mysql$ show databases;

postgres=# \l

创建表

mysql$ Create table employee(employee_id int primary key, name char(8), sex char(2));

postgres=# create table employee(employee_id int primary key, name char(8), sex char(2));

显示数据表

mysql$ show tables;

postgres=# \dt

显示表结构

mysql$ describe employee;

postgres=# \d employee

插入记录

mysql$ insert into employee values('1','zhang','F');

postgres=# insert into employee values('1','zhang','F');

显示记录

mysql$  select * from employee;

postgres=#  select * from employee;

删除记录

mysql$  delete from employee where employee_id='3';

postgres=# delete from employee where employee_id='3';

删除表

mysql$  drop table employee;

postgres=#  drop table employee;

删除数据库

mysql$  drop database YYY;

postgres=#  drop database YYY;

切换数据库

mysql$ use YYY;

postgres=# \c YYY


你可能感兴趣的:(postgres)