mysql字符集,insert,update,delete,select
發(fā)現(xiàn)有錯誤:數(shù)據(jù)太長了。
//查看數(shù)據(jù)庫的所有編碼:
show variables like 'character%';
-----+
| character_set_client???? | utf8??? 設(shè)置客戶端的字符集
???? |
| character_set_connection | utf8??? 設(shè)置連接的字符集
???? |
| character_set_database?? | utf8?設(shè)置數(shù)據(jù)庫的字符集
???? |
| character_set_filesystem | binary??? 設(shè)置文件系統(tǒng)的字符集
???? |
| character_set_results??? | utf8?設(shè)置顯示結(jié)果是使用的編碼
???? |
| character_set_server???? | utf8?設(shè)置配置MySQL時設(shè)置的字符集
???? |
| character_set_system???? | utf8
???? |
| character_sets_dir?????? | C:\Program Files\MySQL\MySQL Server 5.0\share\chars
ets\ |
+--------------------------+----------------------------------------------------
解決亂碼的問題:
1、設(shè)置客戶端的結(jié)果集
2、設(shè)置顯示結(jié)果的字符集
1,set character_set_client=gbk;?? 使用的客戶端編碼
2,set character_set_results=gbk;?結(jié)果集的編碼
創(chuàng)建一張a表
create table a
(
?id int,
?name varchar(20)
);
insert into a values(1,'aaa');
insert into a values('bbbb');//只想添加name時,要把a(name)寫上。
insert into a(name) values('bbbb');
+------+------+
| id?? | name |
+------+------+
|??? 1 | aaa? |
| NULL | bbbb |
+------+------+
實際上into也可以不寫。
insert a values(2,'cccc');
insert a values(3,'dddd');
上面的等價下面的:
insert a value(4,'cccc'),(5,'dddd');
select * from employee;
將所有的員工的薪水修改為5000元
update employee set salary=5000;
將姓名為? zhangsan 的員工的薪水修改為3000元
update employee set salary=3000 where name='zhangsan';
將姓名為 lisi 的員工薪水修改為4000元,sex修改為female
update employee set salary=4000,gender='female' where name='lisi';
將xiaohong的薪水在原有的基礎(chǔ)上增加1000元。
update employee set salary=salary+1000 where name='xiaohong';
set character_set_results=gbk;
3delete語句 刪除數(shù)據(jù)
刪除表中name為zhangsan 的記錄
delete from employee where name='zhangsan';
刪除表中的所有數(shù)據(jù)
delete from employee;
insert into employee
?(id,name,gender,birthday,salary,entry_date,resume)
?values(1,'zhangsan','male','1980-1-1',1000,'2000-3-16','good boy');
insert into employee
?(id,name,gender,birthday,salary,entry_date,resume)
?values(2,'lisi','male','1934-4-1',1000,'2010-3-16','good boy');
insert into employee
?(id,name,gender,birthday,salary,entry_date,resume)
?values(3,'xiaohong','female','1984-1-1',1000,'2008-3-16','good girl');
使用truncate刪除表中的記錄
truncate employee;? 刪除表中的記錄。刪除表在創(chuàng)建表
select * from employee;
insert into employee
?(id,name,gender,birthday,salary,entry_date,resume)
?values(1,'zhangsan','male','1980-1-1',1000,'2000-3-16','good boy');
insert into employee
?(id,name,gender,birthday,salary,entry_date,resume)
?values(2,'lisi','male','1934-4-1',1000,'2010-3-16','good boy');
insert into employee
?(id,name,gender,birthday,salary,entry_date,resume)
?values(3,'xiaohong','female','1984-1-1',1000,'2008-3-16','good girl');
select * from employee;
mysql> select * from employee;
+------+----------+--------+------------+--------+------------+-----------+
| id?? | name???? | gender | birthday?? | salary | entry_date | resume??? |
+------+----------+--------+------------+--------+------------+-----------+
|??? 1 | zhangsan | male?? | 1980-01-01 |?? 1000 | 2000-03-16 | good boy? |
|??? 2 | lisi???? | male?? | 1934-04-01 |?? 1000 | 2010-03-16 | good boy? |
|??? 3 | xiaohong | female | 1984-01-01 |?? 1000 | 2008-03-16 | good girl |
+------+----------+--------+------------+--------+------------+-----------+
4、select 語句
column 指定列名
* 號代表查詢所有列
From 指定查詢哪張表
DISTINCT可選,值顯示結(jié)果時,是否剔除重復(fù)數(shù)據(jù)。
student.sql
create table student
(
?id int,
?name varchar(20),
?chinese float,
?english float,
?math float
);
insert into student(id,name,chinese,english,math) values(1,'張小明',89,78,90);
insert into student(id,name,chinese,english,math) values(2,'李菁',67,53,95);
insert into student(id,name,chinese,english,math) values(3,'王五',87,78,77);
insert into student(id,name,chinese,english,math) values(4,'李一',82,98,92);
insert into student(id,name,chinese,english,math) values(5,'李來才',82,84,67);
insert into student(id,name,chinese,english,math) values(6,'張警報',55,85,45);
insert into student(id,name,chinese,english,math) values(1,'黃蓉',75,65,30);
//查詢所有的學(xué)生的信息
select * from student;
總結(jié)
以上是生活随笔為你收集整理的mysql字符集,insert,update,delete,select的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 发送邮件的代码示例
- 下一篇: 金融界的三架马车是什么