首页 > 数据库技术 > 详细

MySQL 表改表名 更改字符集,更改记录,字段,排序

时间:2015-12-22 13:22:13      阅读:202      评论:0      收藏:0      [点我收藏+]

 

MySQL表 改名 更改字符集,更改记录,字段,排序

【修改表名】
rename table exception to exception_bak;


[创建一个utf8表]
mysql> CREATE TABLE `exception` (mac varchar(30),user varchar(30), model varchar(30) ,Approver varchar(30))DEFAULT CHARSET=utf8;

[查看一个表的详细结构信息]

mysql> show full columns from exception_test;
+----------+-------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
| Field    | Type        | Collation       | Null | Key | Default | Extra | Privileges                      | Comment |
+----------+-------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
| mac      | varchar(30) | utf8_general_ci | YES  |     | NULL    |       | select,insert,update,references |         |
| user     | varchar(30) | utf8_general_ci | YES  |     | NULL    |       | select,insert,update,references |         |
| model    | varchar(30) | utf8_general_ci | YES  |     | NULL    |       | select,insert,update,references |         |
| Approver | varchar(30) | utf8_general_ci | YES  |     | NULL    |       | select,insert,update,references |         |
+----------+-------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
4 rows in set (0.00 sec)


mysql> insert into new_tables (mac) select mac from old_table;
Query OK, 52 rows affected (0.09 sec)
Records: 52  Duplicates: 0  Warnings: 0

【更改记录】
mysql> update exception set user="Unkonw",model="Unkonw",Approver="Unkonw" ;
Query OK, 52 rows affected (0.04 sec)
Rows matched: 52  Changed: 52  Warnings: 0

【更改字段】
mysql> update exception set model="iphone 6" where mac="90:8D:6C:C9:9B:8D";
Query OK, 1 row affected (0.08 sec)
Rows matched: 1  Changed: 1  Warnings: 0


【插入一条记录】
mysql> insert into exception values("90:8D:6C:C9:**:**","***","iphine6"," ***");

【排序】
select * from content order by 字段一 asc ,字段二 asc,字段三 desc想多少字段都行,样式如上!其中:asc或desc(即升级或降序)



【关于字符集】
一、查看MySQL数据库服务器和数据库MySQL字符集。
    mysql> show variables like ‘%char%‘;  

二、查看MySQL数据表(table)的MySQL字符集。
    mysql> show table status from sqlstudy_db like ‘%countries%‘;  

三、查看MySQL数据列(column)的MySQL字符集。
    mysql> show full columns from countries;  



本文出自 “魂斗罗” 博客,请务必保留此出处http://990487026.blog.51cto.com/10133282/1727084

MySQL 表改表名 更改字符集,更改记录,字段,排序

原文:http://990487026.blog.51cto.com/10133282/1727084

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!