我是靠谱客的博主 感动星星,这篇文章主要介绍dos界面操作mysql讲解,现在分享给大家,希望可以做个参考。

dos界面操作mysql讲解:
1.首先运行cmd进入dos界面,输入mysql -uroot -proot进入mysql数据库,此处假设安装mysql时设置的用户名和密码均为root.

2.操作mysql命令创建数据库如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
创建一个名称为mydb1的数据库。 create database mydb1; 查看所有数据库 show databases; 创建一个使用utf-8字符集的mydb2数据库。 create database mydb2 character set utf8; 显示mysql的编码格式 show variables like 'character%'; 创建一个使用utf-8字符集,并带校对规则的mydb3数据库。 create database mydb3 character set utf8 collate utf8_general_ci; 显示库的创建信息 show create database mydb3; 删除前面创建的mydb1数据库 drop database mydb1; 查看服务器中的数据库,并把其中某一个库的字符集修改为gbk; alter database mydb2 character set gbk; show create database mydb2; 备份库 1、准备库的数据 create database mydb1; use mydb1; create table test ( id int ); insert into test(id) values(1); 查看表是否创建成功 select * from test; 2、备份库 2.1 退出mysql客户端:quit 2.2 在windows命令行窗口中下执行:mysqldump -uroot -p mydb1>c:test.sql 3、删除库:drop database mydb1; 4、恢复库(1): 4.1 创建库:create database mydb1; 4.2 source c:test.sql (通过执行脚本文件实现) 5、恢复库(2):mysql -uroot -p mydb1<c:test.sql (window命令)

