Filed Under (Others, mysql) by admin on 14-12-2011
Tagged Under : mysql
Example errors:
“Duplicate entry ’123711155′ for key ‘PRIMARY’” or “Duplicate entry ’14676163′ for key ’1′”
Most likely this happens for tables with more than 5 million records
THE FIX
The fix is to use repair table
REPAIR TABLE <TABLE_NAME>;
Note: Sometimes the duplicate error is also caused by your field type having the maximum value already, for example in tinyint which has the maximum value of 127 so it better to use bigint for your auto ids, if this is not the case you can try the solution above.
Filed Under (mysql) by admin on 10-12-2009
Tagged Under : mysql
Lets say we have this table the ORDERS TABLE
ID customer ordered
—————————-
1111 – John – pizza
2222 – Pete – salad
3333 – Rach – pizza
4444 – Maxx – pizza
5555 – Zigg – rice
1212 – Vinc – salad
4545 – Grac – sushi
1313 – Mark – cake
2424 – Phils – salad
We only want to show items which has been ordered more than 2 times here is our query
—————————————————————————————————————————
SELECT *,count(ordered) as cnt FROM ORDERS group by ordered having cnt > 2
—————————————————————————————————————————-
result:
1111 – John – pizza
3333 – Rach – pizza
4444 – Maxx – pizza
2222 – Pete – salad
1212 – Vinc – salad
2424 – Phils – salad
We use here the having keyword
note: having will work if you have group by on your query
Filed Under (mysql, php) by admin on 26-11-2009
On snow leopard the bundled version of PHP installed is 5.3 And it’s new PHP mysql driver is mysqlnd not the old one (ext/mysql)
This might cause the following error:
mysqlnd cannot connect to MySQL 4.1+ using old authentication
Solution:
type in mysql
SET PASSWORD FOR 'some_user'@'some_host' = OLD_PASSWORD('newpwd');
Findings:
Because mysqlnd has a bigger password hash it will not be compatible anymore with the password written beforehand.
Ref:
http://dev.mysql.com/doc/refman/5.1/en/old-client.html