#1071-Specified key was too long; max key length is 1000 bytes - mysql

I've read thoroughly all the other questions/answers on this error before posting.
I am getting the above error for the following query:
CREATE TABLE IF NOT EXISTS `userdata` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`email` varchar(500) NOT NULL,
`password` varchar(500) NOT NULL,
`firstname` varchar(5000) NOT NULL,
`profile` text NOT NULL,
`lastname` varchar(500) NOT NULL,
`address` varchar(5000) NOT NULL,
`bio` varchar(5000) NOT NULL,
`state` varchar(500) NOT NULL,
`city` varchar(500) NOT NULL,
`zipcode` int(11) NOT NULL,
`country` varchar(500) NOT NULL,
`mobile` varchar(5000) NOT NULL,
`status` varchar(5000) NOT NULL,
`type` varchar(5000) NOT NULL,
`adbalance` varchar(500) NOT NULL,
`pubalance` varchar(500) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=604 ;
Does anyone have idea why and how to fix it?
This same query works perfectly on my local machine, and worked as well on my previous host. It's from a mature project - phpdevshell.
I'm using phpMyAdmin.

Related

MYSQL: Why I am not able create table

I am trying copy schema from one MYSQL database to other MYSQL database. While doing so few tables giving problem as follows
Error Code: 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) DEFAULT NULL,
`is_superuser` tinyint(1) NOT NULL,
`username` varchar(30)' at line 4
Execution Time : 0 sec
Transfer Time : 0 sec
Total Time : 0 sec
MYSQL SCRIPT
DROP TABLE IF EXISTS `auth_user`;
CREATE TABLE `auth_user` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`password` VARCHAR(128) NOT NULL,
`last_login` DATETIME(6) DEFAULT NULL,
`is_superuser` TINYINT(1) NOT NULL,
`username` VARCHAR(30) NOT NULL,
`first_name` VARCHAR(30) NOT NULL,
`last_name` VARCHAR(30) NOT NULL,
`email` VARCHAR(254) NOT NULL,
`is_staff` TINYINT(1) NOT NULL,
`is_active` TINYINT(1) NOT NULL,
`date_joined` DATETIME(6) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=INNODB AUTO_INCREMENT=33 DEFAULT CHARSET=latin1;
Change DATETIME TO TIMESTAMP:
like this:
CREATE TABLE `auth_user` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`password` VARCHAR(128) NOT NULL,
`last_login` TIMESTAMP NOT NULL,
`is_superuser` TINYINT(1) NOT NULL,
`username` VARCHAR(30) NOT NULL,
`first_name` VARCHAR(30) NOT NULL,
`last_name` VARCHAR(30) NOT NULL,
`email` VARCHAR(254) NOT NULL,
`is_staff` TINYINT(1) NOT NULL,
`is_active` TINYINT(1) NOT NULL,
`date_joined` TIMESTAMP NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=INNODB AUTO_INCREMENT=33 DEFAULT CHARSET=latin1;
MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.You don't need to specify the length for datetime datatypes
DROP TABLE IF EXISTS `auth_user`;
CREATE TABLE `auth_user` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`password` VARCHAR(128) NOT NULL,
`last_login` DATETIME DEFAULT NULL,
`is_superuser` TINYINT(1) NOT NULL,
`username` VARCHAR(30) NOT NULL,
`first_name` VARCHAR(30) NOT NULL,
`last_name` VARCHAR(30) NOT NULL,
`email` VARCHAR(254) NOT NULL,
`is_staff` TINYINT(1) NOT NULL,
`is_active` TINYINT(1) NOT NULL,
`date_joined` DATETIME NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=INNODB AUTO_INCREMENT=33 DEFAULT CHARSET=latin1;

A closing bracket was expected near ()

CREATE TABLE IF NOT EXISTs `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`firs_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(32) NOT NULL,
`sign_up_date` date (255) NOT NULL,
`activated` enum('0','1') NOT NULL,
PRIMARY KEY `id`
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Problem is here: sign_up_date date (255) NOT NULL
When you refer to date you don't set the maximum of characters.
Try: sign_up_date date NOT NULL
Try with the below code
CREATE TABLE IF NOT EXISTs `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`firs_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(32) NOT NULL,
`sign_up_date` date NOT NULL,
`activated` enum('0','1') NOT NULL,
PRIMARY KEY `id`
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

How can I declare a table without primary key?

