#1064 MySQL error on webhost - mysql

I am getting the following error on MySQL:
#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) NOT NULL,
`Modified` datetime(6) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHA' at line 14
I have a SQL script that creates a database and some tables. It uploads perfectly on my localhost but when I import it on my web host using phpmyadmin it gives the above errror.
The code it highlights from the script is:
CREATE TABLE IF NOT EXISTS `dbo_countries` (
`CountryId` INT( 11 ) NOT NULL ,
`Code` VARCHAR( 50 ) DEFAULT NULL ,
`ISO2` VARCHAR( 10 ) DEFAULT NULL ,
`ISO3` VARCHAR( 10 ) DEFAULT NULL ,
`RegionId` INT( 11 ) DEFAULT NULL ,
`Name` VARCHAR( 255 ) DEFAULT NULL ,
`Created` DATETIME( 6 ) NOT NULL ,
`Modified` DATETIME( 6 ) DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = utf8 AUTO_INCREMENT =243;

The MySQL DATETIME datatype doesn't accept a length, size, digit specifier. The error is being thrown because it's a syntax violation.
To declare a DATETIME column, do it like this, without any following parens:
`Created` DATETIME NOT NULL

Related

When I am trying to import it to my phpmy admin am getting error #1067 - Invalid default value

Error
SQL query:
--
-- Database: gym
-- --------------------------------------------------------
-- Table structure for table admin_tbl
CREATE TABLE IF NOT EXISTS `admin_tbl` (
`adminid` int( 11 ) NOT NULL ,
`username` varchar( 20 ) NOT NULL ,
`password` varchar( 20 ) NOT NULL ,
`timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON
) ENGINE = InnoDB AUTO_INCREMENT =3 DEFAULT CHARSET = latin1;
MySQL said: Documentation
#1067 - Invalid default value for 'timestamp'
You have an extra ON which you likely copied from:
dt DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
When you remove the ON, it works fine.
So your result should be:
CREATE TABLE IF NOT EXISTS `admin_tbl` (
`adminid` int( 11 ) NOT NULL ,
`username` varchar( 20 ) NOT NULL ,
`password` varchar( 20 ) NOT NULL ,
`timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE = InnoDB AUTO_INCREMENT =3 DEFAULT CHARSET = latin1;
SQLFiddle
MySQL Documentation

Database not importing

Error
##
--
-- Database: verticalned
-- --------------------------------------------------------
-- Table structure for table announcements
CREATE TABLE `announcements` (
`id` INT( 10 ) NOT NULL ,
`description` VARCHAR( 6000 ) DEFAULT NULL ,
`links` VARCHAR( 100 ) DEFAULT NULL ,
`first` TINYINT( 1 ) DEFAULT > NULL ,
`second` TINYINT( 1 ) DEFAULT NULL ,
`third` TINYINT( 1 ) DEFAULT NULL ,
`fourth` TINYINT( 1 ) DEFAULT NULL ,
`staff` VARCHAR( 22 ) DEFAULT NULL ,
`time` DATETIME( 2 ) DEFAULT NULL ,
`subject` VARCHAR( 100 ) DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = latin1;
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 '(2) DEFAULT NULL, subject varchar(100) DEFAULT NULL )
ENGINE=InnoDB DEFAULT ' at line 20
version
Looks like the mysql version you are using (probably older than 5.6.4) does not accept precision (fractional seconds). You can bypass the issue by replacing ..., time DATETIME(2) DEFAULT NULL ,... with ... , time DATETIME DEFAULT NULL ,....
However, you should solve the issue by either changing the data type to timestamp or upgrading MySQL server to a version later than 5.6.4
CREATE TABLE `announcements` (
`id` INT(10) NOT NULL,
`description` VARCHAR(6000) DEFAULT NULL,
`links` VARCHAR(100) DEFAULT NULL,
`first` TINYINT( 1 ) DEFAULT NULL ,
`second` TINYINT( 1 ) DEFAULT NULL ,
`third` TINYINT( 1 ) DEFAULT NULL ,
`fourth` TINYINT( 1 ) DEFAULT NULL ,
`staff` VARCHAR( 22 ) DEFAULT NULL ,
`time` DATETIME( 2 ) DEFAULT NULL ,
`subject` VARCHAR( 100 ) DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = latin1;
obvoiusly theres nothing wrongn with your code. just add the slanted quotes
CREATE TABLE announcements (
id INT NOT NULL ,
description VARCHAR( 6000 ) DEFAULT NULL ,
links VARCHAR( 100 ) DEFAULT NULL ,
firstTINYINT DEFAULT NULL ,
secondTINYINT DEFAULT NULL,
thirdTINYINT DEFAULT NULL ,
fourthTINYINT DEFAULT NULL,
staffVARCHAR(22) DEFAULT NULL ,
timeDATETIME DEFAULT NULL ,
subject` VARCHAR( 100 ) DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = latin1;
Please remove character number from INT and TINYINT, and add the slanted quotes your code should work.

Error in SQL Syntax. What would be the proper solution or right syntax to use for a successful result?

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 '(14) NOT NULL ) ENGINE=MyISAM' at line 23
CREATE TABLE `activity_points` (
`fk_user_id` INT( 10 ) NOT NULL DEFAULT '0',
`date` DATE NOT NULL DEFAULT '0000-00-00',
`points` INT( 10 ) NOT NULL DEFAULT '0',
`lastupdate` TIMESTAMP( 14 ) NOT NULL
) ENGINE = MYISAM ;
TIMESTAMP shouldn't have length
CREATE TABLE `activity_points` (
`fk_user_id` INT( 10 ) NOT NULL DEFAULT '0',
`date` DATE NOT NULL DEFAULT '0000-00-00',
`points` INT( 10 ) NOT NULL DEFAULT '0',
`lastupdate` TIMESTAMP NOT NULL
) ENGINE = MYISAM ;

How do I eliminate error message 1064 when trying to create table with BLOB type columns?

I keep getting an error for this table. I've never created a table using blob's before so I do not understand the error message. Can someone explain the error?
CREATE TABLE `teamc`.`newsletter` (
`title` VARCHAR( 100 ) NOT NULL ,
`subtitle` VARCHAR( 100 ) NOT NULL ,
`date` DATE NOT NULL ,
`jpg` BLOB BINARY NULL DEFAULT NULL ,
`pdf` BLOB BINARY NULL DEFAULT NULL ,
PRIMARY KEY ( `title` , `date` )
) ENGINE = InnoDB;
MySQL gives me the following error:
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 'BINARY NULL DEFAULT NULL, pdf BLOB BINARY NULL DEFAULT NULL, PRIMARY KEY (`tit' at line 1
BINARY is a type, BLOB is a type - and you cannot specify multiple types for the same column. You pick one:
CREATE TABLE `newsletter` (
`title` VARCHAR( 100 ) NOT NULL ,
`subtitle` VARCHAR( 100 ) NOT NULL ,
`date` DATE NOT NULL ,
`jpg` BLOB NULL DEFAULT NULL ,
`pdf` BLOB NULL DEFAULT NULL ,
PRIMARY KEY ( `title` , `date` )
) ENGINE = InnoDB;

MYSQL Error #1064 Error in SQL Syntax

I keep getting this error:
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 'USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=13' at line 11
with this with this query:
SQL query:
CREATE TABLE IF NOT EXISTS `jml_usergroups` (
`id` int( 10 ) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`parent_id` int( 10 ) unsigned NOT NULL DEFAULT '0' COMMENT 'Adjacency List Reference Id',
`lft` int( 11 ) NOT NULL DEFAULT '0' COMMENT 'Nested set lft.',
`rgt` int( 11 ) NOT NULL DEFAULT '0' COMMENT 'Nested set rgt.',
`title` varchar( 100 ) NOT NULL DEFAULT '',
PRIMARY KEY ( `id` ) ,
UNIQUE KEY `idx_usergroup_parent_title_lookup` ( `parent_id` , `title` ) ,
KEY `idx_usergroup_title_lookup` ( `title` ) ,
KEY `idx_usergroup_adjacency_lookup` ( `parent_id` ) ,
KEY `idx_usergroup_nested_set_lookup` ( `lft` , `rgt` ) USING BTREE
) ENGINE = MYISAM DEFAULT CHARSET = utf8 AUTO_INCREMENT =13;
Any idea what the problem is? these errors are like the thorns on a rose
The syntax is ok, your problem is probably that you're trying to run it on a MySQL version earlier than 5.1, which does not have USING BTREE.