A third party has provided a table in CSV format that is named, "KEY.txt". When using mysqlimport to import the file, the following error is returned:
$ mysqlimport fooDB KEY.txt
mysqlimport: Error: 1064, 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 'KEY' at line 1, when using table: KEY
Of course, using reserved words as table and column names is a Bad Idea™. One solution would be to simply rename the file to a non-reserved word, but this is not ideal.
However, MySQL does support using reserved words, as long as the table or column name is put in backtick quotes. The following query from within the mysql client works:
mysql> LOAD DATA LOCAL INFILE 'KEY.txt" INTO TABLE `KEY`;
Records: 303 Deleted: 0 Skipped: 0 Warnings: 0
Is there a way to get mysqlimport to backtick-quote the table name?
As of this writing (v8.0.31 client, v8.0.18 server) mysqlimport does indeed properly handle reserved-word table names as expected, as long as the --delete option isn't specified (as an argument, or in my.cnf).
Related
Hi,I am new to SQL and I wanted to store images in the database.I already created a column with blob data type and tried to execute the following statement as given here
INSERT INTO `abc`
(`img`)
SELECT
BulkColumn FROM OPENROWSET(
Bulk 'C:\Users\adity\Desktop\New folder\a.png', SINGLE_BLOB) AS BLOB
which gives error
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 '(
Bulk C:\Users\name\Desktop\New folder\a.png, SINGLE_BLOB) AS BLOB' at line 4
I also tried following code as given here
insert into table `abc`(`img`) values('C:\Users\name\Desktop\New folder\an.jpg') where id=1;
which gives the error
#1064 - 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 'table abc(img) values('C:\Users\adity\Desktop\New folder\an.jpg') where id=1' at line 1
So please suggest me how to store images in a blob without using php,etc and simply using simple sql insert statement.I am using wamp server for my database.
I know that I should use file system for images instead of using database.But what does a file system actually mean.Does it mean a file or image hosting site whose address will be stored in database.
I think that command is a MSSQL syntax. Try this command:
INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/Users/adity/Desktop/New folder/a.png'))
This command stores image as a BLOB
Through Mysql workbench, its very easy to load images into database using the following steps.
Right click on the value of the (blob)column in the table and select "Load value from file".
Then we can provide the image path in the system.
Then it will converted into byte array and stored it automatically.
finally save the changes of the table.
Below works for me,
However, I was able to get it done by moving the image(fileName.jpg) file first in to below folder(in my case) C:\ProgramData\MySQL\MySQL Server 5.7\Uploads and then I executed below command and it works for me,
INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/an.jpg'));
Hope this helps.
I am trying to use mysql library to request my database.
I need to use the syntax with query placeholders, so I tried a simple request:
connection.query('DROP DATABASE IF EXISTS ?;', ['mydb']);
But this leads to :
'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 \'\'mydb\'\' at line 1'
The query is indeed:
'DROP DATABASE IF EXISTS \'mydb\';'
So how is this supposed to work actually ?
The MySQL notation for this is:
DROP DATABASE IF EXISTS `mydb`
Since you're escaping it as a string, that's not a database reference it can drop.
Some drivers support alternate placeholders for this very reason:
DROP DATABASE IF EXISTS ??
Normally you can't use placeholder values for things like databases, columns or tables as these are treated differently. This is a limitation of the driver.
You just need to be careful on user-supplied values and names with irregular characters in them. These need to be escaped according to MySQL schema identifier rules.
I am having problems getting the SQL "use" command to work in MySQL 5.7.
I have a database 'mydb' with a 'character' table. (At the moment, the table is empty, but I don't think that should matter here).
Explicitly using "use" gives me an error:
use mydb;
select count(*) from character;
Error Code: 1064. 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 'character' at line 1 0.000 sec
However, the following line, which does not use "use", works okay:
select count(*) from mydb.character;
Does anyone know what I am doing wrong? Admittedly, I am quite new to SQL. The full output is shown below:
character is a reserved keyword in MySQL. Hence you get the error when you select from that table. Escape with `` to avoid this. Or use names other than reserved keywords for your tablenames.
Reserved Keywords in MySQL
Hi,I am new to SQL and I wanted to store images in the database.I already created a column with blob data type and tried to execute the following statement as given here
INSERT INTO `abc`
(`img`)
SELECT
BulkColumn FROM OPENROWSET(
Bulk 'C:\Users\adity\Desktop\New folder\a.png', SINGLE_BLOB) AS BLOB
which gives error
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 '(
Bulk C:\Users\name\Desktop\New folder\a.png, SINGLE_BLOB) AS BLOB' at line 4
I also tried following code as given here
insert into table `abc`(`img`) values('C:\Users\name\Desktop\New folder\an.jpg') where id=1;
which gives the error
#1064 - 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 'table abc(img) values('C:\Users\adity\Desktop\New folder\an.jpg') where id=1' at line 1
So please suggest me how to store images in a blob without using php,etc and simply using simple sql insert statement.I am using wamp server for my database.
I know that I should use file system for images instead of using database.But what does a file system actually mean.Does it mean a file or image hosting site whose address will be stored in database.
I think that command is a MSSQL syntax. Try this command:
INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/Users/adity/Desktop/New folder/a.png'))
This command stores image as a BLOB
Through Mysql workbench, its very easy to load images into database using the following steps.
Right click on the value of the (blob)column in the table and select "Load value from file".
Then we can provide the image path in the system.
Then it will converted into byte array and stored it automatically.
finally save the changes of the table.
Below works for me,
However, I was able to get it done by moving the image(fileName.jpg) file first in to below folder(in my case) C:\ProgramData\MySQL\MySQL Server 5.7\Uploads and then I executed below command and it works for me,
INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/an.jpg'));
Hope this helps.
When I use the MySQL client to create database, if I type below command:
create database nice-day;
Then it tells me that:
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 '-day' at line 1
But when I use phpAdmin tool, I can create the database named nice-day. What is the problem?
The - character is not considered to be part of an identifier in SQL, so the database name must be quoted:
CREATE DATABASE `nice-day`
In general, though, it is advisable to use underscores (_) instead of dashes in database names to avoid this issue.
Please use backticks "`" (the key before the 1 on a standard US 101 keyboard).
as per http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
The identifier quote character is the backtick (“`”):