一、mysql常用到的操作:
1、数据库操作:
1)、连接数据库:
mysql -u 用户名 -p 密码
2)、退出数据库:
exit/quit/ctrl+d
3)、显示所有的数据库:
show databases;
4)、显示当前数据库时间:
select now();
5)、显示数据库版本:
select version();
6)、创建数据库:
create database 数据库名;
7)、删除数据库:
drop database 数据库名;
8)、查看当前使用的数据库:
select database();
9)、查看创建数据库的语句:
show create database 数据库名;
10)、使用数据库:
use 数据库名
2、数据表操作:
1)、查看当前库中的表:
show tables;
2)、创建表:
create table 表名(字段 类型 约束);
3)、查看表的创建语句:
show create table 表名;
4)、查看表结构:
desc 表名;
5)、添加表字段:
alter table 表名 add 列名 类型 约束;
6)、删除表字段:
alter table 表名 drop 列名;
7)、修改表字段属性:
table 表名 modify 列名 类型 约束;
8)、修改表字段名称:
alter table 表名 change 原名 新名 类型 约束;
9)、删除表:
drop table 表名;
3、数据的增删改查:
查询:
1)、查询所有的列:select * from表名;
2)、指定查询条件:select * from 表名 where 条件;
3)、查询指定列: select 列名 from 表名;
4)、指定别名:select 列名 as 别名 form 表名;
增加:
1)、全列插入:insert into 表名 values(........);
2)、部分插入:insert into 表名 (列名...)values(值.....)
3)、多行插入:insert into 表名 values(....),(....),(....)
修改:
pudate 表名 set 列名=值 where 条件;
删除:
delete from 表名 where 表名;
逻辑删除:
alter table 表名 add 列名 bit default 0;
update 表名 set 列名=1 where 条件;