mysql常用命令

一. 数据库操作

1.数据库连接

[root@localhost ~] # mysql -u root -p

Enter password:

2.退出数据库

mysql> exit

Bye

3.创建数据库

create database <数据库名>;

4.显示数据库

show databases;

5.删除数据库

drop database <数据库名>;

6.选择数据库

use <数据库名>;

二. 数据表操作

7.创建数据表

create table <表名> (<字段名1><类型1>,<字段名2><类型2>,...,<字段名n><类型n>);

8.显示数据表

show tables;

9.查看表结构

desc <表名>;

10.删除数据表

drop table <表名>;

11.插入表数据

insert into <表名> (字段名1,字段名2,...字段名n) values (值1,值2,...值N);

12.修改表数据

update 表名 set 字段名1= 新值1,字段名2=新值2,...where 条件表达式1 and(or) 条件表达式2 ...;

13.查询单表数据

select 字段名1,字段名2,...from <表名> where 条件表达式1 and(or) 条件表达式2 ...;

14.查询多表关联数据

(1) 关联查询

select 字段名1,...from 表名1,表名2,... where 关联条件表达式 and 过滤条件表达式 ...;

(2)等值连接

select 字段名1,...from 表名1 inner join 表名2 on 关联条件表达式 and 过滤条件表达式 ...;

(3)左连接

select 字段名1,...from 表名1 left join 表名2 on 关联条件表达式 and 过滤条件表达式 ...;

(4)右连接

select 字段名1,...from 表名1 right join 表名2 on 关联条件表达式 and 过滤条件表达式 ...;

15.删除表数据

delete from 表名 where 条件1 and(or) 条件2 ......

原文地址:https://www.cnblogs.com/gdq8023/p/14781429.html