【问题标题】:Truncate a specific table from a MySQL database using Command Line使用命令行从 MySQL 数据库中截断特定表
【发布时间】:2016-10-19 22:51:09
【问题描述】:

目标

我正在尝试截断数据库中的一张表。


详情

数据库名称:站点本地 表名:cloud_security


我试过了

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

对此的任何提示/建议将不胜感激!

【问题讨论】:

    标签: mysql linux database command-line-interface


    【解决方案1】:

    命令行在数据库和表名中的破折号有问题。

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

    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\`"
    

    【讨论】:

    • 或者用单引号代替双引号,那么反引号就不需要转义了:-e 'truncate table `benu-local`.`cloud_securities`'
    猜你喜欢
    • 2010-12-27
    • 2021-11-05
    • 1970-01-01
    • 2014-09-01
    • 2011-03-02
    相关资源
    最近更新 更多