PostgreSQL与MySQL常用命令比较[转]
PostgreSQL与MySQL常用命令比较
原文链接:
PostgreSQL |
MySQL |
服务启动: |
服务启动:
MySQL的进程号为1663 |
第一次进入数据库: |
第一次进入数据库: #mysql |
创建用户:(用户Ajian,密码:123) $psql =#create user ajian with password ‘123’ |
创建用户:(用户Ajian,密码: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 (查看数据库) =#\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 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现