使用命令行从 MySQL 数据库截断特定的 table

Truncate a specific table from a MySQL database using Command Line

目标

我正在尝试截断我的数据库中的一个 table。


详情

数据库名称:站点本地 table 姓名:cloud_securities


我试过了

mysql -u root -p'' -h localhost site-local -e "truncate table site-local.cloud_securities"

结果

输入密码后,一直收到

ERROR 1064 (42000) at line 1: 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 '-local.cloud_securities' at line 1

我该如何解决这个问题?

命令行在 db 和 tablenames 中的破折号有问题。

但是您可以访问客户端然后发送您的语句,必须将 db 和 table 放在反引号中。

mysql -u root -h localhost
truncate table `site-local`.`cloud_securities`;

编辑:nvm,您可以使用反引号从命令行执行此操作,但您必须转义它们。

解法:

mysql -u root -p'' -h localhost site-local -e "truncate table \`site-local\`.\`cloud_securities\`"