Mysql error adding table to script

Mysql error (don't laugh, please)

I created a script that creates a statistics table for my site. This script creates more than 2000 tables that are used for different statistics with a different level of detail, for example:

  • year tables
  • daily tables
  • tables
  • user_agent tables

etc. (do not ask me why this was done by the previous so-called architect - they wrote in less than 0.02 seconds)

So, I updated the script to add new tables, but made a mistake.

I put a space in the table name and now I can not delete it. so I'm trying to put \ to avoid it, but failed:

root@summary :reports> drop table xd_2012_02_\ ua; ERROR: Unknown command '\ '. 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 '\ ua' at line 1 
+4
source share
2 answers

You must use ` . This will process the string passed as the actual name of the table, not the bunch of commands you want to execute.

 root@summary :reports> drop table `xd_2012_02_\ ua`; 

This should show:

 Query OK, 0 rows affected (0.00 sec) 

I would recommend using ` not only for this case, but also preventing errors if you use reserved MySQL words such as type or desc (as a description) for columns or table names. This can save you a headache later. Although the use of reserved or special characters is not good practice, it’s just me.

+8
source

use this syntax:

 drop table \`xd_2012_02 ua\`; 

this should work with space

0
source

Source: https://habr.com/ru/post/1399503/


All Articles