I am trying to create a new table using the mysql GUI in phpmyadmin. This is the error I am getting #1072 - Key column 'id ' doesn't exist in table
CREATE TABLE `loginsys`.`groups`(
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(20) NOT NULL,
`permission` TEXT NOT NULL,
PRIMARY KEY(`id `)
) ENGINE = InnoDB
Please correct the extra space in when you're defining PRIMARY KEY(id )
This should be your query :-
CREATE TABLE `loginsys`.`groups`(
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(20) NOT NULL,
`permission` TEXT NOT NULL,
PRIMARY KEY(`id`)
) ENGINE = InnoDB
simply run the query without "`"
CREATE TABLE loginsys.groups(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(20) NOT NULL,
permission TEXT NOT NULL,
PRIMARY KEY(id))
So im trying to create this table but im getting a #1064 eroor message. Here is my code: CREATE TABLE JagBank.AccountType ( typeID INT(4) NOT NULL , type VARCHAR(15) NULL , interestRate DOUBLE(4) NULL , PRIMARY KEY (typeID)) ENGINE = InnoDB;
I'm new to php but I was pretty sure this was correct? Whats the problem?
for table jagbank.accounttype
CREATE TABLE IF NOT EXISTS `jagbank.accounttype` (
`typeID` int(11) NOT NULL,
`type` varchar(15) COLLATE latin1_general_ci DEFAULT NULL,
`interestRate` double DEFAULT NULL,
PRIMARY KEY (`typeID`)
) ENGINE=InnoDB
just remove size for double data type,
double data type not having size try query below,
CREATE TABLE JagBank.AccountType ( typeID INT(4) NOT NULL , type VARCHAR(15) NULL , interestRate DOUBLE NULL , PRIMARY KEY (typeID)) ENGINE = InnoDB;
I'm trying to move a WordPress database from Plesk to cPanel using phpMyAdmin but I get the following error when importing:
SQL query:
Table structure for table `wp_commentmeta`
CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
`meta_id` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`comment_id` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT '0',
`meta_key` VARCHAR( 255 ) DEFAULT NULL ,
`meta_value` LONGTEXT
) ENGINE = MYISAM AUTO_INCREMENT =236 DEFAULT CHARSET = utf8;
MySQL said: Documentation
#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
I exported the database using the quick option as I normally do then just did a normal import.
The relevant part of the sql export is:
--
-- Table structure for table `wp_commentmeta`
--
CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL auto_increment,
`comment_id` bigint(20) unsigned NOT NULL default '0',
`meta_key` varchar(255) default NULL,
`meta_value` longtext
) ENGINE=MyISAM AUTO_INCREMENT=236 DEFAULT CHARSET=utf8;
So I tried a solution mentioned on Google
CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL PRIMARY KEY auto_increment,
`comment_id` bigint(20) unsigned NOT NULL default '0',
`meta_key` varchar(255) default NULL,
`meta_value` longtext
) ENGINE=MyISAM AUTO_INCREMENT=236 DEFAULT CHARSET=utf8;
And this time I got this error:
SQL query:
CREATE TABLE IF NOT EXISTS `wp_comments` (
`comment_ID` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`comment_post_ID` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT '0',
`comment_author` TINYTEXT NOT NULL ,
`comment_author_email` VARCHAR( 100 ) NOT NULL DEFAULT '',
`comment_author_url` VARCHAR( 200 ) NOT NULL DEFAULT '',
`comment_author_IP` VARCHAR( 100 ) NOT NULL DEFAULT '',
`comment_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`comment_date_gmt` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`comment_content` TEXT NOT NULL ,
`comment_karma` INT( 11 ) NOT NULL DEFAULT '0',
`comment_approved` VARCHAR( 20 ) NOT NULL DEFAULT '1',
`comment_agent` VARCHAR( 255 ) NOT NULL DEFAULT '',
`comment_type` VARCHAR( 20 ) NOT NULL DEFAULT '',
`comment_parent` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT '0',
`user_id` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT '0'
) ENGINE = MYISAM AUTO_INCREMENT =226 DEFAULT CHARSET = utf8;
MySQL said: Documentation
#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
The CREATE section for wp_comments is as follows.
DROP TABLE IF EXISTS `wp_comments`;
CREATE TABLE IF NOT EXISTS `wp_comments` (
`comment_ID` bigint(20) unsigned NOT NULL auto_increment,
`comment_post_ID` bigint(20) unsigned NOT NULL default '0',
`comment_author` tinytext NOT NULL,
`comment_author_email` varchar(100) NOT NULL default '',
`comment_author_url` varchar(200) NOT NULL default '',
`comment_author_IP` varchar(100) NOT NULL default '',
`comment_date` datetime NOT NULL default '0000-00-00 00:00:00',
`comment_date_gmt` datetime NOT NULL default '0000-00-00 00:00:00',
`comment_content` text NOT NULL,
`comment_karma` int(11) NOT NULL default '0',
`comment_approved` varchar(20) NOT NULL default '1',
`comment_agent` varchar(255) NOT NULL default '',
`comment_type` varchar(20) NOT NULL default '',
`comment_parent` bigint(20) unsigned NOT NULL default '0',
`user_id` bigint(20) unsigned NOT NULL default '0'
) ENGINE=MyISAM AUTO_INCREMENT=226 DEFAULT CHARSET=utf8;
At the bottom of the dump is the following auto_increment information.
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `wp_commentmeta`
--
ALTER TABLE `wp_commentmeta`
AUTO_INCREMENT=236;
--
-- AUTO_INCREMENT for table `wp_comments`
--
ALTER TABLE `wp_comments`
AUTO_INCREMENT=226;
--
-- AUTO_INCREMENT for table `wp_event_list`
--
ALTER TABLE `wp_event_list`
AUTO_INCREMENT=9;
--
-- AUTO_INCREMENT for table `wp_layerslider`
--
ALTER TABLE `wp_layerslider`
AUTO_INCREMENT=6;
--
-- AUTO_INCREMENT for table `wp_options`
--
ALTER TABLE `wp_options`
AUTO_INCREMENT=497473;
--
-- AUTO_INCREMENT for table `wp_postmeta`
--
ALTER TABLE `wp_postmeta`
AUTO_INCREMENT=18312;
--
-- AUTO_INCREMENT for table `wp_posts`
--
ALTER TABLE `wp_posts`
AUTO_INCREMENT=2083;
--
-- AUTO_INCREMENT for table `wp_terms`
--
ALTER TABLE `wp_terms`
AUTO_INCREMENT=136;
--
-- AUTO_INCREMENT for table `wp_term_taxonomy`
--
ALTER TABLE `wp_term_taxonomy`
AUTO_INCREMENT=137;
--
-- AUTO_INCREMENT for table `wp_usermeta`
--
ALTER TABLE `wp_usermeta`
AUTO_INCREMENT=1527;
--
-- AUTO_INCREMENT for table `wp_users`
--
ALTER TABLE `wp_users`
AUTO_INCREMENT=43;
--
-- AUTO_INCREMENT for table `wp_woocommerce_attribute_taxonomies`
--
ALTER TABLE `wp_woocommerce_attribute_taxonomies`
AUTO_INCREMENT=5;
--
-- AUTO_INCREMENT for table `wp_woocommerce_order_itemmeta`
--
ALTER TABLE `wp_woocommerce_order_itemmeta`
AUTO_INCREMENT=1869;
--
-- AUTO_INCREMENT for table `wp_woocommerce_order_items`
--
ALTER TABLE `wp_woocommerce_order_items`
AUTO_INCREMENT=294;
--
-- AUTO_INCREMENT for table `wp_woocommerce_tax_rates`
--
ALTER TABLE `wp_woocommerce_tax_rates`
AUTO_INCREMENT=4;
--
-- AUTO_INCREMENT for table `wp_woocommerce_termmeta`
--
ALTER TABLE `wp_woocommerce_termmeta`
AUTO_INCREMENT=116;
And this is where I'm really stuck as I've rapidly and suddenly reached the limit of my knowledge and don't want to make matters worse. I'm used to seeing the info in the alter table section within the create and don't know id I should be copying it into the create sections or what.
Can someone please provide some hints as to why this is occurring.
Thanks.
For each Wordpress table, add its key in this way (see the penultimate line):
CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL auto_increment,
`comment_id` bigint(20) unsigned NOT NULL default '0',
`meta_key` varchar(255) default NULL,
`meta_value` longtext,
key (meta_id) -- add this line (remember to add the comma in the previous line)
) ENGINE=MyISAM AUTO_INCREMENT=236 DEFAULT CHARSET=utf8;
Wordpress tables:
wp_commentmeta
wp_comments
wp_links
wp_options
wp_postmeta
wp_posts
wp_terms
wp_term_relationships
wp_term_taxonomy
wp_usermeta
wp_users
Possible that you are using two different versions of phpmyadmin, one in plesk, the other one in your cpanel system?
You could try 'Adminer', which is a powerful phpmyadmin alternative and it is based on only one single file!
Download it from here: http://www.adminer.org/en/
Copy adminer.php to the server where you want to get the export from and to the one where you want to import the sql data.
Go to your website/adminer.php and login to your db with the credentials you have. The Export and import is similar to phpmyadmin but the advantage is that you are using one common version of the adminer software which makes sure that import and export is gonna be run fine.
I have the same problem when I export from another phpMyAdmin, the file mysql export does not include primary key in there, then when exporting I choosed method "Custom - display all possible options", then I checked "IF NOT EXISTS (less efficient as indexes will be generated during table creation)". And then the exported file included primary key in the file. And my problem is solved. I hope this help you.
This problem is documented by phpMyAdmin (PMA) and "fixed" by essentially saying that you can't use the current version with MySQL 5.0.
http://sourceforge.net/p/phpmyadmin/bugs/4437/
http://sourceforge.net/p/phpmyadmin/bugs/4261/
Table export with auto_increment, primary key creates invalid statements > Problems due to missing enforcement of the minimum supported MySQL version
Found out my server is running PMA 4.3 with MYSQL 5.0.95 whereas my local is MYSQL 5.5. I don't know why this is a problem now, as older PMA would import/export beautifully as mysqldump, I guess they changed and simplified the syntax for performances reasons which is legit.
If you're like me, you exported your tables from MySQL 5.5 (hosting server) and tried to import into MySQL 5.6 (XAMPP on Mac) and you got the dreaded 1075 error. After searching on the Internet for hours you found out it has something to do with the Auto-increment and Primary key. Not being a database programmer, this information (provided in links by liquified, above) does not help solve the problem as you're basically told: "Hey, don't do that". Well mr. PMA bug, it's already done, so how do I fix it?
Here's what worked for me:
The SQL you exported has a bunch of statements near the bottom to "ALTER" all the tables you created at top. All you need to do is copy into the CREATE statement above.
So, at the bottom, your ALTER wp_commentmeta looks like this:
ALTER TABLE `wp_commentmeta`
ADD PRIMARY KEY (`meta_id`),
ADD KEY `comment_id` (`comment_id`),
ADD KEY `meta_key` (`meta_key`);
And at the top, the CREATE looks like this:
CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL auto_increment,
`comment_id` bigint(20) unsigned NOT NULL default '0',
`meta_key` varchar(255) default NULL,
`meta_value` longtext
) TYPE=MyISAM AUTO_INCREMENT=67;
The solution is to remove the ALTER at bottom and put those statements into the CREATE, like this (adding the comma after the 'longtext'):
CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL auto_increment,
`comment_id` bigint(20) unsigned NOT NULL default '0',
`meta_key` varchar(255) default NULL,
`meta_value` longtext,
PRIMARY KEY (`meta_id`),
KEY `comment_id` (`comment_id`),
KEY `meta_key` (`meta_key`)
) TYPE=MyISAM AUTO_INCREMENT=67;
Now, if you use this, you'll get a 1064 error for bad syntax. Can a guy get a break? You still need to change the MyISAM stuff for this new version:
TYPE=MyISAM AUTO_INCREMENT=67;
change to
ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=67;
In the end your final CREATE declaration will look like this and you won't need any ALTER table statements at the bottom of your SQL:
CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL auto_increment,
`comment_id` bigint(20) unsigned NOT NULL default '0',
`meta_key` varchar(255) default NULL,
`meta_value` longtext,
PRIMARY KEY (`meta_id`),
KEY `comment_id` (`comment_id`),
KEY `meta_key` (`meta_key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=50 ;
Yes, you have to manually edit your SQL if you plan on importing it into the new DB. If you have a lot of tables and/or websites affected by this 'bug', it will take some time, so grab a coffee, whatever works, and fix it and move on with your life.
Now, if you still get errors, check your syntax, make sure to remove 'ADD' when you copy from the ALTER table. Remove ';' and use commas correctly. If you managed to import part of the DB, a few tables, but got snagged on syntax, DUMP all tables and try your import again once you've made the fix. I encountered a 1062: duplicate primary key because I managed to import some tables and others failed. When I tried to import again, the primary key was already set for the table.
All this headache because of performance 'enhancements' in new PMA/MySQL. Humbug!
I've been working for a while with MySQL, and right now I have a problem with some sub query, that takes 60 sec to execute! :(
I should change this because it seems a "bit slow", and I'm no SQL expert, so I figure I'd ask if there's a smarter way of doing this. This is the current query:
SELECT VAR_ID, VAR_REF, DET_VAR_NOMB, DET_VAR_IMG, DET_VAR_MEDIDA, DET_VAR_DETALLE, SEN_FECH, SEN_VALOR
FROM variable, detalle_variable, senal
WHERE equipo_EQO_ID =6
AND detalle_variable_DET_VAR_ID = DET_VAR_ID
AND variable_VAR_ID = VAR_ID
AND SEN_ID
IN (
SELECT MAX( SEN_ID )
FROM senal
GROUP BY variable_VAR_ID
)
The query result is: (and thats all I wish to select)
VAR_ID VAR_REF DET_VAR_NOMB DET_VAR_IMG DET_VAR_MEDIDA DET_VAR_DETALLE SEN_FECH SEN_VALOR
8 101 vsth ../../img/foto/variable/play_blue.png something something 2012-05-30 03:14:17 16
The tables look like this:
-- -----------------------------------------------------
-- Table `pgssgc_stap2`.`detalle_variable`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `pgssgc_stap2`.`detalle_variable` ;
CREATE TABLE IF NOT EXISTS `pgssgc_stap2`.`detalle_variable` (
`DET_VAR_ID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`DET_VAR_NOMB` VARCHAR(45) NOT NULL ,
`DET_VAR_MEDIDA` VARCHAR(45) NULL DEFAULT NULL ,
`DET_VAR_DETALLE` VARCHAR(255) NULL DEFAULT NULL ,
`DET_VAR_IMG` VARCHAR(255) NULL DEFAULT NULL ,
PRIMARY KEY (`DET_VAR_ID`) )
ENGINE = InnoDB
AUTO_INCREMENT = 101
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;
-- -----------------------------------------------------
-- Table `pgssgc_stap2`.`variable`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `pgssgc_stap2`.`variable` ;
CREATE TABLE IF NOT EXISTS `pgssgc_stap2`.`variable` (
`VAR_ID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`VAR_REF` VARCHAR(45) NOT NULL ,
`detalle_variable_DET_VAR_ID` INT(10) UNSIGNED NOT NULL ,
`equipo_EQO_ID` INT(10) UNSIGNED NOT NULL ,
PRIMARY KEY (`VAR_ID`) ,
INDEX `fk_variable_detalle_variable1` (`detalle_variable_DET_VAR_ID` ASC) ,
INDEX `fk_variable_equipo1` (`equipo_EQO_ID` ASC) ,
CONSTRAINT `fk_variable_detalle_variable1`
FOREIGN KEY (`detalle_variable_DET_VAR_ID` )
REFERENCES `pgssgc_stap2`.`detalle_variable` (`DET_VAR_ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_variable_equipo1`
FOREIGN KEY (`equipo_EQO_ID` )
REFERENCES `pgssgc_stap2`.`equipo` (`EQO_ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 11
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;
-- -----------------------------------------------------
-- Table `pgssgc_stap2`.`senal`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `pgssgc_stap2`.`senal` ;
CREATE TABLE IF NOT EXISTS `pgssgc_stap2`.`senal` (
`SEN_ID` INT(11) NOT NULL AUTO_INCREMENT ,
`variable_VAR_ID` INT(10) UNSIGNED NOT NULL ,
`SEN_FECH` DATETIME NULL DEFAULT NULL ,
`SEN_VALOR` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`SEN_ID`) ,
INDEX `fk_senal_variable1` (`variable_VAR_ID` ASC) ,
CONSTRAINT `fk_senal_variable1`
FOREIGN KEY (`variable_VAR_ID` )
REFERENCES `pgssgc_stap2`.`variable` (`VAR_ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 2086
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;
Thank you for your reply.
Assuming that you have problem with jut the sub query.
Make sure that the column variable_VAR_ID of table senal is INDEXED.
I get a lock timeout when updating a certain row in the database. Other rows update okay.
#1205 - Lock wait timeout exceeded; try restarting transaction
How can I unlock this particular row?
Here are the two related tables. I'm trying to update the email on user. I don't think tenant should be causing any problems though.
CREATE TABLE IF NOT EXISTS `mydb`.`user` (
`username` VARCHAR(45) NOT NULL ,
`email` VARCHAR(60) NOT NULL ,
`password` VARCHAR(45) NOT NULL ,
`created` TIMESTAMP NULL DEFAULT NULL ,
`last_login` TIMESTAMP NULL ,
PRIMARY KEY (`username`) )
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `mydb`.`tenant` (
`id` INT NOT NULL AUTO_INCREMENT ,
`username` VARCHAR(45) NOT NULL ,
`address` VARCHAR(90) NULL ,
`company` VARCHAR(45) NULL ,
`phone` VARCHAR(25) NOT NULL ,
`fax` VARCHAR(25) NULL ,
`notes` TEXT NULL ,
`contacts` TEXT NULL ,
PRIMARY KEY (`id`) ,
INDEX `fk_tenant_user1` (`username` ASC) ,
CONSTRAINT `fk_tenant_user1`
FOREIGN KEY (`username` )
REFERENCES `mydb`.`user` (`username` )
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
I ended up just running FLUSH TABLE user and it seems fine now.
Try running the following in an interactive mysql client:
SHOW ENGINE INNODB STATUS\G
And look at the currently open transactions. See if one of them is causing the row to be locked.
In my case MySql fixed itself after 6-7 hours. (When I wake up to solve this problem. It was gone)