I am using MySQL Query Browser.
I have tried this code:
CREATE TABLE `something`.`payment_something` (
`firstName` varchar(15) NOT NULL,
`lastName` varchar(15) NOT NULL,
`inputEmail` varchar(55) NOT NULL,
`genderRadios` varchar(15) NOT NULL,
`monthh` varchar(10) NOT NULL,
`dayy` varchar(10) NOT NULL,
`yearr` varchar(10) NOT NULL,
`postalAddress` varchar(15) NOT NULL,
`phoneNumber` varchar(15) NOT NULL,
`ZipCode` varchar(15) NOT NULL,
`CreditCard` varchar(15) NOT NULL,
`expireMonth` varchar(10) NOT NULL,
`expireYear` varchar(10) NOT NULL,
`Institution` varchar(25) NOT NULL,
`textinput` varchar(15) NOT NULL,
`radios` varchar(10) NOT NULL,
PRIMARY KEY ()
) ENGINE=InnoDB DEFAULT CHARSET=greek;
of course it shows error in the PRIMARY KEY line. Any idea?
EDIT Better solution
CREATE TABLE `something`.`payment_something` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`firstName` varchar(15) NOT NULL,
`lastName` varchar(15) NOT NULL,
`inputEmail` varchar(55) NOT NULL,
`genderRadios` varchar(15) NOT NULL,
`monthh` varchar(10) NOT NULL,
`dayy` varchar(10) NOT NULL,
`yearr` varchar(10) NOT NULL,
`postalAddress` varchar(15) NOT NULL,
`phoneNumber` varchar(15) NOT NULL,
`ZipCode` varchar(15) NOT NULL,
`CreditCard` varchar(15) NOT NULL,
`expireMonth` varchar(10) NOT NULL,
`expireYear` varchar(10) NOT NULL,
`Institution` varchar(25) NOT NULL,
`textinput` varchar(15) NOT NULL,
`radios` varchar(10) NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=greek;
It shows wrong in the PRIMARY KEY line why?
Simply exclude the problematic line:
PRIMARY KEY ()
You don't need to have that line, if you are not actually defining a key. In your example, you will also have to remove the comma directly preceding this line, of course.
UPDATE:
In your updated example, just take the '' off of 'id' when you declare it. Use the backtick (`), instead of the apostrophe:
PRIMARY KEY (`id`)

Duplicate entry '2014-02-28' for key 1 Error Code : 1062

I am getting following error please help me whats the reason
Duplicate entry '2014-02-28' for key 1
CREATE TABLE `th_userinfo` (
`user_id` varchar(250) NOT NULL,
`firstname` varchar(100) default NULL,
`lastname` varchar(100) default NULL,
`fb_id` varchar(250) default NULL,
`email` varchar(255) default NULL,
`gender` varchar(255) default NULL,
`age` varchar(20) default NULL,
`city` varchar(50) default NULL,
`prefix` varchar(10) default NULL,
`mobile` varchar(15) default NULL,
`created` datetime default NULL,
`status` varchar(100) default NULL,
`utm_source` varchar(100) default NULL,
`utm_content` varchar(200) default NULL,
`utm_medium` varchar(100) default NULL,
`utm_campaign` varchar(100) default NULL,
`app_type` varchar(50) default NULL,
`access_token` varchar(250) default NULL,
`modified_access_token` varchar(255) default NULL,
`user_browser` varchar(250) default NULL,
`is_token_expire` varchar(250) default 'No',
`education` varchar(350) default NULL,
`work` text,
PRIMARY KEY (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC
QUERY
UPDATE th_userinfo
SET prefix='0311', mobile='1111111', STATUS='B'
WHERE user_id='1615972863'
You probably have a trigger on that table which inserts/updates values in some other table. This is probably what causes the issue and not the original update on the current th_userinfo table.

mysql Sending data slow on inner join

I have tow SAME dedicated servers.
SQL-query on first work fine and quick.
SELECT
`store_item`.`product_id`
FROM
`store_item`
INNER JOIN `store`
ON (
`store_item`.`store_id` = `store`.`id`
)
WHERE (
`store_item`.`product_id` IN (
<many id (up to 500)>
)
AND `store`.`is_active` = 1
AND `store_item`.`is_available` = 1
)
LIMIT 200 ;
On other server with SAME configuration and SAME version mysql:
What could be wrong?
update 1.
Table stucture are same in both servers.
Structure Table store
CREATE TABLE `store` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` int(11) NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`address` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`phone` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(75) COLLATE utf8_unicode_ci NOT NULL,
`url` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`description` longtext COLLATE utf8_unicode_ci NOT NULL,
`delivery_days` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`currency_id` int(11) NOT NULL,
`account_currency_id` int(11) NOT NULL,
`minimal_margin` decimal(5,2) NOT NULL,
`balance_money` decimal(10,2) NOT NULL,
`total_count` int(11) NOT NULL,
`added_count` int(11) NOT NULL,
`empty_count` int(11) NOT NULL,
`unknown_count` int(11) NOT NULL,
`is_distributor` tinyint(1) NOT NULL,
`is_active` tinyint(1) NOT NULL,
`group` int(11) NOT NULL,
`sort` int(11) NOT NULL,
`return_percent` int(11) NOT NULL,
`updated` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `store_52094d6e` (`name`),
KEY `store_41f657b3` (`currency_id`),
KEY `store_145a375d` (`sort`),
KEY `store_60ef08a5` (`account_currency_id`)
) ENGINE=MyISAM AUTO_INCREMENT=163 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Structure store_item
CREATE TABLE `store_item` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`store_id` int(11) NOT NULL,
`code` varchar(54) COLLATE utf8_unicode_ci NOT NULL,
`product_id` int(11) NOT NULL,
`manufacturer_id` int(11) NOT NULL,
`num` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`description` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`price_in` decimal(10,2) NOT NULL,
`price_out` decimal(10,2) NOT NULL,
`count` int(11) NOT NULL,
`is_available` tinyint(1) NOT NULL,
`delivery_days` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`discount_id` int(11) DEFAULT NULL,
`discount_code` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `store_id` (`store_id`,`product_id`),
KEY `store_item_47799232` (`store_id`),
KEY `store_item_44bdf3ee` (`product_id`),
KEY `store_item_516bb1bd` (`count`),
KEY `store_item_4ac7f441` (`manufacturer_id`),
KEY `store_item_3aac1984` (`num`),
KEY `store_item_52094d6e` (`name`),
KEY `store_item_5c536bf3` (`discount_id`),
KEY `store_item_65da3d2c` (`code`),
KEY `store_item_5436e97a` (`modified`),
KEY `store_item_64b158cd` (`discount_code`),
KEY `store_item_5e0d2c81` (`is_available`)
) ENGINE=MyISAM AUTO_INCREMENT=16070923 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci