Mysql change column collation and character set of information schema - mysql

I want to change column collation and character set of system database information_schema...
Can anyone give any input on how to do this? Is there any special priviledges i need for this

To change the character set and collation for all columns in an existing table, use:
ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name [COLLATE collation_name];

As far as I know, you cannot run ALTER TABLE commands on the tables in information_schema. Instead you will probably want to take a look at the character_set_* variabes. You can see which variables are set to which values in your MySQL server with a show variables command:
show variables like "character_set_%";
The variable that has to do with meta data in MySQL, such as the information_schema tables, is the character_set_system variable. I think the my.cnf is the right place to set it.
There's more information on this page: UTF-8 for Metadata.
For ordinary tables, you change the character set of a table with an ALTER TABLE command:
alter table some_table convert to character set utf8;
To do this, you will need the "alter" privilege.
You can see which privileges your MySQL server supports with a show privileges command, and you can see which privileges are granted to your current user with a show grants command.

alter table some_table convert to character set utf8;
awesome that worked great as far as i can tell for me, now i can use chinese in that tables!! and i can remove all the utf8_encode() utf8_decode() throughout my site!

Related

How to tailor mySQL commands to MariaDB?

mySQL. MariaDB Server version
I want to run the following command in mySQL, but there is an error in my syntax that phpMyAdmin console states is related to MariaDB server version.
Alter table page modify column page_title convert to character set latin1_general_ci
How to tailor a mySQL script to MariaDB?
The syntax is indeed incorrect, it is not specific to MariaDB, you would have an error with MySQL as well.
You are mixing up different operations. Either you want to change the whole table (all character columns), and then it is
ALTER TABLE page CONVERT TO CHARACTER SET <character set>
or you want to change the column, and then it is
ALTER TABLE page MODIFY COLUMN page_title <column type> CHARACTER SET <character set>
Please read the documentation carefully to make sure the command that you choose does what you want, it is not always obvious.
Also, latin1_general_ci is not a character set, so you will have another error when you fix the syntax one.

SQL latin1 to utf-8 converting

I have a very big database with data stored on latin1 charsets.
On database with phpmyadmin if i use lines like this:
alter table TABLE_NAME modify FIELD_NAME blob;
alter database DATABASE_NAME charset=utf8;
alter table TABLE_NAME modify FIELD_NAME varchar(255) character set utf8;
All goes on. Text was converting.
But i have a lot of fields, tables. How to make it on all tables, fields? Is there a good convertation php script?
Also i uses on iconv, but no changes from latin1 to utf-8
create new database in utf8
restore your database structure
run "ALTER TABLE the_latin_one CONVERT TO CHARACTER SET utf8;" for all of your tables
create php script that create sql.txt like this
file_put_contents(PATH2."sql.txt","insert into ". $TABLE[0]. " values(". (rtrim($q_col,",") ).");\n",FILE_APPEND);
really you must create all tables insert query. using "show FULL tables where Table_type<>'VIEW'" and "set character set 'latin1'" query may help you for do this. if you have any problem write a comment for me ;)
in command line mysql -u xxx -p yourDB< sql.txt
i do this and solve my problem after 3 years :))

Where can I change the default character set of a table in MySQL Workbench's data modeling tool?

I created a database schema using MySQL Workbench's data modeling tool. When it generates the SQL CREATE statements, it generates "default character set = latin1;" for some tables, e.g.:
-- -----------------------------------------------------
-- Table `moocdb`.`resource_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `moocdb`.`resource_types` (
`resource_type_id` INT(11) NOT NULL,
`resource_type_name` VARCHAR(20) CHARACTER SET 'utf8' NOT NULL,
PRIMARY KEY (`resource_type_id`))
ENGINE = InnoDB
default character set = latin1;
How can I change it to the schema's default character set? (I found where to change the schema's default character set, but not the table's)
As a side note:
Note: Since MySQL 5.5.3 you should use utf8mb4
rather than utf8. They both refer to the UTF-8 encoding, but the
older utf8 had a MySQL-specific limitation preventing use of
characters numbered above 0xFFFD.
You can set the used charset/collation combination in the table editor. You have to expand the header (which is by default collapsed to save space) to be able to change it. See this screenshot:
Thanks a lot for this topic : it saves me a lot of time (I searched the header that was just collapsed by default).
I just want to say that you can specify for the table collation the option : schema default (the first option in the collation drop list).
And then, you can specify too the collation for the text type fields : table default.
With that, you can control the collation of your database with just the global schema collation parameter.
(my mysql workbench version : 6.1.7 revision 11891 build 1788)
Enjoy
Expand the database. Select the table from the tree view-> Right click and select alter table. You will get the following window shown in the screen shot. Here you can change the charset.
To change the entire database in the work bench...
In "Model Overview", under "Physical Schemata", right-click the database and select "Edit Schema...". Define the character set to the "Collation"-field. (MySQL Workbench 5.2.35)
Answered here:
https://stackoverflow.com/a/8149026/5579664
When you open your model, double click (or right click and edit) on MySQL schema, and MySQL Workbench show you, settings for Charset/Collation like as figure

phpmyadmin MySQL data stored as ascii values in certain table

my host has just updated phpmyadmin to version 4.0.3. I don't know if it is related to the following problem.
I have a table 'users' which stores user data for the site and all data is now being stored as numbers. Where I had a username of 'rich' it is now '72696368' which is it's ascii code.
Any ideas why this might have happened? I have a lot of tables and have checked them all, it is only the users table that has been modified. It is not critical as I can still log in and accept new users etc but I would like to know why this is happening.
Thanks a lot
EDIT The collation is utf8_general_c
try adding this snippet to the script you are running in the line in which you create the schema
DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
for example :
CREATE SCHEMA IF NOT EXISTS `my_schema` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

mysql charset cli

how do i determine what a mysql db's charset is set to? in the cli?
SHOW CREATE DATABASE db-name
Will show you the default character set for the database,
SHOW CREATE TABLE db-name.table-name
Will show you the character set for a specific table (along with a lot of other information).
You can use the command "show table status",
it will show you a lot of information (including character set) about your tables
mysql> show table status;