when copying a table from database to database with phpMyAdmin, I get an error for Timestamp row.
This is my SQL statement:
CREATE TABLE `database`.`table` ( `id` int( 10 )
unsigned NOT NULL AUTO_INCREMENT ,
`Timestamp` timestamp( 6 ) NOT NULL DEFAULTCURRENT_TIMESTAMP( 6 )
ON UPDATE CURRENT_TIMESTAMP( 6 ) ,
`row3` tinyint( 1 ) DEFAULT NULL COMMENT 'Comment',
`row4` tinyint( 1 ) DEFAULT NULL COMMENT 'comment',
PRIMARY KEY ( `id` ) ,
KEY `keyname` ( `row4` ) ) ENGINE = MyISAM
DEFAULT CHARSET = latin1 COLLATE = latin1_german2_ci
And this is the error message:
#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 'DEFAULTCURRENT_TIMESTAMP( 6 ) ON UPDATE CURRENT_TIMESTAMP( 6 )
at line 2
I think that there is something wrong with DEFAULTCURRENT_TIMESTAMP and Timestamp (6), but I don't know, what.
The version of phpMyAdmin that you're using is extremely old. Currently, version 4.7 is out; your version 2.11.11.3 is over seven years old. Probably this is some bug that has been fixed, but could also be an incompatibility with your PHP, MySQL, and phpMyAdmin versions (depending on what those other versions are). There are some bug reports from around that time that might be related, but it's difficult for me to trace back and test against such old versions. I suggest that you upgrade to the latest version that you're able to (based on the version requirements) and see if the problem continues.
Related
I've finished the first version of my site, and I'm now ready to move it from my local development environment (MySQL) to my x10hosting server (they use MariaDB).
I'm able to move all my files over fine, but the issues started happening when I moved the database over.
I exported my database as a .sql file from phpmyadmin on my local machine, and opened phpmyadmin on x10 to import the file, but it throws this error:
#1067 - Invalid default value for 'created'
I traced the issue to it being that 'created' is a datetime type, and apparently MariaDB doesn't let you set current_timestamp as a default for datetime.
How can I use the current timestamp as the datetime default in maria?
The full create statement is:
CREATE TABLE IF NOT EXISTS `comments` (
`id` BIGINT( 10 ) NOT NULL AUTO_INCREMENT ,
`post` BIGINT( 10 ) NOT NULL ,
`author` VARCHAR( 50 ) NOT NULL ,
`comment` TEXT NOT NULL ,
`mod_status` INT( 2 ) NOT NULL DEFAULT '0' COMMENT '0 is needing moderation, 1 is approved, and 2 is rejected',
`created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( `id` )
) ENGINE = INNODB DEFAULT CHARSET = latin1 AUTO_INCREMENT =4;
In MariaDB you must refer to DEFAULT_TIMESTAMP as a function () :
`created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP(),
^^
Then it will work. Have noticed the same peculiarity when firing INSERT statements using CURRENT_TIMESTAMP or NOW. In MySQL you can do
insert into table (created, id) values ('CURRENT_TIMESTAMP', 42)
in MariaDB it must be
insert into table (created, id) values (CURRENT_TIMESTAMP(), 42)
I guess your column is of type datetime and not timestamp, so you should use
current_date
Have a look at https://mariadb.com/kb/en/mariadb/current_date/
I exported the database, disabling foreign key checks (as advised by the webhost) and then imported it from the cPanel phpMyadmin.
It threw up the error below
Error
SQL query:
-- --------------------------------------------------------
--
-- Table structure for table `club_listing`
--
CREATE TABLE IF NOT EXISTS `club_listing` (
`id` INT( 11 ) NOT NULL ,
`name` VARCHAR( 50 ) NOT NULL ,
`venue` VARCHAR( 100 ) NOT NULL ,
`time` TIME( 4 ) NOT NULL ,
`description1` VARCHAR( 15 ) NOT NULL ,
`description2` VARCHAR( 15 ) NOT NULL ,
`description3` VARCHAR( 15 ) NOT NULL ,
`memberid` INT( 11 ) NOT NULL COMMENT 'foreignkey for members id for management',
`photoid` INT( 11 ) NOT NULL COMMENT 'link to photo table',
`imagefile` VARCHAR( 200 ) NOT 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 '(4) NOT NULL,
description1 varchar(15) NOT NULL,
description2 varchar(15' at line 11
I zeroed the error to be the time datatype. However, I checked the mysql documentation and couldn't find anything that explains the error.
the webhost mysql is version 5.5 while xampp is 5.6
If you create it without the length it will compile, I would suggest that if you can get away with it, then just truncate the time to the correct precision in your sql calls. I was having the same error in phpmyadmin perhaps try it in command line.
SQL query:
CREATE TABLE `comment_threads` (
`comment_id` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0',
`updated` TIMESTAMP NOT NULL ,
`timestamp` TIMESTAMP NOT NULL ,
) ENGINE = MYISAM ;
This is an old file that I'm trying to run on HostGator through phpMyAdmin. I get an error that says:
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 ') ENGINE=MyISAM' at line 5
UPDATE:
If I change the statement to this, I still get an error:
CREATE TABLE comment_threads (
comment_id INT( 11 ) UNSIGNED NOT NULL DEFAULT '0',
updated TIMESTAMP( 14 ) NOT NULL ,
timestamp TIMESTAMP NOT NULL
PRIMARY KEY ( comment_id ) )
ENGINE = MYISAM ;
I get the error:
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 '( 14 ) NOT NULL ,
timestamp TIMESTAMP NOT NULL
PRIMARY KEY ( comment_id ) )
ENGI' at line 3
Your MySQL query is incorrect. Correcting it to this works.
CREATE TABLE `comment_threads` (
`comment_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`updated` TIMESTAMP NOT NULL ,
`timestamp` TIMESTAMP NOT NULL
) ENGINE=MyISAM;
To run this in phpMyAdmin, you can use the in-built table creator or enter the corrected SQL statement in the SQL query window.
Note that I removed the comma after the last TIMESTAMP NOT NULL line (immediately before the ending ).
UPDATE:
The second statement you posted corrects to this:
CREATE TABLE `comment_threads` (
`comment_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`updated` TIMESTAMP NOT NULL ,
`timestamp` TIMESTAMP NOT NULL,
PRIMARY KEY(`comment_id`)
) ENGINE=MyISAM;
Here are the problems you introduced in your second CREATE TABLE statement:
TIMESTAMP( 14 ) should just be TIMESTAMP (per the documentation)
You need a comma after the line TIMESTAMP NOT NULL line. The comma is necessary now because unlike in the first example, you're separated two parts of the statement: the TIMESTAMP NOT NULL line and the PRIMARY KEY declaration.
If you want more information on simple methods for debugging SQL statements, I strongly suggest you look at my answer to this question (see the section titled A bit more information on how to methodically fix errors like this).
Make sure that when you change a CREATE TABLE statement, or any piece of code, that you make changes in small enough increments that you're only "breaking at most one thing at a time." In the case of your second CREATE TABLE statement, there was no reason to change the first TIMESTAMP declaration, and doing so broke the code. That line was working; no need to change it.
CREATE TABLE `db`.`Complete` (
`CompleteId` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`HoursTaken` DOUBLE( 5 ) NOT NULL ,
`DateFinished` DATETIME NOT NULL
) ENGINE = MYISAM
I am trying to create this simple table, however, I get an error. The above code is the code generated by a UI for a MySql database.
I get this 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 ') NOT NULL ,
`DateFinished` DATETIME NOT NULL
) ENGINE = MYISAM' at line 4
I am not sure what to change.
You need to add the precision to the DOUBLE datatype, it should be DOUBLE(5,n) I think.
I solved this by using float instead of double, this was the generated code:
CREATE TABLE `db`.`Complete` (
`CompleteId` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`HoursTaken` FLOAT NOT NULL ,
`DateFinished` DATETIME NOT NULL
) ENGINE = MYISAM
I am trying to copy a MyIsam dataBase from my a remote server to my local machine for testing. I am using phpMyAdmin on the remote server. I select the database and then export. When I try to import (using mamp, phMyAdmin) I get the following error message
Error
SQL query:
CREATE TABLE IF NOT EXISTS `assignments` (
`uid` int( 11 ) default NULL ,
`rid` int( 11 ) default NULL ,
`semester` varchar( 255 ) default NULL ,
`year` int( 11 ) default NULL
) TYPE = MYISAM ;
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 'TYPE=MyISAM' at line 6
Please Help!
Thanks
Try the trick proposed by Reza (Type=InnoDB) but I use MAMP on local machines and it can support either InnoDB/MyISAM… Which version of MAMP do you use ? (I use the free one)
Maybe your local database doesn't support MyISAM type? Does it have to be MyISAM? You can try changing it to 'TYPE=InnoDB' in the sql dump text file