MySQL Error 1064: You have an error in your SQL syntax workbench 8.0 [duplicate] - sql

Im using xampp control panel and from there i start the process for apache and mysql. Then i go to mysql workbench and server status seems to be ok, here is some info
Host: Windows-PC
Socket: C:/xampp/mysql/mysql.sock
Port: 3306
Version 10.1.31-MariaDB mariadb.org binary distribution
Compiled For: Win32(32)
Configuratin File: unknown
Then everytime when i try to add the foreign key for my dummy schema like:
ALTER TABLE `puppies`.`animals`
ADD INDEX `Breed_idx` (`BreedID` ASC) VISIBLE;
;
ALTER TABLE `puppies`.`animals`
ADD CONSTRAINT `Breed`
FOREIGN KEY (`BreedID`)
REFERENCES `puppies`.`breeds` (`Breed`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
I get the following error
ERROR 1064: You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
'' at line 2
SQL Statement:
ALTER TABLE `puppies`.`animals`
ADD INDEX `Breed_idx` (`BreedID` ASC) VISIBLE
So what can i do so that xampp will start using mysql syntax over mariaDb?
Or if im wrong in my understanding of the problem, then what should i do so that i dont have to face this kind of issues again when using xampp?

Problem is the word VISIBLE, remove it and it will work.
Index are visible by default.
Your question: "If i remove VISIBLE it works just fine, so why did mysql workbench decided to add visible?"
My answer: The option to mark index invisible is not yet implemented in MariaDB (afaik!).
Update:
The syntax for MariaDB is different, please see this reference: https://jira.mariadb.org/browse/MDEV-7317

Just to add to those who are using Maria DB with MySQL Workbench, you don't need to install mysql. You can just change 'Default Target MySQL Version' from Preferences to 5.7 or 5.6, and the VISIBLE keyword will be removed by workbench.
Here is a link from mysql bugs
https://bugs.mysql.com/bug.php?id=92269

I am using MySQL Workbench and have same problem. Change in the Preferences but it did not work.
Solution: If you export forward-engineer the model you need to change the configuration on another place.
Go to Model > Model Options
Inside the Model Options, go to MySQL
Then change the "Target MySQL Version" to 5.6

Related

How to solve the ENGINE = InnoDB' error in SQL? [duplicate]

Im using xampp control panel and from there i start the process for apache and mysql. Then i go to mysql workbench and server status seems to be ok, here is some info
Host: Windows-PC
Socket: C:/xampp/mysql/mysql.sock
Port: 3306
Version 10.1.31-MariaDB mariadb.org binary distribution
Compiled For: Win32(32)
Configuratin File: unknown
Then everytime when i try to add the foreign key for my dummy schema like:
ALTER TABLE `puppies`.`animals`
ADD INDEX `Breed_idx` (`BreedID` ASC) VISIBLE;
;
ALTER TABLE `puppies`.`animals`
ADD CONSTRAINT `Breed`
FOREIGN KEY (`BreedID`)
REFERENCES `puppies`.`breeds` (`Breed`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
I get the following error
ERROR 1064: You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
'' at line 2
SQL Statement:
ALTER TABLE `puppies`.`animals`
ADD INDEX `Breed_idx` (`BreedID` ASC) VISIBLE
So what can i do so that xampp will start using mysql syntax over mariaDb?
Or if im wrong in my understanding of the problem, then what should i do so that i dont have to face this kind of issues again when using xampp?
Problem is the word VISIBLE, remove it and it will work.
Index are visible by default.
Your question: "If i remove VISIBLE it works just fine, so why did mysql workbench decided to add visible?"
My answer: The option to mark index invisible is not yet implemented in MariaDB (afaik!).
Update:
The syntax for MariaDB is different, please see this reference: https://jira.mariadb.org/browse/MDEV-7317
Just to add to those who are using Maria DB with MySQL Workbench, you don't need to install mysql. You can just change 'Default Target MySQL Version' from Preferences to 5.7 or 5.6, and the VISIBLE keyword will be removed by workbench.
Here is a link from mysql bugs
https://bugs.mysql.com/bug.php?id=92269
I am using MySQL Workbench and have same problem. Change in the Preferences but it did not work.
Solution: If you export forward-engineer the model you need to change the configuration on another place.
Go to Model > Model Options
Inside the Model Options, go to MySQL
Then change the "Target MySQL Version" to 5.6

Symfony 4 - SQLSTATE[42000] alter table for unknown reasons

I'm here because, I need your help. I'm working on a Symfony project, I just finished to modify my DataBase with MySqlWorkBench (I've done this because I have to present the DataBase at the end of the school year). After that, I've executed "Forward Engineer" to send all the tables and columns to the database.
Then, i've just entered this line, to create my entities:
php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
Later I put this line line to generate my setters/getters and my Repositories
php bin/console make:entity --regenerate App
When it's done, I've used those lines :
php bin/console d:m:diff
And I migrate all to the database:
php bin/console d:migrations:execute --up 20190321194410
And after this command, I got a ton of errors but they deal of the same thing.
There is this query, I don't know why it's executed:
ALTER TABLE school_has_level RENAME INDEX fk_school_has_school_level_school1_idx TO IDX_102C1F10C32A47EE
And after there is those errors :
In AbstractMySQLDriver.php line 79:
An exception occurred while executing 'ALTER TABLE school_has_level RENAME INDEX fk_school_has_school_level_school1_idx TO IDX_102C1F10C32A47EE':
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB serve
r version for the right syntax to use near 'INDEX fk_school_has_school_level_school1_idx TO IDX_102C1F10C32A47EE' at line 1
I'm searching some tips on Internet but I didn't find anything about that. The problem is that, I don't understand where the query is started...
Thank you for your future answer, and sorry for my english :'(
Best regards,
Mathieu

Bad changelog from generateChangeLog with MariaDB

I am attempting to generate a change log against a MariaDB server. I am able to successfully generate a change log, however if I do a dropAll and update to validate that it is useful, there are multiple problems with it. I have tried using both the native mariadb and MySQL jdbc connectors and both experience these problems. I am also using liquibase 3.1.1.
The first is that there are deferrable and initiallyDeferred flags which are not supported by MySQL. The update command specifically calls these out as being invalid flags against MySQL.
Once I remove all of those references in the .xml, attempting to update runs into a sql syntax error because a double datatype is defined as DOUBLE(22) (in the xml). This is not a valid syntax for a double in mariadb or MySQL. They accept no parameters, or DOUBLE(m,d); my database is defined as default (no parameters).
Now its trying to create a table with an auto_increment but not specifying that the column is also a key in the create table statement; ie. it's missing the primaryKey constraint.
And I'm sure there are more problems in line as I work my way through the changelog (this is just changeset 116 out of 1500+).
Its almost as if liquibase is creating the changelog based on it thinking the db is a different type (postgres/oracle?).
Am I missing something?
You are right, the problem is that Liquibase is thinking it is an unknown database and doesn't know it is almost mysql. There is an issue open to add mariaDB support (https://liquibase.jira.com/browse/CORE-1411) but it hasn't been implemented quite yet.
The easiest work-around would be to add an extension:
Create a new liquibase.database.ext.MariaDBDatabase class in your codebase that extends liquibase.database.core.MySQLDatabase and override the isCorrectDatabaseImplementation(DatabaseConnection conn) method that returns true if conn.getDatabaseProductName() equals whatever the MariaDB jdbc driver is returning.
You may also want to override the getDefaultDatabaseProductName() to return "mariadb" instead of MySQL so you can differentiate it with contexts

Does MariaDB support renaming an index?

Is there a syntax for renaming an index in MariaDB? I understand that MySQL 5.7 supports the syntax, but does MariaDB 10.0 (which includes MySQL 5.6) support it?
I just tried ALTER TABLE thing RENAME INDEX ix_old TO ix_new; in MariaDB 10.2.12 and it failed.
It also doesn't appear in the docs at https://mariadb.com/kb/en/library/alter-table/
And mysteriously an answer to this question displayed in duckduckgo doesn't exist! It said
No, there is no way to rename an index in current versions of MySQL
(up to 5.6) or MariaDB (up to 10) or Percona Server (up to 5.6).
You can only drop an index and create a new index of a different name.
As a workaround, you could use pt-online-schema-change to add a new
index with the new name and drop the old index by its old name, while
allowing continuous read/write access to the original table.
$ pt-online-schema-change --alter "ADD KEY new_idx_name, DROP KEY
old_idx_name" \ D=mydatabase,t=mytable
--Bill Karwin
But Bill Karwin's edit to the question remains. Hmmm, why would he have deleted it?
They added the option on version 10.5.2, but I'm not sure it works because I have the vs 10.3 in my servers. https://mariadb.com/kb/en/alter-table/#rename-indexkey
I'll update it with more info.

SQL to add column with default value - Access 2003

Updating an old ASP/Access site for a client - I need SQL to add a column to an existing table and set a default value. Doesn't work - any ideas?
This works fine
ALTER TABLE documents ADD COLUMN membersOnly NUMBER
I want this to work:
ALTER TABLE documents ADD COLUMN membersOnly NUMBER DEFAULT 0
Have googled and seen instructions for default values work for other field types but I want to add number. Thanks!
Tools -> Options -> Tables/Queries -> (At the bottom right:) Sql Server Compatible Syntax - turn option on for this database.
then you can execute your query:
ALTER TABLE documents ADD COLUMN membersOnly NUMBER DEFAULT 0
With ADO, you can execute a DDL statement to create a field and set its default value.
CurrentProject.Connection.Execute _
"ALTER TABLE discardme ADD COLUMN membersOnly SHORT DEFAULT 0"
How are you connecting to the database to run the update SQL? You can use the ODBC compatible mode through ADO. Without opening the database in Access.
You may find Sql Server Compatible Syntax is already turned on, so definately worth just trying to run the sql statement mentioned above (via an ADO connection from ASP) before resorting to taking the db offline. Thanks, this helped me out.
Tools -> Options -> Tables/Queries -> (At the bottom right:) Sql Server Compatible Syntax - turn option on for this database.
is not found on MS Access 2010