PostgreSQL与MySQL命令的使用比较
前端之家收集整理的这篇文章主要介绍了
PostgreSQL与MySQL命令的使用比较,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
502_0@
服务启动:
1)#service postgresql start
2)#/etc/init.d/postgresql start
3)#su postgresql
$ pg_ctl start
Postgresql的进程号:1210、1207、
创建用户:(用户Ajian,密码:123)
#su – postgres
$ psql
=#create user ajian with password ‘123’
创建用户:(用户Ajian,密码:123)
#grant all privileges on *.* to<a href="mailto:ajian@" %'="" style="padding: 0px; margin: 0px; color: rgb(103,88,29); text-decoration: none;">
ajian@"%
" identified by "123"
(注意:同还可以分配权限,这里是ALL)
创建
数据库(My):
#su – postgres
$p
sql
=#create database My with owner = ajian template = template1 encoding=’UNICODE’;
创建
数据库(My):
1)#
MysqL
MysqL>create database My;
2)#
MysqLadmin create My
新建
用户登录:
(首先
修改配置文件)
# vi /var/lib/pg
sql/data/pg_hba.conf(在最后加)
host all all 127.0.0.1 255.255.255.255 md5
再重启服务:#service postgre
sql restart
登录:#p
sql –h 127.0.0.1 –U ajian My
Password:
创建表(employee):
=#create table employee(
(#employee_id int primary key,
(#name char(8),
(#sex char(2));
创建表:
>create table employee(
->employee_id int primary key,
->name char(8),
->sex char(2));
查看表:
=#\dt
查看表:
>show tables;
查看表的结构:
=#\d employee
查看表的结构:
>sescribe employee;
向表中
添加数据:
=#insert into employee values
-#(‘1’,’zhang’,’F’);
-#(‘2’,’chen’,’M’,);
向表中
添加数据:
>insert into employee values
->(‘1’,’F’);
->(‘2’,);
查看表的数据:
=#select * from emlpoyee
查看表的数据:
>select * from emlpoyee;
创建索引(IN_employee):
=#create index IN_employee on employee(name);
查看索引:
=#\di
删除索引:
=#drop index IN_employee on employee;
重建索引:
=#reindex table employee;(重建employee所有的)
=#reindex index IN_employee;(重建指定的)
创建索引(IN_employee):
1)>create index IN_employee on employee(name);
2)>alter table employee add index IN_employee(name);
查看索引:
>show index from employee;
删除索引:
1)>drop index IN_employee on employee;
2)>alter table emlpoyee drop index IN_employee;
删除表:
=#drop table employee;
删除表:
>drop table employee;
删除数据库:(注意命令前面的标志) 1)=#drop database ajian; 2)$dropdb ajian 删除数据库:(注意命令前面的标志) 1)>drop database ajian; 2)#MysqLadmin drop ajian
原文链接:https://www.f2er.com/postgresql/194702.html