Mysql changes default table encoding to database encoding

I have a problem with charset of mysql table. Each table in my database has a default character set. For instance:

CREATE TABLE privacy_settings (
  id_privacy_setting int(11) NOT NULL AUTO_INCREMENT,
  id_account int(11) NOT NULL,
  setting_name varchar(255) NOT NULL DEFAULT '0',
  privacy_level int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (id_privacy_setting),
  KEY fk_privacy_settings_accounts (id_account),
  CONSTRAINT fk_privacy_settings_accounts FOREIGN KEY (id_account) REFERENCES accounts (id_account) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8  

I want to remove the DEFAULT CHARSET block so that the table can use the default encoding for the database:

CREATE TABLE privacy_settings (
      id_privacy_setting int(11) NOT NULL AUTO_INCREMENT,
      id_account int(11) NOT NULL,
      setting_name varchar(255) NOT NULL DEFAULT '0',
      privacy_level int(11) NOT NULL DEFAULT '0',
      PRIMARY KEY (id_privacy_setting),
      KEY fk_privacy_settings_accounts (id_account),
      CONSTRAINT fk_privacy_settings_accounts FOREIGN KEY (id_account) REFERENCES accounts (id_account) ON DELETE NO ACTION ON UPDATE NO ACTION
    ) ENGINE=InnoDB   

Is there a way to do this without recreating the table?

+5
source share
2 answers

To change the character set of a table, MySQL Documentation :

If you want to change the default character set in the table and all character columns (CHAR, VARCHAR, TEXT) to a new character set, use an instruction like:

ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name;

, : ( )

ALTER DATABASE db_name DEFAULT CHARACTER SET charset_name;
+9

:

alter table TABLENAME convert to CHARACTER SET utf8 COLLATE utf8_unicode_ci;
alter database SCHEMA default character set utf8 COLLATE utf8_unicode_ci;
+2

All Articles