我正在服务器上执行以下命令以将新条目添加到数据库中:
mysql --useruser --password='password' --database='mydatabase' --execute='INSERT INTO `artist` (`artist_id`, `artist_name`, `name_sorted`, `Discogs_Real_Name`, `Discogs_Search_Name`, `url`, `current_rank`, `previous_rank`, `last_rank_change_date`, `Discogs_ID`, `Discogs_IMG_URL`, `discogs_file_jpg`, `discogs_file_png`, `discogs_file_icon`, `Discogs_Profile`, `musical_id`, `artist_id_new`, `artist_id_feat`) VALUES ('"'$artist_id'"', '"'$discogs_name'"', '"'$discogs_name'"', '"'$discogs_name'"', '"'$discogs_search_name'"', '', '0', '0', '2020-08-28', '"'$discogs_id'"', '"'$discogs_image_url'"', '"'$discogs_new_filename_jpg'"', '', '', '', '"'$musical_id'"', '1', '')';
运行命令后我收到以下错误消息:
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 ' 0, 0, 2020-08-28, '17546', ' https://img.discogs.com/jWSXBLWwmOog3YRLDtGQ_RK95x' at line 1
答案1
单引号内不能有单引号而不转义它们。在单引号内,变量 - 例如 $musical_id - 将不会被解释。