I duplicated your tables with this:
Code:
CREATE TABLE category (
category_id int(10) unsigned NOT NULL auto_increment,
`name` varchar(25) NOT NULL,
PRIMARY KEY (category_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO category (category_id, name) VALUES
(1, 'categoryname'),
(2, 'categoryname2');
CREATE TABLE content (
content_id int(10) unsigned NOT NULL auto_increment,
category varchar(25) NOT NULL,
title varchar(25) NOT NULL,
PRIMARY KEY (content_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO content (content_id, category, title) VALUES
(1, 'categoryname', 'title 1'),
(2, 'categoryname2', 'title 2'),
(3, 'categoryname', 'title 3');
I then executed this query:
Code:
UPDATE content c1 SET c1.category=(SELECT c2.category_id FROM category c2 WHERE c2.name=c1.category)
And then changed the field type of category:
Code:
ALTER TABLE `content` CHANGE `category` `category` INT UNSIGNED NOT NULL
Now, I didn't watch my field types very closely. My main goal was to demonstrate how, so be sure to make adjustments based on your field types.
With a lot of records, you may want to run the change on an external server and then import all the changes.
Hope that helps!