ım working localhost, after my work end. I want a upload my db server phpmyadmin. But still syntax error how can ı fix this?
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 '(6) NULL DEFAULT NULL,
PRIMARY KEY (id) USING BTREE
) ENGINE = InnoDB AUTO' at line 7 )
DROP TABLE IF EXISTS `veriler`;
CREATE TABLE `veriler` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`kullanici` varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`gpa` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`durumu` int(10) NULL DEFAULT NULL,
`miktari` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`tarih` datetime(6) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
Support for fractional seconds in DATETIME values wasn't added until version MySQL 5.6. If you can't upgrade your server, you will need to remove the trailing (6) from the definition of column tarih i.e.
`tarih` datetime NULL DEFAULT NULL,
Note that you will lose precision in those values relative to your MariaDB server. If you need to store microseconds in your data values, you will need to upgrade the MySQL server to version 5.6 or later.
Try this simplified version:
CREATE TABLE `veriler` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`kullanici` varchar(60) DEFAULT NULL,
`gpa` varchar(255) DEFAULT NULL,
`durumu` int(10) DEFAULT NULL,
`miktari` varchar(20) DEFAULT NULL,
`tarih` datetime(6) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
Related
I'm trying to migrate a db
from: MySQL Distrib 5.5.60-MariaDB, for Linux (x86_64)
to: MySQL 5.5.4, UNIX
I tried importing the db as a zip package and it started throwing errors so now I'm trying to re-create each table one at a time on phpMyAdmin.
The query below is throwing a #1064 Syntax error, and I'm having trouble figuring out the issue.
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 '(2) NOT NULL DEFAULT CURRENT_TIMESTAMP(2) ON UPDATE CURRENT_TIMESTAMP(2),
`st' at line 6
I'm looking at line 6, trying to find any reserved words, missing data, typos, and or obsolete commands but no luck.
CREATE TABLE `tblmoto_auth_policies` (
`policy_id` int(11) NOT NULL AUTO_INCREMENT,
`policy_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`policy_desc` text COLLATE utf8_unicode_ci NOT NULL,
`policy_url` text COLLATE utf8_unicode_ci NOT NULL,
`date_added` timestamp(2) NOT NULL DEFAULT CURRENT_TIMESTAMP(2) ON UPDATE CURRENT_TIMESTAMP,
`status` smallint(2) NOT NULL DEFAULT '1',
PRIMARY KEY (`policy_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
I could use some help.
Thanks in advance.
CURRENT_TIMESTAMP is not good
Try this:
CREATE TABLE `tblmoto_auth_policies` (
`policy_id` int(11) NOT NULL AUTO_INCREMENT,
`policy_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`policy_desc` text COLLATE utf8_unicode_ci NOT NULL,
`policy_url` text COLLATE utf8_unicode_ci NOT NULL,
`date_added` timestamp(2) NOT NULL DEFAULT CURRENT_TIMESTAMP(2) ON UPDATE CURRENT_TIMESTAMP(2),
`status` smallint(2) NOT NULL DEFAULT '1',
PRIMARY KEY (`policy_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
This works in SQL Fiddle:
CREATE TABLE `tblmoto_auth_policies` (
`policy_id` int(11) NOT NULL AUTO_INCREMENT,
`policy_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`policy_desc` text COLLATE utf8_unicode_ci NOT NULL,
`policy_url` text COLLATE utf8_unicode_ci NOT NULL,
`date_added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`status` smallint(2) NOT NULL DEFAULT '1',
PRIMARY KEY (`policy_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
i.e., remove the precision (the (2)) from the definition of the date_added column.
TIMESTAMP(2) is valid syntax, but not in combination with the DEFAULT CURRENT_TIMESTAMP nor ON UPDATE CURRENT_TIMESTAMP auto-initializers.
I want to export one of my database to my Raspberry. I tried through PHPMyadmin, but on import I got this errormessage:
SQL query:
--
-- Database: `leltar`
--
-- --------------------------------------------------------
--
-- Table structure for table `eventlog`
--
CREATE TABLE `eventlog` (
`ID` int(50) NOT NULL,
`event` varchar(50) COLLATE utf8_hungarian_ci NOT NULL,
`productbc` varchar(50) COLLATE utf8_hungarian_ci DEFAULT NULL,
`uname` varchar(50) COLLATE utf8_hungarian_ci NOT NULL,
`datetime` datetime(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci;
MySQL said: Documentation
#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 '(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci' at line 16
What's the matter?
Your datetime field has fractional seconds specified: datetime(1).
This feature is probably not supported by the target mysql version (< v5.7), hence the error message.
You either need to upgrade your target mysql version to support fractional seconds or you need to remove the fractional seconds from the export file, both from the data definition and the data itself.
CREATE TABLE `eventlog` (
`ID` int(50) NOT NULL,
`event` varchar(50) COLLATE utf8_hungarian_ci NOT NULL,
`productbc` varchar(50) COLLATE utf8_hungarian_ci DEFAULT NULL,
`uname` varchar(50) COLLATE utf8_hungarian_ci NOT NULL,
`datetime` DATETIME NOT NULL
) ;
Remove the "(1)" after the word "datetime" because it needs no length (sorry, it's not "length" it is a fractional seconds specification). The following should work:
CREATE TABLE `eventlog` (
`ID` int(50) NOT NULL,
`event` varchar(50) COLLATE utf8_hungarian_ci NOT NULL,
`productbc` varchar(50) COLLATE utf8_hungarian_ci DEFAULT NULL,
`uname` varchar(50) COLLATE utf8_hungarian_ci NOT NULL,
`datetime` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci;
So I had a set of tables working on an older version of MySQL, however on this new version the tables it exported give a syntax error.
CREATE TABLE `joblistings` (
`jobid` int(11) NOT NULL AUTO_INCREMENT COLLATE utf8_unicode_ci NOT NULL,
`id` varchar(255) NOT NULL,
`client` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`service` tinyint(1) COLLATE utf8_unicode_ci NOT NULL,
`firstline` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`city/town/village` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`county` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`postcode` varchar(9) COLLATE utf8_unicode_ci NOT NULL,
`daterequired` date(YYY-MM-DD) NOT NULL,
`timefrom` time(HH:MM),
`timeto` time(HH:MM),
PRIMARY KEY (`jobid`),
UNIQUE KEY `id` (`jobid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=10 ;
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 '(YYY-MM-DD) NOT NULL, `timefrom` time(HH:MM),
`timeto` time(HH:MM), PRIMARY ' at line 10
These 3 seem to be the problem, from what I understand, however I am not versed well enough in versions and changes to see a way of fixing this.
`daterequired` date(YYY-MM-DD) NOT NULL,
`timefrom` time(HH:MM),
`timeto` time(HH:MM),
Any help would be much appreciated, keeping this format is important for my system to function.
You cannot change the format of the date and time. It will be stored in the default format('YYYY-MM-DD HH:MM:SS'). You can refer the documentation for more details.
The SQL Fiddle Demo after setting it to default format.
If you want to get the output in some other format then you have to use the DATE_FORMAT() function to get it in your required format.
I have a table
CREATE TABLE `devicelist` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`ip` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
`serial` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`networkname` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`login` varchar(130) COLLATE utf8_unicode_ci DEFAULT NULL,
`password` varchar(130) COLLATE utf8_unicode_ci DEFAULT NULL,
`peopleid` int(10) unsigned NOT NULL,
`deviceid` int(10) unsigned NOT NULL,
`placeid` int(10) unsigned NOT NULL,
`stationid` int(10) unsigned NOT NULL,
`place` text COLLATE utf8_unicode_ci,
`date` date NOT NULL,
`active` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `placeid` (`placeid`),
KEY `stationid` (`stationid`),
KEY `peopleid` (`peopleid`),
KEY `deviceid` (`deviceid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
as you see the serial is set to NOT NULL,
but when i run query like
UPDATE DeviceList SET serial = NULL WHERE id = 1
It outputs
1 row affected. ( Query took 0.0079 sec )
Why is this inserting null to not null field?
I want an error to occure:D
///****************************** EDIT
well i found the answer
the problem was in sql_mode
https://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sql-mode-strict
my sql_mode was empty by default
iw changed it to STRICT_ALL_TABLES via
SET GLOBAL sql_mode='STRICT_ALL_TABLES'
MySQL sucked the hell out of my day today because of this so I'm just sharing what I learned about this.
MySQL 5.6 defaults to NO_ENGINE_SUBSTITUTION.
MySQL 5.7 defaults to ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION.
As stated in this page from the MySQL Reference Manual,
MySQL installation programs may configure the SQL mode during the installation process. For example, mysql_install_db creates a default option file named my.cnf in the base installation directory.
It should and does throw error. I'd guess the create table you posted in the question doesn't correspond actual table definition ( taking into account you have a syntax error - extra comma ).
From documentation, I'm creating pma_history table.
This is the only part of scripts/create_tables.sql that fails:
CREATE TABLE IF NOT EXISTS `pma_history` (
`id` bigint(20) unsigned NOT NULL auto_increment,
`username` varchar(64) NOT NULL default '',
`db` varchar(64) NOT NULL default '',
`table` varchar(64) NOT NULL default '',
`timevalue` timestamp(14) NOT NULL,
`sqlquery` text NOT NULL,
PRIMARY KEY (`id`),
KEY `username` (`username`,`db`,`table`,`timevalue`)
)
ENGINE=MyISAM COMMENT='SQL history for phpMyAdmin'
DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
This is what server says:
#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 '(14) NOT NULL, `sqlquery` text NOT NULL, PRIMARY KEY (`id`),
KEY `user' at line 6
Leave the length of the timestamp column
`timevalue` timestamp NOT NULL
Prior to version 4.1, the format in which MySQL retrieves and displays TIMESTAMP values depends on the display size
Taken from here