How to make category for word post_content

I personally find it easier to use built-in WP functions rather than running straight MySQL queries, so here’s one option:

<?php
global $wpdb;
// replace 'yoursearchword' with whatever you're looking for.
// the two % symbols are to find the word no matter what comes before or after.
$query = "SELECT * FROM wp_posts WHERE post_content LIKE %yoursearchword%";
$posts = $wpdb->get_results($query);
foreach($posts as $post) {
    // replace with the desired category ID number.
    wp_set_post_categories($post->ID, array(1));
}
?>

For SEO purposes it’s best to only assign one category per post, which is what this code achieves. Each time you run it, if your search word is found, all categories will be overwritten by just the one you are assigning. If instead you would like posts to be able to live in multiple categories, add true and the function will append (add additional) categories instead of overwriting.

wp_set_post_categories($post->ID, array(1), true);