3.创建表及表的相关操作

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
创建一个员工表,并设置编码格式 use mydb1; 进入库 create table employee ( id int, name varchar(20), gender varchar(4), birthday date, entry_date date, job varchar(40), salary double, resume text )character set utf8 collate utf8_general_ci; 查看库中所有表 show tables; 查看表的创建细节 show create table employee; 查看表的结构 desc employee; 在上面员工表的基本上增加一个image列。 alter table employee add image blob; 修改job列,使其长度为60。 alter table employee modify job varchar(60); 删除sex列。 alter table employee drop gender; 表名改为user。 rename table employee to user; 修改表的字符集为utf-8 alter table user character set gbk; show create table user; 列名name修改为username alter table user change column name username varchar(20); 使用insert语句向表中插入一个员工的信息。 insert into employee(id,username,birthday,entry_date,job,salary,resume) values(1,'aaa','1980-09-09','1980-09-09','bbb',1000,'bbbbbbbb'); 查看插入的数据 select * from employee; 使用insert语句向表中插入一个员工的信息。因为存在中文信息,如果character_set_client=utf8,则会插入失败,需修改编码 insert into employee(id,username,birthday,entry_date,job,salary,resume) values(2,'小李子','1980-09-09','1980-09-09','bbb',1000,'bbbbbbbb'); 插入失败后的解决方案 show variables like 'chara%'; set character_set_client=gbk; 如果插入时的编码为gbk格式,显示时的编码为utf8,则会显示失败,显示失败后的解决方案 set character_set_results=gbk; 将所有员工薪水修改为5000元。 update employee set salary=5000; 将姓名为’aaa’的员工薪水修改为3000元。 update employee set salary=3000 where username='aaa'; 将姓名为’aaa’的员工薪水修改为4000元,job改为ccc update employee set salary=4000,job='ccc' where username='aaa'; 将aaa的薪水在原有基础上增加1000元。 update employee set salary=salary+1000 where username='aaa'; 删除表中名称为’zs’的记录。 delete from employee where username='小李子'; 删除表中所有记录。 delete from employee; 使用truncate删除表中记录。 truncate table employee; 查询表中所有学生的信息。 select id,name,chinese,english,math from student; select * from student; 查询表中所有学生的姓名和对应的英语成绩。 select name,english from student; 过滤表中重复数据。 select distinct english from student; 在所有学生的英语分数上加10分特长分。 select name,english+10 from student; 统计每个学生的总分。 select name,(english+chinese+math) from student; 使用别名表示学生分数。 select name as 姓名,(english+chinese+math) as 总分 from student; select name 姓名,(english+chinese+math) 总分 from student; 查询姓名为王五的学生成绩 select * from student where name='王五'; 查询英语成绩大于90分的同学 select * from student where english>90; 查询总分大于200分的所有同学 select * from student where (english+chinese+math)>200; 查询英语分数在 80-90之间的同学。 select * from student where english>80 and english<90; select * from student where english between 80 and 90; 查询数学分数为89,90,91的同学。 select * from student where math=80 or math=90 or math=91; select * from student where math in(80,90,91); 查询所有姓李的学生成绩。 select * from student where name like '李%'; 对数学成绩排序后输出。 select name,math from student order by math; 对总分排序后输出,然后再按从高到低的顺序输出 select name from student order by (math+english+chinese) desc; 对姓李的学生成绩排序输出 select name 姓名,(math+english+chinese) 总分 from student where name like '李%' order by (math+english+chinese) desc; 统计一个班级共有多少学生? select count(*) from student; select count(name) from student; 统计数学成绩大于90的学生有多少个? select count(*) from student where math>90; 统计总分大于250的人数有多少? select count(*) from student where (math+english+chinese)>250; 统计一个班级数学总成绩? select sum(math) from student; 统计一个班级语文、英语、数学各科的总成绩 select sum(math),sum(chinese),sum(english) from student; 统计一个班级语文、英语、数学的成绩总和 select sum(chinese+math+english) from student; 统计一个班级语文成绩平均分 select sum(chinese)/count(chinese) from student; 求一个班级数学平均分? select avg(math) from student; 求一个班级总分平均分 select avg(chinese+english+math) from student; 求班级最高分和最低分 select max(chinese+english+math),min(chinese+english+math) from student; 创建一个产品表 create table orders( id int, product varchar(20), price float ) 插入几条记录 insert into orders(id,product,price) values(1,'电视',900); insert into orders(id,product,price) values(2,'洗衣机',100); insert into orders(id,product,price) values(3,'洗衣粉',90); insert into orders(id,product,price) values(4,'桔子',9); insert into orders(id,product,price) values(5,'洗衣粉',90); 对订单表中商品归类后,显示每一类商品的总价 select product from orders group by product; select product,sum(price) from orders group by product; 查询购买了几类商品,并且每类总价大于100的商品 select product from orders group by product having sum(price)>100;

4.定义表的主键,外键及关系模型一对一,多对多的表的构造

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
定义带有主键约束的表 create table test1 ( id int primary key, name varchar(20), password varchar(20) ); 定义一个主键 自动增长的表 create table test2 ( id int primary key auto_increment, name varchar(20), password varchar(20) ); create table test3 ( id int primary key auto_increment, name varchar(20) unique ); create table test4 ( id int primary key auto_increment, name varchar(20) unique not null ); //什么是外键约束 create table husband ( id int primary key, name varchar(20) ); create table wife ( id int primary key, name varchar(20), husband_id int, constraint husband_id_FK foreign key(husband_id) references husband(id) ); //多对多 create table teacher2 ( id int primary key, name varchar(20), salary double ); create table student2 ( id int primary key, name varchar(20) ); create table teacher_student ( teacher_id int, student_id int, primary key(teacher_id,student_id), constraint teacher_id_FK foreign key(teacher_id) references teacher2(id), constraint student_id_FK foreign key(student_id) references student2(id) ); //一对一 create table person ( id int primary key, name varchar(20) ); create table idcard ( id int primary key, address varchar(40), constraint id_FK foreign key(id) references person(id) );

最后

以上就是感动星星最近收集整理的关于dos界面操作mysql讲解的全部内容,更多相关dos界面操作mysql讲解内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部