折腾:
中,要把:
MariaDB [guanzhi_removeDuplicate]> ALTER TABLE selection ADD created_at_gmt8 int(10) after created_at; Query OK, 2273 rows affected (1.33 sec) Records: 2273 Duplicates: 0 Warnings: 0 MariaDB [guanzhi_removeDuplicate]> SHOW COLUMNS from selection; +—————–+————-+——+—–+———+—————-+ | Field | Type | Null | Key | Default | Extra | +—————–+————-+——+—–+———+—————-+ | id | int(10) | NO | PRI | NULL | auto_increment | | staff_id | int(10) | NO | MUL | NULL | | | car_sn | varchar(10) | NO | | NULL | | | bid_price | int(10) | NO | | NULL | | | created_at | int(10) | NO | | NULL | | | created_at_gmt8 | int(10) | YES | | NULL | | | sequence | int(10) | NO | | NULL | | +—————–+————-+——+—–+———+—————-+ 7 rows in set (0.00 sec) MariaDB [guanzhi_removeDuplicate]> |
中的:
created_at_gmt8
改为NOT NULL
即:
MariaDB [guanzhi_removeDuplicate]> SHOW COLUMNS from selection; +—————–+————-+——+—–+———+—————-+ | Field | Type | Null | Key | Default | Extra | +—————–+————-+——+—–+———+—————-+ | id | int(10) | NO | PRI | NULL | auto_increment | | staff_id | int(10) | NO | MUL | NULL | | | car_sn | varchar(10) | NO | | NULL | | | bid_price | int(10) | NO | | NULL | | | created_at | int(10) | NO | | NULL | | | created_at_gmt8 | int(10) | NO | | NULL | | | sequence | int(10) | NO | | NULL | | +—————–+————-+——+—–+———+—————-+ 7 rows in set (0.00 sec) MariaDB [guanzhi_removeDuplicate]> SELECT * from selection LIMIT 10; +—-+———-+——–+———–+————+—————–+———-+ | id | staff_id | car_sn | bid_price | created_at | created_at_gmt8 | sequence | +—-+———-+——–+———–+————+—————–+———-+ | 1 | 287 | 13 | 99800 | 1453253772 | 0 | 13 | | 2 | 287 | 15 | 109119 | 1453253772 | 0 | 15 | | 3 | 160 | 46 | 45000 | 1453253789 | 0 | 46 | | 4 | 160 | 64 | 38888 | 1453253789 | 0 | 64 | | 5 | 160 | 77 | 45000 | 1453253789 | 0 | 77 | | 6 | 160 | 82 | 63000 | 1453253789 | 0 | 82 | | 7 | 160 | 83 | 50010 | 1453253789 | 0 | 83 | | 8 | 160 | 84 | 50000 | 1453253789 | 0 | 84 | | 9 | 160 | 85 | 47818 | 1453253789 | 0 | 85 | | 10 | 160 | 88 | 71800 | 1453253789 | 0 | 88 | +—-+———-+——–+———–+————+—————–+———-+ 10 rows in set (0.00 sec) |
是从created_at获得对应的GMT的时间后,算出GMT+8的时间,然后去设置created_at_gmt8列的值
mysql change column type
mysql – How do I Alter Table Column datatype on more than 1 column? – Stack Overflow
How do I change the data type for a column in MySQL? – Stack Overflow
MySQL :: MySQL 5.7 Reference Manual :: 13.1.7 ALTER TABLE Syntax
直接modify:
MariaDB [guanzhi_removeDuplicate]> ALTER TABLE selection MODIFY created_at_gmt8 int(10) NOT NULL; Query OK, 2273 rows affected, 2273 warnings (1.22 sec) Records: 2273 Duplicates: 0 Warnings: 2273 MariaDB [guanzhi_removeDuplicate]> SHOW COLUMNS from selection; +—————–+————-+——+—–+———+—————-+ | Field | Type | Null | Key | Default | Extra | +—————–+————-+——+—–+———+—————-+ | id | int(10) | NO | PRI | NULL | auto_increment | | staff_id | int(10) | NO | MUL | NULL | | | car_sn | varchar(10) | NO | | NULL | | | bid_price | int(10) | NO | | NULL | | | created_at | int(10) | NO | | NULL | | | created_at_gmt8 | int(10) | NO | | NULL | | | sequence | int(10) | NO | | NULL | | +—————–+————-+——+—–+———+—————-+ 7 rows in set (0.00 sec) MariaDB [guanzhi_removeDuplicate]> |
[总结]
直接用之前的设置column的属性,类型,去modify即可:
ALTER TABLE selection MODIFY created_at_gmt8 int(10) NOT NULL; |
即可修改其属性了。
转载请注明:在路上 » [已解决]mysql修改已有列的属性