MySQL命令
来源:互联网 发布:mac加密ntfs 编辑:程序博客网 时间:2024/06/09 14:06
连接MySQL服务器
1》mysql -u用户名 -p密码
2》mysql -u用户名 -p
Enter Password:来输入密码
3》mysql -h主机名名称 -u用户名 -p密码
退出MySQL
1》exit
2》quit
3》\q
4》Ctrl+C
mysql -h localhost -u 用戶名 -p密碼 //连接数据表
use desk_show; //使用数据表
show tables; //显示数据表
describe desk6_0; //显示表结构
mysql其他命令:
show databases; 显示数据库
create database name; 创建数据库
use databasename; 选择数据库
drop database name 直接删除数据库,不提醒
show tables; 显示表
describe tablename; 显示具体的表结构
select 中加上distinct去除重复字段
mysqladmin drop databasename
删除数据库前,有提示。
显示当前mysql版本和当前日期
select version(),current_date;
查看已有的数据库:show databases|schemas;
创建数据库:create database [if not exists] 数据库名称 [default]
character set '字符集(UTF-8)';
修改数据库的编码方式:
alter database db_name default character set '字符集';
如需在表中添加列
alter table user add email varchar(50) not null; 向user表中加入email varchar50位不为空
修改username唯一
alter table user modify username varchar(30) unique;
删除数据库drop database [if not exists]
创建数据表create table if not exists 'table_name'(
'字段名称' 字段类型 [字段属性]
...
)
字段属性:
int(3)
[unsigned无符号(+和-)|zerofill]
[not null|null]
not null 配合default 默认值
[primary] key:主键,一个表中只能有一个主键,主键代表唯一,而且
被设置为主键的字段自动不能为空
auto_increment:自增长,对于整型字段有用,一定要命名成主键
unique[key]:代表唯一,值不能重复,一个表中可以有多个字段添加唯一
--注释内容
#注释内容
create table if not exists 'user'(
'id' int unsigned auto_increment key,
'username' varchar(30) not null unique(key)#(varchar为变长,如果是char不管存多少都是固定值)
'password' char(32) not null,
'age' tinyint unsigned default 10 #default为10是给年龄一个默认值
'sex' enum("男","女","保密") default"男",
'addr' varchar(255),
'face' varchar(40) not null default "psd1403.jpeg",
'email' varchar(50) not null defalut '844216765@qq.com',
'vip' tinyint(1) not null default 0 comment"会员,0代表非会员,其余的代表会员",
'startTime' int unsigned comment"会员起始时间",
'endTime' int unsigned comment"会员到期时间",
)
tinyint(1)值为0的时候为false,其余的值都为真1
创建数据表create table if not exists 'table_name'(
'字段名称' 字段类型 [字段属性]
...
)
字段属性:
int(3)
[unsigned无符号(+和-)|zerofill]
[not null|null]
not null 配合default 默认值
[primary] key:主键,一个表中只能有一个主键,主键代表唯一,而且
被设置为主键的字段自动不能为空
auto_increment:自增长,对于整型字段有用,一定要命名成主键
unique[key]:代表唯一,值不能重复,一个表中可以有多个字段添加唯一
--注释内容
#注释内容
create table if not exists 'user'(
'id' int unsigned auto_increment key,
'username' varchar(30) not null unique(key)#(varchar为变长,如果是char不管存多少都是固定值)
'password' char(32) not null,
'age' tinyint unsigned default 10 #default为10是给年龄一个默认值
'sex' enum("男","女","保密") default"男",
'addr' varchar(255),
'face' varchar(40) not null default "psd1403.jpeg",
'email' varchar(50) not null defalut '844216765@qq.com',
'vip' tinyint(1) not null default 0 comment"会员,0代表非会员,其余的代表会员",
'startTime' int unsigned comment"会员起始时间",
'endTime' int unsigned comment"会员到期时间",
)
tinyint(1)值为0的时候为false,其余的值都为真1
--删除admin表中id为1的用户
delect from admin where id=1;
清空表:
truncate [table] table_name;//清空表后在插入值的时候id是从一开始的
truncate和delete的区别
truncate会将auto_increment的值重置为1
--删除admin表中id为1的用户
delect from admin where id=1;
清空表:
truncate [table] table_name;//清空表后在插入值的时候id是从一开始的
truncate和delete的区别
truncate会将auto_increment的值重置为1
--查询
select * from user;
select username,password from user \G;
select username,password ,vip"会员" from user \G;
select * from user as "用户名";
select * from user where username="admin"&& password="123123";
select * from user where username="admin" or age="10";
select * from user where addr is null;
select * from user where username like "%a%"\G;
select * from user where username like "a%"\G;
select * from user where username like "a__"\G;
select * from user where id in(1,2,3,4,5,111,22,6666);
select * from user where id > 1 && id <5;
select count(*)total from user where id betwwen 1 and 5;//包含了1和5
select * from user order by id desc;根据id降序排列
select * from user where id <=3 order by id desc;
select * from table_name limit 显示记录的条数;
代表显示几条记录
select * from user limit 1;
select * from table_name 偏移量,显示记录的条数;
select * from user 0,2;
select * from user where id<=10 order by id desc limit 2,2;//分页的核心就是通过limit来实现的
select * from user;
select username,password from user \G;
select username,password ,vip"会员" from user \G;
select * from user as "用户名";
select * from user where username="admin"&& password="123123";
select * from user where username="admin" or age="10";
select * from user where addr is null;
select * from user where username like "%a%"\G;
select * from user where username like "a%"\G;
select * from user where username like "a__"\G;
select * from user where id in(1,2,3,4,5,111,22,6666);
select * from user where id > 1 && id <5;
select count(*)total from user where id betwwen 1 and 5;//包含了1和5
select * from user order by id desc;根据id降序排列
select * from user where id <=3 order by id desc;
select * from table_name limit 显示记录的条数;
代表显示几条记录
select * from user limit 1;
select * from table_name 偏移量,显示记录的条数;
select * from user 0,2;
select * from user where id<=10 order by id desc limit 2,2;//分页的核心就是通过limit来实现的
阅读全文
0 0
- Mysql命令
- MySql命令
- MySql命令
- MySql命令
- mysql命令
- Mysql 命令
- mysql命令
- MYSQL命令
- Mysql命令
- Mysql命令
- mysql命令
- MYSQL命令
- Mysql命令
- mysql 命令
- mysql命令
- mysql命令
- mysql命令
- mysql命令
- 漏洞--Struts2远程命令执行S2-016
- Android7.0相机兼容处理方法
- 11.20第十三课
- Unsupported major.minor version 52.0
- 使用VideoView 或者SurfaceView 实现视频播放功能
- MySQL命令
- linux下面文件的一些基本操作
- 目标检测之二(传统算法和深度学习的源码学习)
- IF判断括号区别
- c#中public,private,protected,internal的区别
- 使用POI读写word docx文件
- Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Python
- RecyclerView实现瀑布流的效果
- 模拟恶劣网络环境常用的几种解决方案