I have a database with tables already in the database. There is a table called Character that I am trying to access to add an additional column. However any command that I use with the table Character gives me the following error:
mysql> SHOW FIELDS FROM Character;
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 'Character' at line 1
I've tried the following commands:
mysql> SHOW FIELDS FROM "Character";
mysql> SHOW FIELDS FROM 'Character';
mysql> SHOW FIELDS FROM Character;
All three give me the same error. I have already selected the appropriate database that contains the Character table using the command "USE dbname;"
Character is a reserved word therefore you should use backticks:
SHOW FIELDS FROM `Character`;
See it here 9.3 Keywords and Reserved Words
Also, about the "Uppercase" (or not), read this answer Are table names in MySQL case sensitive?
On this image I'm using MySql Workbench
Related
This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 1 year ago.
I have a MySQL database table that contains a column named GROUP.
I am trying to add an index on this column using the following SQL:
alter table MY_TABLE add index (GROUP);
This gives me the error:
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 'GROUP)' at line 1
I have tried qualifying the column as MY_TABLE.GROUP and tried creating the index using the MySQL Workbench UI but both throw the same error.
Like all reserved words it is best not to use them at all
But you can use backticks, but you need to use them in all queries with that index
also you can read more about that on When to use single quotes, double quotes, and backticks in MySQL
alter table MY_TABLE add index (`GROUP`);
Here is my sql sentence
INSERT IGNORE INTO user_predicts (id,points,rank,rid,uid,win_count)
VALUES (0,0,0,1,1016,0)
All the fields in this table is int
But in 8.0.22, it just give me this bottom line:
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 'rank,rid,uid,win_count) VALUES (0,0,0,1,1016,0)' at line 1
But this sql works fine in 5.7.35
RANK is a reserved word in MySQL v8, added since version 8.0.2. You can't use it in query unless you wrap it with backticks (`). Try this:
INSERT IGNORE INTO user_predicts (id,points,`rank`,rid,uid,win_count) VALUES
(0,0,0,1,1016,0)
Here's MySQL documentation about reserved words. Please note that all words appended with (R) in the docs must wrap in backticks if you want to use it. Either that, or just change you column name to Ranks.
You are using the RANK keyword as field name. In MySQL 8.0, the word is used as a window function RANK(). You must replace the field name rank with a different name.
Basically mistyped a migration and now I have a column in my users table like this: {:index=>true}_id
I am trying to remove this field in MYSQL terminal with:
ALTER TABLE 'users' DROP COLUMN '{:index=>true}_id';
Error message:
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 ''users' drop column '{:index=>true}_id'' at line 1
You need to use backticks instead of single quotes.
ALTER TABLE `users` DROP COLUMN `{:index=>true}_id`;
I am trying to drop tables with wp_ prefix but its giving error below
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 'WHERE TABLE LIKE 'wp_%'' at line 1
Here is my query
"DROP TABLE WHERE TABLE LIKE '{$wp}%'"
What is wrong in this query? Please help
As far as I know, you can't selectively delete tables. You have to specifically delete each table, since deletion can't use a filter. You could probably use the metadata to get the names of all of your tables, and then find out in your code which ones start with wp_. Then, you would just loop through your list of tables to delete and then delete them with drop table [table-name];.
To get the list of table names from metadata, use select table_name from information_schema.tables;.
I'm converting a SQLite database to MySQL so I can import it to PHPMyAdmin.
This should be straightforward. I exported it to a dump, changed the autoincrements and changed all double quotes to backticks. This is what the start of the resulting file looks like:
DROP TABLE IF EXISTS `chars`;
CREATE TABLE chars(
charid INTEGER PRIMARY KEY AUTO_INCREMENT,
character TEXT
);
INSERT INTO `chars` VALUES(3,'a');
INSERT INTO `chars` VALUES(4,'b');
...
When trying to import to PHPMyAdmin it throws this error.
Error
SQL query:
CREATE TABLE chars(
charid INTEGER PRIMARY KEY AUTO_INCREMENT ,
CHARACTER TEXT
);
MySQL said:
#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 TEXT
)' at line 3
Is there too much space after the indented line? I left the "format" option as "SQL", left SQL compatibility mode as NONE and left "Do not use AUTO_INCREMENT for zero values" ticked.
Its going to be used in a django web app.
CHARACTER is a reserved word in mySQL. I'm betting that is the reason.
Use either a different column name (preferred), or use backticks:
`CHARACTER` TEXT