Mysql碰到的一些命令与错误

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. 更新数据出错

错误信息:

1
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.

解决方案:

1
set SQL_SAFE_UPDATES = 0;

原因: Mysql有个叫SQL_SAFE_UPDATES的变量,为了数据库更新操作的安全性,此值默认为1。

2. 导入CSV文件

导入CSV文件的命令为:

1
2
3
4
load data local infile '/Users/ltc/Downloads/test.csv' 
into table `test`
fields terminated by ',' optionally enclosed by '"' escaped by '"'
lines terminated by '\n';

碰到的错误:

1
Error Code: 13. Can't get stat of '/Users/ltc/Downloads/test.csv' (Errcode: 13 - Permission denied)

infile前面缺少local,因为导入的是本地文件。

3. 清空某个table

命令为:

1
truncate table tablename;

上面的命令特别之处在于能清理含有自增主键的数据库表。

如果有收获,可以请我喝杯咖啡!