我通过python将一个数据帧作为表( table -name = tips)导入到mysql服务器。在此过程中,我意外地向mysql服务器添加了名为"index“和"Unnamed: 0”的列。我尝试了不同的方法来删除列,如下所示。
alter table tips drop 'index';
alter table tips drop column 'index';
alter table tips drop [index];
alter table tips drop ['index'];对于上面列"index“的所有语句,下面都是错误的。
ERROR 1064 (42000): 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 ''index'' at line 1我对'Unnamed: 0‘也做了同样的尝试
alter table tips drop 'Unnamed: 0';
alter table tips drop column 'Unnamed: 0';
alter table tips drop [Unnamed: 0];
alter table tips drop ['Unnamed: 0'];对于上面关于"Unnamed: 0“的所有语句,下面都是错误。
ERROR 1064 (42000): 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 ''Unnamed: 0'' at line 1发布于 2019-04-18 10:33:47
当列名包含保留字或无效字符时,需要用反引号(`)将其引起来。改用下面的代码:
alter table tips drop column `index`, drop column `Unnamed: 0`https://stackoverflow.com/questions/55738260
复制相似问题