MySql - unable to create new tables after changing my.ini (windows) - mysql

In order to be able to create tables with capital letters I had to modify the my.ini file in ProgramData\MySQL\MySQL Server 5.7, U added lower_case_table_names = 2 at the end of the file like it was suggested here, when I closed MySQL server and restarted it couldn't create any new tables, so I removed the line I added, restarted the server again, I keep having this error
Operation failed: There was an error while applying the SQL script to the database.
Executing:
CREATE TABLE `toys`.`new_table` (
);
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 ')' at line 2
SQL Statement:
CREATE TABLE `toys`.`new_table` (
)

You cannot create a table without columns - you need something between the brackets there. E.g.:
CREATE TABLE `toys`.`new_table` (
id INT -- just for example
);

Related

setting the target database version for mysql workbench migration

I am running a migration from sql server to mariadb 10.0 and the generated code keeps failing due to a syntax error in the create table statements.
Specifcally it doesn't like the INDEX lines of the create table statements. And example of a statement it chokes on is
CREATE TABLE t1 (
`fk_manager` varchar(255),
INDEX `imgr` (`fk_manager` ASC) visible
);
This is the error I get
ERROR 1064 (42000): 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 'INDEX
`imgr` (`fk_manager` ASC) visible)'
at line 3
If i remove the visible keyword the same command works, so I assume this is syntax valid on newer versions of mysql but not mine. Is there any way I can tell mysql workbench to exclude it?
In the top menu click Model > Model Options
In the dialogue that pops up, select MySQL on the left side
Change Target MySQL Version to 5.7

MySQL syntax error - dropping foreign key if exist

The following ALTER statement is working fine on my local (xamp), but on my server (Debian), I'm getting this 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
'IF EXISTS `foreign_key1`' at line 1
This is the query:
ALTER TABLE `table` DROP FOREIGN KEY IF EXISTS `foreign_key1`;
How do I fix the error?
Sounds like your development environment is running MariaDB, and your server is running MySQL.
MySQL doesn't support the IF EXISTS in an ALTER TABLE statement.
That syntax is supported in MariaDB 10.0.
To confirm the version running in each environment, we could execute
SHOW VARIABLES LIKE 'version'
MariaDB https://mariadb.com/kb/en/mariadb/alter-table/
MySQL https://dev.mysql.com/doc/refman/5.7/en/alter-table.html
I don't know if this answers the question that was asked... "What is the explanation for the observed behavior?" (Was that the question?)

Is there a way to run multi-SQLs by RMySQL(dbExecute)?

I am using RMySQL to connect and manipulate MySQL.
Now I have a SQL like:
"drop table if exists t_tmp; create table t_tmp(name varchar(20));"
which works just fine in MySQL CLI.
But when I put these SQLs to RMySQL.dbExecute() exception throws:
"could not run statement: 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 'create table t_tmp(name varchar(20))' at line 1"
I am trying to run the 2 SQLs respectively, then they both work out OK.
Is there any way I can put the whole STRING(SQLs) and run it correctly in RMySQL?
Thanks!

Cannot duplicate mysql database using phpmyadmin export/import on same server

I am trying to duplicate one of my databases on a remote bluehost server in order to setup a dev and stage environment for my drupal website. Dev is already setup/populated and working fine, so I am now simply trying to duplicate the dev database. Using phpmyadmin on windows (PHP 5.2.17, MySQL 5.5.42). I have done the following steps:
created site_stage database
exported/dumped all tables from site_dev db into compressed sql.gz file
imported all tables into site_stage db
Import fails with $1064 error:
INSERT INTO `cache_bootstrap` (`cid`, `data`, `expire`, `created`, `serialized`, `tags`, `checksum`) VALUES
('system_list', 0x613a323a7b733a353a227468656d65223b613a31333a7b733a363a2262617274696b223b433a33313a2244727570616c5c436f72655c457874656e73696f6e5c457874656e73696f6e223a323339343a7b613a31363a7b733a343a2274797065223b733a353a227468656d65223b733a383a22706174686e616d65223b733a33343a22636f72652f7468656d65732f62617274696b2f62617274696b2e696e666f2e796d6c223b733a383a2266696c656e616d65223b733a31323a2262617274696b2e7468656d65223b733a373a2273756270617468223b733a31333a227468656d65732f62617274696b223b733a363a226f726967696e223b733a343a22636f7265223b733a363a22737461747573223b693a313b733a343a22696e666f223b613a31393a7b733a343a226e616d65223b733a363a2242617274696b223b733a343a2274797065223b733a353a227468656d65223b733a31303a2262617365207468656d65223b733a363a22636c61737379223b733a31313a226465736372697074696f6e223b733a38363a224120666c657869626c652c207265636f6c6f7261626c65207468656d652077697468206d616e79[...]
#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 '?' at line 2
Thought maybe it didn't like the length of that value, so I just deleted that cache_bootstrap query from uncompressed version of dump file (shouldn't need this cache table anyways) and tried to import again, this time, it failed with the following error:
CREATE TABLE IF NOT EXISTS `key_value` (
`collection` varchar(128) CHARACTER SET ascii NOT NULL DEFAULT '' COMMENT 'A named collection of key and value pairs.'
`value` longblob NOT NULL COMMENT 'The value.',
PRIMARY KEY (`collection`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Generic key-value storage table. See the state system for…';
#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 '`value` longblob NOT NULL COMMENT 'The value.',
PRIMARY KEY (`collection`,`nam' at line 9
I've read a lot of '1064 error on import' threads, but none of them help and most of them pertain to moving sql data between servers. Very strange that I would get syntax errors copying tables from one database to another on same server, with same mysql version, etc. Any ideas? Thanks in adv.

How to restore dump file using Mysql Query Browser

When i am trying to run some queries from the batch file i am getting some error message in my query browser
I have tried with
source E:\Rename_scripts_unused_tables_msp.sql
and i am getting error message like
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 'source E:\Rename_scripts_unused_tables_msp updated.sql' at line 1'
And the query works fine in command line.
Here is my source file statements:
rename table appliance_backup_usage_history to unused_appliance_backup_usage_history;
rename table backup_core_server to unused_backup_core_server;
rename table bdr_vms to unused_bdr_vms;
rename table client_details1 to unused_client_details1;
rename table client_service_technologies_backup to unused_client_service_technologies_backup;
rename table cloud_instances to unused_cloud_instances;
and more statements like that
What's the reason behind this ??
source is a mysql CLI command - not an SQL query command. It only works using the command line client mysql.
https://dev.mysql.com/doc/refman/5.7/en/mysql-batch-commands.html