-1

The script is in /etc/cron.daily.


When I had database name = baseName and the table = tableName, the below script to empty the table worked well :

#!/bin/bash

mysql -u root --password=PASSWD -e "DELETE FROM baseName.tableName"

But I needed to rename the database in baseName.fr.value so I basically modified my script to

#!/bin/bash

mysql -u root --password=PASSWD -e "DELETE FROM baseName.fr.value.tableName"

But I got an You have an error in your SQL syntax, check the manual...


So what's the correct syntax when there's a . in the database name ?

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
azro
  • 53,056
  • 7
  • 34
  • 70

1 Answers1

1

In MySQL, you put backticks around database, table, or column names that contain special characters.

mysql -u root --password=PASSWD -e 'DELETE FROM `baseName.fr.value`.tableName'

Note that I changed from double quotes to single quotes, because backticks have special meaning to the shell when used inside double quotes.

See When to use single quotes, double quotes, and back ticks in MySQL and Difference between single and double quotes in Bash.

azro
  • 53,056
  • 7
  • 34
  • 70
Barmar
  • 741,623
  • 53
  • 500
  • 612