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;
MySQL表重命名与结构调整:字符集转换与操作实践
本文详细介绍了如何在MySQL中重命名表(如将`exception`改名为`exception_bak`),创建UTF-8编码表,并执行记录更新、字段修改、插入操作。此外,还展示了如何查看和设置表的字符集,以及如何对数据进行排序。

被折叠的 条评论
为什么被折叠?



