Exported a MySQL database on one of my servers and am trying to import it on my new server. All done through phpMyAdmin.
MySQL says
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 IF NOT EXISTS jobs ( id mediumint(9) NOT
NULL, title varc' at line 12
That area of code is
CREATE TABLE IF NOT EXISTS `jobs` (
`id` mediumint(9) NOT NULL,
`title` varchar(200) DEFAULT NULL,
`descshort` varchar(400) DEFAULT NULL,
`descr` varchar(7000) DEFAULT NULL,
`postdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
One thing I might note is that I exported this from phpMyAdmin version 4.4.4 and MySQL 5.6, to my new server which is running phpMyAdmin 4.5.02 and MySQL 5.6
Any idea what might be causing this?
EDIT:
The table created before it successfully is
CREATE TABLE IF NOT EXISTS `horses` (
`id` mediumint(9) NOT NULL,
`bgcolor` varchar(7) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`bgimgurl` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`htop` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`hbottom` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`ptext` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`linktext` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`linktarget` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sord` int(11) DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Related
Continuation from this question:
PDO query updating a datetime column not in query
A column in my table called lastLoginDate was being automatically updated even though my prepared statement did not include said column.
Apparently, when I created the new column, a trigger was set.
Upon using the command SHOW CREATE TABLE table_name, I returned the following results:
CREATE TABLE `users_edi` (
`username` varchar(30) NOT NULL DEFAULT '',
`fullname` varchar(50) DEFAULT NULL,
`userlevel` tinyint(1) unsigned NOT NULL,
`ipaddress` varchar(30) DEFAULT NULL,
`email` varchar(150) DEFAULT NULL,
`entrydate` datetime DEFAULT NULL,
`division` varchar(35) DEFAULT NULL,
`password` varchar(32) DEFAULT NULL,
`userid` varchar(32) DEFAULT NULL,
`timestamp` int(11) unsigned NOT NULL,
`job_title` varchar(30) DEFAULT NULL,
`dept` varchar(50) DEFAULT NULL,
`phone` varchar(11) DEFAULT NULL,
`lastLoginDate` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, // <-- here
PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
The table is years old. I just created the column and somehow, a trigger was set to it (I guess).
Regardless, I tried to remove it using the following command:
ALTER TABLE `users_edi`
`lastLoginDate` datetime DEFAULT NULL
But I only get the following error:
[Err] 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 '`lastLoginDate` datetime DEFAULT NULL' at line 4
How do I remove this trigger using the ALTER TABLE command or any other command?
ALTER TABLE users_edi MODIFY COLUMN lastLoginDate DATETIME DEFAULT NULL;
You might like to read this page on ALTER TABLE: https://dev.mysql.com/doc/refman/8.0/en/alter-table.html
While importing a Database file in myPHP Admin I'm getting the following error:
CREATE TABLE IF NOT EXISTS wpcp_2_aiowps_events ( id bigint(20) NOT NULL AUTO_INCREMENT, event_type varchar(150) NOT NULL DEFAULT '', username varchar(150) DEFAULT NULL, user_id bigint(20) DEFAULT NULL, event_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00', ip_or_host varchar(100) DEFAULT NULL, referer_info varchar(255) DEFAULT NULL, url varchar(255) DEFAULT NULL, country_code varchar(50) DEFAULT NULL, event_data longtext, PRIMARY KEY (id) ) TYPE=MyISAM AUTO_INCREMENT=1 MySQL said: Documentation #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 'TYPE=MyISAM AUTO_INCREMENT=1' at line 13
How can I solve this and import the data successfully without any errors
Note
The older TYPE option was synonymous with ENGINE. TYPE was deprecated in MySQL 4.0 and removed in MySQL 5.5. When upgrading to MySQL 5.5 or later, you must convert existing applications that rely on TYPE to use ENGINE instead.
So you should use
CREATE TABLE IF NOT EXISTS wpcp_2_aiowps_events ( id bigint(20) NOT NULL AUTO_INCREMENT, event_type varchar(150) NOT NULL DEFAULT '', username varchar(150) DEFAULT NULL, user_id bigint(20) DEFAULT NULL, event_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00', ip_or_host varchar(100) DEFAULT NULL, referer_info varchar(255) DEFAULT NULL, url varchar(255) DEFAULT NULL, country_code varchar(50) DEFAULT NULL, event_data longtext, PRIMARY KEY (id) )ENGINE = MyISAM ;
This question already has answers here:
How do you set a default value for a MySQL Datetime column?
(26 answers)
Closed 6 years ago.
here's the table:
CREATE TABLE `obits` (
`pid` int(11) NOT NULL,
`surname` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`firstname` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`middlename` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`maiden` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`presuf` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`birth` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`death` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`obitdate` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`obitsource` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`sourcepage` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`obittext` text COLLATE utf8_unicode_ci,
`DateCreated` DATETIME COLLATE utf8_unicode_ci NOT NULL DEFAULT(GETDATE())
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
here is the error I'm getting: 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 '(GETDATE())
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' at line 14 (line 14 is the datecreated line)
I probably missed something really simple but for the life of me I don't know what. Thank you for any/all help. This table was fine before I tried to re-create it with the datecreated line.
You can't use a function to fill default values in MySql, except CURRENT_TIMESTAMP for TIMESTAMP columns. Prior to version 5.6.5, you must use TIMESTAMP.
DateCreated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
After version 5.6.5, you are able to use DATETIME columns with CURRENT_TIMESTAMP as default value.
I have the following SQL query
CREATE TABLE IF NOT EXISTS `Log` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`customer_id` int(11) unsigned NOT NULL,
`request_xml` BLOB NOT NULL,
`response_xml` LONGBLOB NOT NULL,
`timestamp_process_end` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`timestamp_response` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
);
could someone see any mistakes? Because it gives me a SQL Error when I run the code on server. But on localhost works without any problems (or phpmyadmin)
And btw this works on the server:
CREATE TABLE IF NOT EXISTS `lang` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`language` varchar(2) COLLATE utf8_unicode_ci NOT NULL UNIQUE,
PRIMARY KEY (`id`)
);
that is written in the same style. Any remarks?
LE: Mysql Ver 14.14 Distrib 5.1.73
In the end, the problem was that on the remote server I couldn't have two DEFAULT CURRENT_TIMESTAMP, as stated here mysql link, but this is wired that on the localhost worked.
I am getting the following error message when trying to run some sql code in my 5.5.35-MariaDB. Please can someone help me understand what is wrong?
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 'CREATE TABLE IF NOT EXISTS action_recorder ( id int(11) NOT NULL AUTO_I' at line 1
My code is below:
CREATE TABLE IF NOT EXISTS `action_recorder` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`module` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`user_id` int(11) DEFAULT NULL,
`user_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`success` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
`date_added` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `idx_action_recorder_module` (`module`),
KEY `idx_action_recorder_user_id` (`user_id`),
KEY `idx_action_recorder_identifier` (`identifier`),
KEY `idx_action_recorder_date_added` (`date_added`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=23 ;
Please can someone help me resolve this? Thanks!
You're missing the closing parenthesis. The one at the end is only for the key idx_action_recorder_date_added, but you need another one to close the whole table definition.
Also, I think you shouldn't use those normal single quotes. They are for strings. Use backticks or omit them altogether.
Since the "near..." mentions 'CREATE...', the error is either the CREATE or what immediately precedes it. I vote for the latter -- Look at what have right before it.