Search code examples
mysqlwordpressalter

Running common "alter table" command on mysql returns "no database selected" error


I'm trying to fix some Wordpress character encoding problems by going through and altering all tables to use utf8. But the command I'm using doesn't work.

The command:

ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

The error:

ERROR 1046 (3D000): No database selected

This seems to work for everyone. What am I doing wrong?


Solution

  • you need to specify the database that contains the table you are altering. you can do this in two ways:

    1)

    run this command before your alter table commang:

    USE `database_name`;
    ALTER TABLE `tbl_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
    

    or 2)

    ALTER TABLE `database_name`.`tbl_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;