A Little Noise

April 9, 2009

errno: 121 (Duplicate key) with CREATE TABLE

Filed under: MySQL FAQ — snoyes @ 7:02 am

Trying to create a table, and getting something like this?

ERROR 1005 (HY000): Can't create table '<db>.<table>' (errno: 121)

Discovered that perror 121 says this?

MySQL error code 121: Duplicate key on write or update

Really confused how you might get a duplicate key error while creating a table?

If the table you’re trying to create includes a foreign key constraint, and you’ve provided your own name for that constraint, remember that it must be unique within the database. Run this query to see if that name is in use somewhere:

SELECT 
  constraint_name,
  table_name
FROM 
  information_schema.table_constraints 
WHERE 
  constraint_type = 'FOREIGN KEY' 
  AND table_schema = DATABASE() 
ORDER BY 
  constraint_name;

(If you’re still on 4.1 or earlier,

mysqldump --no-data yourDbName | grep CONSTRAINT

to get a similar list)

Thanks to [raymond] on Freenode.

April 7, 2009

Error 1307 creating stored procedure

Filed under: MySQL FAQ — snoyes @ 10:52 am

Trying to create a stored procedure, and getting a cryptic error like this?

ERROR 1307 (HY000): Failed to CREATE PROCEDURE <procName>

Try this simple diagnostic query first:

SELECT 
  IF(
    COUNT(*) XOR (CAST(VERSION() AS decimal(2, 1)) >= 5.1), 
    'Wrong mysql.proc table version. Did you forget to run mysql_upgrade?',
    'The mysql.proc table looks ok. Keep hunting.'
  ) AS troubleshooting 
FROM 
  information_schema.columns 
WHERE 
  table_schema = 'mysql' 
  AND table_name = 'proc' 
  AND column_name LIKE 'body_utf8';

February 12, 2009

Location, location, location

Filed under: Kids — snoyes @ 8:19 pm

Iona: What are we watching?
Daddy: Hogan’s Heroes.
Iona: Are they on a boat?
Daddy: No, they’re in a POW camp.
Iona: Oh. New York is sort of like Texas.

February 10, 2009

Misconceptions

Filed under: MySQL FAQ — snoyes @ 9:31 am

Others (including the manual) have said it, and most who bother to read MySQL related blogs know it anyway, but:

* autoincrement does *not* have to be primary, or even unique. Just indexed.
* int(1) and int(100) hold the same range of values. The difference is how many zeros are added if zerofill is turned on.

December 17, 2008

Itsy Bitsy

Filed under: Kids — snoyes @ 12:25 pm

We found a couple of tiny spiders in the door frame of the waiting room.

Iona: “Why do they have spiders?”
Daddy: “They keep them as pets, to catch flies.”
Iona: “They need to build a water spout so they can catch more flies.”

November 27, 2008

The First Day of Christmas

Filed under: Kids — snoyes @ 10:39 am

Daddy: “What do grapes grow on?”
Iona: “Grape vines.”
Daddy: “What do pears grow on?”
Iona: “Pear trees.”
Daddy: “What animal is famous for being in a pear tree in a song?”
Iona: “Polar bears?”

November 24, 2008

Captive Audience

Filed under: Kids — snoyes @ 8:51 am

(while riding in the car)

Iona: Knock knock
Eden: …
Iona: Say, “who’s there?”
Eden: Who there!
Iona: Bacon.
Eden: …
Iona: Say, “bacon who?”
Eden: Bacon who?
Iona: Bakin’ a birthday cake!
Eden: …
Iona: Now, laugh at me.
Eden: ha. ha. ha.

October 11, 2008

What was that diagnosis again?

Filed under: Kids — snoyes @ 11:48 am

Eden: “Iona had to go to the doctor because she had a rash.”
Daddy: “Yep, but the doctor said it wasn’t chicken pox.”
Eden: “Yeah, but the doctor didn’t say it wasn’t popsicles. Or an apple, or a banana either.”

October 10, 2008

Another Parting Shot

Filed under: MySQL Gotchas — snoyes @ 1:38 pm

Related to that last quiz. Here’s the SHOW CREATE TABLE output – I’ve only cleaned up the whitespace.

CREATE TABLE `t1` (
  `id` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 
/*!50100 PARTITION BY RANGE (id) (
  PARTITION p0 VALUES LESS THAN (100) 
    ENGINE = MyISAM, 
  PARTITION p1 VALUES LESS THAN MAXVALUE 
    DATA DIRECTORY = '~/mysql/data/' 
    ENGINE = MyISAM
) */

Now, pay close attention to the rows inserted:

mysql> INSERT INTO t1 VALUES (100);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT COUNT(*) FROM t1;
+----------+
| COUNT(*) |
+----------+
|        1 |
+----------+
1 row in set (0.00 sec)

Ok, here’s the tricky bit:

mysql> SELECT * FROM t1;
Empty set (0.00 sec)

No triggers, no BLACKHOLE, no Proxy, no events or other scheduled tasks, no other connections deleting rows, no temporary tables, and I have all the necessary privileges (including to the data directory shown, which exists and isn’t full). It’s all MyISAM, so surely no transactions. No errors or warnings have been reported.

When you figure it out, don’t do it in your production environment. Bad things happen.

October 2, 2008

How’s that again?

Filed under: Kids — snoyes @ 4:47 pm

Iona: “Is it dried water or cold water?”

« Newer PostsOlder Posts »

Powered by WordPress