Does phpmyadmin's linter has a bug? - mysql

I created two tables from phpmyadmin like this
CREATE TABLE customers (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(245) DEFAULT NULL,
place varchar(245) DEFAULT NULL,
email varchar(245) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
and another one like this
CREATE TABLE `orders` (
id int(11) NOT NULL AUTO_INCREMENT,
menu_name varchar(245) DEFAULT NULL,
menu_id int(11) DEFAULT NULL,
date_of_order date DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK orders menu_id customer id_idx` (`menu_id`),
CONSTRAINT `FK orders menu_id customer id` FOREIGN KEY (`menu_id`)
REFERENCES `customers` (`id`) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
after this i insert a value in the first table called 'customers' like this:
now after that when i insert values into the 'orders' table, phpmyadmin linter displays error like this:
However, strangely when i click 'Go', the query works fine. It also works fine through the command line too. So is it a bug? or i have to write it in a different way?

Its a bug in phpmyadmin sql query parser in parsing sub queries. The issue is opened and has not been entertained yet.
You have some alternatives here:
Adminer
Or you can try a different mySql client:
MySQL Workbench
HeidiSQL

Yes, phpmyadmin version 4.5.1 had a bug which #Shaharyar mentioned above. i apologize for not posting the version before. However, updating it to version 4.6.3 fixed the issue. Thank you.

Related

MySql multiple columns as primary key doesn't work

I create the MySql table by the following sql statement:
CREATE TABLE IF NOT EXISTS `mytable` (
`agent` varchar(64) NOT NULL,
`name` varchar(40) NOT NULL,
`app` varchar(64) NOT NULL,
PRIMARY KEY (`app`,`agent`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
As you see, the field 'app' and 'agent' is the primary key. But unfortunately it doesn't work when I insert the following data, it always show the duplicated key in 'app' field:
app agent name
-------------------------
MyApp ios cde
MyApp android abc
Can anybody tell me anything wrong? Thanks
In your primary key app and agent are a primary key together, not two individual keys.
You'll be able to add many rows with app = 'MyApp' as long as agent differs. And the other way around.
If you wan't to disallow multiple rows with the same app and multiple rows with the same agent add normal unique indexes.
CREATE TABLE IF NOT EXISTS `mytable` (
`agent` varchar(64) NOT NULL,
`name` varchar(40) NOT NULL,
`app` varchar(64) NOT NULL,
UNIQUE app_index (`app`),
UNIQUE agent_index (`agent`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
The set of primary keys in MySQL does not check for individual unique values, it will give duplicate error when you will try to insert same set of values in multiple records, but both the columns will not accept NULL values
Eg.
app agent name
-------------------------
MyApp ios cde
MyApp ios abc - it will give you error as "Duplicate entry 'MyApp-ios' for key 'PRIMARY'"
may this will help you

Data in database column not showing but exists

I have this problem that occurred today I am left baffled, The issues is that when I insert data in one of my database table called tbl_template_log, it exists but it is not showing in browse mode I am using phpMyAdmin.
But when I click "edit" the data appears correct...
Hopefully my question is understandable if not ask me for additional details.
This is how my data appear in browse Mode:
And The proof that the data in user_id actually exists after running this query "SELECT * FROM tbl_template_log" is here:
tbl_template_log structure:
CREATE TABLE IF NOT EXISTS `tbl_template_log` (
`templog_id` int(6) NOT NULL AUTO_INCREMENT,
`user_id` int(6) DEFAULT NULL,
`temp_id` int(6) DEFAULT NULL,
`savetemp_id` int(6) DEFAULT NULL,
`send_date` datetime NOT NULL,
`send_to` varchar(254) NOT NULL,
`email_send` text NOT NULL,
PRIMARY KEY (`templog_id`),
KEY `tbl_user.user_id` (`user_id`,`temp_id`,`savetemp_id`),
KEY `tbl_template.temp_id` (`temp_id`),
KEY `tbl_saved_template.savetemp_id` (`savetemp_id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=85 ;
--
-- Dumping data for table `tbl_template_log`
--
INSERT INTO `tbl_template_log` (`templog_id`, `user_id`, `temp_id`, `savetemp_id`, `send_date`, `send_to`, `email_send`) VALUES
(83, 77, NULL, NULL, '2014-05-20 22:08:25', 'tomasz#onetwotrade.com', '<html blahh blahh>'),
--
-- Constraints for table `tbl_template_log`
--
ALTER TABLE `tbl_template_log`
ADD CONSTRAINT `tbl_template_log_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `tbl_user` (`user_id`),
ADD CONSTRAINT `tbl_template_log_ibfk_2` FOREIGN KEY (`temp_id`) REFERENCES `tbl_template` (`temp_id`),
ADD CONSTRAINT `tbl_template_log_ibfk_3` FOREIGN KEY (`savetemp_id`) REFERENCES `tbl_saved_template` (`savedtemp_id`);
I have found a problem, firstly thank you all who tried to help me, Funny enough the problem was with my Safari browser :o, I cleared my browsing History, Catche & Cookies then everything started to work suddenly
Scroll all the way down in PHP my admin and change the Show 30 row(s) value to something like 100 or 500 or how many you want.
Your value is most probably on a different page.

Mysql - duplicate entry error for key with auto increment

Why do I get an error of the form:
Error in query: Duplicate entry '10' for key 1
...when doing an INSERT statement like:
INSERT INTO wp_abk_period (pricing_id, apartment_id) VALUES (13, 27)
...with 13 and 27 being valid id-s for existing pricing and apartment rows, and the table is defined as:
CREATE TABLE `wp_abk_period` (
`id` int(11) NOT NULL auto_increment,
`apartment_id` int(11) NOT NULL,
`pricing_id` int(11) NOT NULL,
`type` enum('available','booked','unavailable') collate utf8_unicode_ci default NULL,
`starts` datetime default NULL,
`ends` datetime default NULL,
`recur_type` enum('daily','weekly','monthly','yearly') collate utf8_unicode_ci default NULL,
`recur_every` char(3) collate utf8_unicode_ci default NULL,
`timedate_significance` char(4) collate utf8_unicode_ci default NULL,
`check_in_times` varchar(255) collate utf8_unicode_ci default NULL,
`check_out_times` varchar(255) collate utf8_unicode_ci default NULL,
PRIMARY KEY (`id`),
KEY `fk_period_apartment1_idx` (`apartment_id`),
KEY `fk_period_pricing1_idx` (`pricing_id`),
CONSTRAINT `fk_period_apartment1` FOREIGN KEY (`apartment_id`) REFERENCES `wp_abk_apartment` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_period_pricing1` FOREIGN KEY (`pricing_id`) REFERENCES `wp_abk_pricing` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
Isn't key 1 id in this case and having it on auto_increment sufficient for being able to not specify it?
Note: If I just provide an unused value for id, like INSERT INTO wp_abk_period (id, pricing_id, apartment_id) VALUES (3333333, 13, 27) it works fine, but then again, it is set as auto_increment so I shouldn't need to do this!
Note 2: OK, this is a complete "twilight zone" moment: so after running the query above with the huge number for id, things started working normally, no more duplicate entry errors. Can someone explain me WTF was MySQL doing to produce this weird behavior?
It could be that your AUTO_INCREMENT value for the table and the actual values in id column have got out of whack.
This might help:
Step 1 - Get Max id from table
select max(id) from wp_abk_period
Step 2 - Align the AUTO_INCREMENT counter on table
ALTER TABLE wp_abk_period AUTO_INCREMENT = <value from step 1 + 100>;
Step 3 - Retry the insert
As for why the AUTO_INCREMENT has got out of whack I don't know. Added auto_increment after data was in the table? Altered the auto_increment value after data was inserted into the table?
Hope it helps.
I had the same problem and here is my solution :
My ID column had a bad parameter. It was Tinyint, and MySql want to write a 128th line.
Sometimes, your problem you think the bigger you have is only a tiny parameter...
Late to the party, but I just ran into this tonight - duplicate key '472817' and the provided answers didn't help.
On a whim I ran:
repair table wp_abk_period
which output
Number of rows changed from 472816 to 472817
Seems like mysql had the row count wrong, and the issue went away.
My environment:
mysql Ver 14.14 Distrib 5.1.73, for Win64 (unknown)
Create table syntax:
CREATE TABLE `env_events` (
`tableId` int(11) NOT NULL AUTO_INCREMENT,
`deviceId` varchar(50) DEFAULT NULL,
`timestamp` int(11) DEFAULT NULL,
`temperature` float DEFAULT NULL,
`humidity` float DEFAULT NULL,
`pressure` float DEFAULT NULL,
`motion` int(11) DEFAULT NULL,
PRIMARY KEY (`tableId`)
) ENGINE=MyISAM AUTO_INCREMENT=528521 DEFAULT CHARSET=latin1
You can check the current value of the auto_increment with the following command:
show table status
Then check the max value of the id and see if it looks right. If not change the auto_increment value of your table.
When debugging this problem check the table name case sensitivity (especially if you run MySql not on Windows).
E.g. if one script uses upper case to 'CREATE TABLE my_table' and another script tries to 'INSERT INTO MY_TABLE'. These 2 tables might have different contents and different file system locations which might lead to the described problem.

Codeigniter query create federated table

I'm trying to create a table with this function in Codeigniter
public function createTable($connectionString) {
$createString = "CREATE TABLE {$this->getTabela()} (
`data` datetime NOT NULL,
`idempregado` varchar(45) DEFAULT NULL,
`nif` varchar(15) DEFAULT NULL,
`idsociedade` bigint(20) DEFAULT NULL,
`tipo` varchar(45) DEFAULT NULL,
PRIMARY KEY (`data`),
KEY `fk_assiduidade_user1` (`idempregado`,`nif`,`idsociedade`),
CONSTRAINT `fk_assiduidade_user1` FOREIGN KEY (`idempregado`, `nif`, `idsociedade`) REFERENCES `user` (`idempregado`, `nif`, `idsociedade`) ON DELETE NO ACTION ON UPDATE NO ACTION
)
ENGINE=FEDERATED
DEFAULT CHARSET=utf8
CONNECTION='$connectionString'";
var_dump($createString);
var_dump($this->getDbConnect()->conn_id);
var_dump($this->getDbConnect()->query($createString));
}
But the query is always returning False.
As you guys can see i already made 3 var_dumps to check if its all OK.
Ca you guys help me get to the point where this don't execute the query?
Regards,Elkas
I just found the problem.
After talking with technicians at the Data center (because i dont have access to any logs) i found that they have the FEDERATED engine disabled.
Problem Solved.
Thanks for the tips.

Resolving a duplicate primary key on mysql import

I'm looking to append a comments table from one WordPress site to another. The users are different. When I import the comments from site B to A, I run into a duplicate key issue; comment_id is already taken.
So how can I resolve this and append the table with a simple .sql file? Would I have to take the user information, generate a new user, check for comments made on site B, pull the content and postID, then go back to site A and recreate the comment for the newly created user!?
What a headache! THanks.
if your only problem is a duplicate key issue, go to the end of your sql file after
ENGINE=MyISAM
and make it
ENGINE=MyISAM AutoIncrement=a nubmer above the last id in the new database
or
Query database A for the last id then add one and use it on a new insert query.
Example 1:
CREATE TABLE IF NOT EXISTS `movies` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`year` int(4) NOT NULL,
`size` varchar(255) NOT NULL,
`added` date NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `title` (`title`,`year`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
The Inserts From My Dump:
INSERT INTO `movies` (`title`, `year`, `size`, `added`) VALUES
('[REC] 2', 0, '716688', '2011-09-23'),
('5 Days of War', 0, '1435406', '2012-01-09'),
('[REC]', 0, '1353420800', '2011-11-06');
See how i didnt include the PRIMARY KEY (id) in my includes, but it will still check against my UNIQUE KEY and see if the title exists. Just a little demo that hopefully helps out. If your table already exists on the new database then just skip to the inserts and dont include the primary key and it will be auto set on a new insert to the next available value.