I am getting an error when I try to import data through the command:
mysql -u root -p"root" cvdb < "cvdb.sql"
The error I am getting is:
ERROR 1064 (42000) at line 72: 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,
Created datetime NOT NULL default ' 0000-00-00 00:00:00 ',
' at line 14
The code of my SQL file is:
DROP TABLE IF EXISTS `activity`;
CREATE TABLE `activity` (
`AllDay` enum('YES','NO') default 'NO',
`ActivityID` int(11) unsigned NOT NULL auto_increment,
`Type` int(11) NOT NULL default '0',
`Priority` int(11) NOT NULL default '0',
`Status` int(11) NOT NULL default '0',
`Title` varchar(255) default NULL,
`DueDate` datetime default NULL,
`CompletedDate` datetime default NULL,
`Details` text,
`Creator` int(11) NOT NULL default '0',
`Owner` int(11) default NULL,
`ModifiedBy` int(11) default NULL,
`Modified` timestamp(14) NOT NULL,
`Created` datetime NOT NULL default ' 0000-00-00 00:00:00 ',
`Start` datetime default NULL,
`End` datetime default NULL,
`AttachmentType` enum('NONE','FILE','LINK') NOT NULL default 'NONE',
`Location` varchar(25) default NULL,
`visibility` enum('PRIVATE','PUBLIC') NOT NULL default 'PRIVATE',
`Notes` varchar(255) default NULL,
PRIMARY KEY (`ActivityID`),
UNIQUE KEY `ActivityID` (`ActivityID`),
KEY `Type` (`Type`),
KEY `Priority` (`Priority`),
KEY `Status` (`Status`),
KEY `Creator` (`Creator`),
KEY `Owner` (`Owner`),
KEY `ModifiedBy` (`ModifiedBy`),
KEY `Location` (`Location`)
) ENGINE=InnoDB;
the error is here Modified timestamp(14) NOT NULL. you should remove (14) from timestamp.
your partial DDL,
`ModifiedBy` int(11) default NULL,
`Modified` timestamp NOT NULL,
`Created` datetime NOT NULL default '0000-00-00 00:00:00',
`Start` datetime default NULL,
From mysql doc
Incompatible change: In very old versions of MySQL (prior to 4.1), the
TIMESTAMP data type supported a display width, which was silenty
ignored beginning with MySQL 4.1. This is deprecated in MySQL 5.1, and
removed altogether in MySQL 5.5. These changes in behavior can lead to
two problem scenarios when trying to use TIMESTAMP(N) columns with a
MySQL 5.5 or later server:
...
You should try to handle potential issues of these types proactively
by updating with ALTER TABLE any TIMESTAMP(N) columns in your
databases so that they use TIMESTAMP instead, before performing any
upgrades.
So try to remove the (14)
in
Modified timestamp(14) NOT NULL
or as said in doc, try to make alter table statements on your timestamp columns before import.
Related
I'm trying to export an old wp_posts database into a new one, and I'm hitting a few brick walls.
I'm currently exporting in SQL compatibility mode: MYSQL40.
Here's the error:
--
-- Database: `grafiqe`
--
-- --------------------------------------------------------
--
-- Table structure for table `wp_actionscheduler_actions`
--
CREATE TABLE `wp_actionscheduler_actions` (
`action_id` bigint(20) UNSIGNED NOT NULL,
`hook` varchar(191) NOT NULL,
`status` varchar(20) NOT NULL,
`scheduled_date_gmt` datetime DEFAULT '0000-00-00 00:00:00',
`scheduled_date_local` datetime DEFAULT '0000-00-00 00:00:00',
`args` varchar(191) DEFAULT NULL,
`schedule` longtext,
`group_id` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`attempts` int(11) NOT NULL DEFAULT '0',
`last_attempt_gmt` datetime DEFAULT '0000-00-00 00:00:00',
`last_attempt_local` datetime DEFAULT '0000-00-00 00:00:00',
`claim_id` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`extended_args` varchar(8000) DEFAULT NULL
)
MySQL said: Documentation
#1050 - Table 'wp_actionscheduler_actions' already exists```
Your code snippet already tells you the error
#1050 - Table 'wp_actionscheduler_actions' already exists```
It's not possible to create a table with the name of a table that already exists in the database. Daft question, but are you importing it into the new empty database and not the same one you just exported it from?
I'm trying to create a table on mysql 5.5 with the following:
CREATE TABLE `markets` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL,
`created_at` datetime(6) NOT NULL,
`updated_at` datetime(6) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4;
But I get the 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 '(6) NOT NULL,
01 `updated_at` datetime(6) NOT NULL,
01 PRIMARY KEY (`id`)
01 ) ENGINE' at line 4
What am I doing wrong here?
instead of
`created_at` datetime(6) NOT NULL,
`updated_at` datetime(6) NOT NULL,
try
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
I want to execute the following mysql statement from the framadate software.
CREATE TABLE IF NOT EXISTS `sondage` (
`id_sondage` char(16) NOT NULL,
`commentaires` text,
`mail_admin` varchar(128) DEFAULT NULL,
`nom_admin` varchar(64) DEFAULT NULL,
`titre` text,
`id_sondage_admin` char(24) DEFAULT NULL,
`date_creation` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_fin` timestamp NOT NULL,
`format` varchar(2) DEFAULT NULL,
`mailsonde` tinyint(1) DEFAULT '0',
`statut` int(11) NOT NULL DEFAULT '1' COMMENT '1 = actif ; 0 = inactif ; ',
UNIQUE KEY `id_sondage` (`id_sondage`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
But I get the error: Error in query (1067): Invalid default value for 'date_fin'
I wonder what that means, because there is no default value given for date_fin.
It sounds to me like your MySQL server is insisting you provide a default value for your date_fin column. Try this.
...
`date_fin` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
...
In general, it's a reasonably good practice to provide default values for NOT NULL columns.
I have a table named Users with a column call created. Whenever a record is created I want to add the datetime.
Users Table:
CREATE TABLE `Users` (
`userId` int(11) unsigned NOT NULL AUTO_INCREMENT,
`fullName` varchar(50) DEFAULT NULL,
`firstName` varchar(25) NOT NULL DEFAULT '',
`lastName` varchar(25) NOT NULL DEFAULT '',
`address` varchar(50) NOT NULL DEFAULT '',
`city` varchar(25) DEFAULT NULL,
`state` char(2) DEFAULT NULL,
`zipCode` varchar(25) DEFAULT NULL,
`email` varchar(50) NOT NULL DEFAULT '',
`cellPhone` varchar(15) DEFAULT NULL,
`birthDate` date NOT NULL,
`creditCard` varchar(250) NOT NULL DEFAULT '',
`subscriptionStarted` date NOT NULL,
`subscriptionEnded` date NOT NULL,
`basicPlan` tinyint(1) DEFAULT NULL,
`standardPlan` tinyint(1) DEFAULT NULL,
`premiumPlan` tinyint(1) DEFAULT NULL,
`staff` tinyint(1) DEFAULT NULL,
`admin` tinyint(1) DEFAULT NULL,
`systemAdmin` tinyint(1) DEFAULT NULL,
`edited` datetime DEFAULT NULL,
`created` datetime DEFAULT NULL,
PRIMARY KEY (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1;
now i added this extra query to make my created field get the current datetime when a new record is created.
ALTER TABLE Users
ALTER COLUMN created SET DEFAULT CURRENT_TIMESTAMP
The problem is that I get the following error when running the alter table query
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 'CURRENT_TIMESTAMP' at line 2
Your syntax is slightly off, I think you have to specify the column to change:
ALTER TABLE Users CHANGE created created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
See this sample SQL Fiddle for an example.
Many servers now a days have the latest version of MySQL - which is giving an error when running the following piece of code:
$drop_table = mysql_query("DROP TABLE IF EXISTS `$t_ads`");
$sqls[$t_ads] = "CREATE TABLE `$t_ads` (
`adid` int unsigned NOT NULL auto_increment,
`adtitle` varchar(100) NOT NULL default '',
`addesc` longtext NOT NULL,
`area` varchar(50) NOT NULL default '',
`email` varchar(50) NOT NULL default '',
`showemail` enum('0','1','2') NOT NULL default '0',
`password` varchar(50) NOT NULL default '',
`code` varchar(35) NOT NULL default '',
`cityid` smallint unsigned NOT NULL default '0',
`subcatid` smallint unsigned NOT NULL default '0',
`price` DECIMAL( 10, 2 ) NOT NULL default '0',
`othercontactok` enum('0','1') NOT NULL default '0',
`hits` int unsigned NOT NULL default '0',
`ip` varchar(15) NOT NULL default '',
`verified` enum('0','1') NOT NULL default '0',
`abused` int unsigned NOT NULL default '0',
`enabled` enum('0','1') NOT NULL default '0',
`createdon` datetime NOT NULL default '0000-00-00 00:00:00',
`expireson` datetime NOT NULL default '0000-00-00 00:00:00',
`timestamp` timestamp(14) NOT NULL,
`paid` enum('0','1','2') NOT NULL default '2',
PRIMARY KEY (`adid`),
KEY `subcatid` (`subcatid`),
KEY `cityid` (`cityid`),
KEY `verified` (`verified`),
KEY `enabled` (`enabled`),
KEY `paid` (`paid`)
) TYPE=MyISAM;";
Servers with an older version of mysql seem to accept this, but the new version is not accepting it at all and giving an error. I have many errors related to it since the PHP database setup is little bigger. An example of the error is below:
#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, paid enum, NOT NULL default '2', PRIMARY KEY (adid), K' at line 21
The plain SQL part of your code looks ok (just tested it with MySQL 5.6), though I'd generally advise not to use keywords like timestamp as a column name. The table will be created in MySQL 5.6, but you'll encounter two warnings:
The syntax TIMESTAMP(14) is deprecated and will be removed in
MySQL 6.0. Please use TIMESTAMP instead
The syntax TYPE=storage_engine is deprecated and will be removed in MySQL
6.0. Please use ENGINE=storage_engine instead
If this doesn't help, please post the actual MySQL version you're working with.
Change your column name it should not be mysql keyword 'timestamp' and
chnage
`timestamp` timestamp(14) NOT NULL,
to
`<SOME OTHERNAME>` timestamp NOT NULL,