首页 技术 正文
技术 2022年11月7日
0 收藏 914 点赞 330 浏览 2109 个字

PostgreSQL与MySQL常用命令比较

原文链接:

http://www.phpwell.com/?p=174

PostgreSQL

MySQL

服务启动:
1)#service postgresql start
2)#/etc/init.d/postgresql start
3)#su – postgresql
$pg_ctl start
PostgreSQL的进程号:1210、1207、

服务启动:
1)#service mysqld start
2)#/etc/init.d/mysqld start
3)#safe_mysqld&

MySQL的进程号为1663

第一次进入数据库:
#su – postgres
$createdb (建名为postgres的数据库)
$psql

第一次进入数据库:

#mysql
mysql> (出现这个提示符说明成功)

创建用户:(用户Ajian,密码:123)
#su – postgres

$psql

=#create user ajian with password ‘123’

创建用户:(用户Ajian,密码:123)
#grant all privileges on *.* to ajian@”%” identified by “123″

(注意:同还可以分配权限,这里是ALL)

创建数据库(My):

#su – postgres

$psql

=#create database My with owner = ajian template = template1 encoding=’UNICODE’;

创建数据库(My):

1)#mysql

Mysql>create database My;

2)#mysqladmin create My

查看用户和数据库:

#su – postgres

$psql

=#\l (查看数据库)
=#\du (查看用户)

=#\c 从一个数据库中转到另一个数据库中,如template1=# \c sales 从template1转到sales

查看用户和数据库:

1)#mysql

Mysql>show databases; (看数据库)

2)#mysqlshow

use dbname;

新建用户登录:

(首先修改配置文件)

# vi /var/lib/pgsql/data/pg_hba.conf(在最后加)

host all all 127.0.0.1 255.255.255.255 md5

再重启服务:#service postgresql restart

登录:#psql –h 127.0.0.1 –U ajian My

Password:

新建用户登录:

1)#mysql –u ajian –p (带口令登录)

2)#mysql

Mysql>use My;

(不带口令登录一般用于本机)

创建表(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’,’zhang’,’F’);

->(‘2’,’chen’,’M’,);

查看表的数据:

=#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

  http://www.92csz.com/32/1229.html

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,860