修改字段默认字符集出错-----mysql数据类型了解

用alter modify修改字段的默认字符集出错,如下情况:

mysql> desc runoob_tbl;
+-----------------+-------------+------+-----+---------+-------+
| Field           | Type        | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| runoob_id       | int(11)     | NO   | PRI | NULL    |       |
| runoob_title    | varchar(10) | YES  |     | NULL    |       |
| runoob_author   | varchar(10) | YES  |     | NULL    |       |
| submission_date | date        | YES  |     | NULL    |       |
+-----------------+-------------+------+-----+---------+-------+
4 rows in set (0.04 sec)

mysql> alter table runoob_tbl modify runoob_id int not null charset utf8;
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'charset utf8' at line 1

原因:列的数据类型不能由数值型与字符型互相转换,只能改为同类的其他类型;charset utf8是针对字符型数据的字符集,不能混用到数值型数据上,属于概念没搞清楚

  • mysql数据类型介绍

参考:作者myxlphttps://www.cnblogs.com/-xlp/p/8617760.html) 

菜鸟教程http://www.runoob.com/mysql/mysql-data-types.html

猜你喜欢

转载自blog.csdn.net/qq_42254088/article/details/81585210