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;
Related
There is a view table created with a mis-encoded query.
Interestingly, the results of "show create table" and "mysqldump" were different.
The result of "show create table" showed the incorrectly encoded part with a question marks.
However, the result of "mysqldump" shows the incorrectly encoded part as the value of bytes.
I want to show like mysqldump result.
mysql> show create table test_view;
CREATE ALGORITHM=UNDEFINED DEFINER=`tester`#`%` SQL SECURITY DEFINER VIEW
`test_view` AS select `test_table`.`idx` AS `Index`,
`test_table`.`tel` AS `???IP` from `test_table` order by `test_table`.`idx`
Use mysqldump...
/*!50001 VIEW `test_view` AS
select `test_table`.`idx` AS `Index`,`test_table`.`tel` AS `�ъ⑹踰IP`
from `test_table`
order by `test_table`.`idx` */;
In MySQL character_set_results configuration variable decides the encoding of the results sent back to the client. Use the same character set from the CLI interface as you use from mysqldump to get the same results. set names also sets this variable.
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
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;
I recently went to backup a database and got the following error "#1007 - Can't create database 'wordpress_8'; database exists".
I have the following line in the beginning of my sql file:
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: 'wordpress_8'
--
CREATE DATABASE wordpress_8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE wordpress_8;
What do I need to change this to in order to insert the subsequent data into the existing "wordpress_8" database rather than create a new one?
Thanks!
To change which database you're using, you use the USE statement. In this case, USE wordpress_8;. Then the actual data needs to be inserted into the tables using INSERT statements.
To ensure a clean restore, I would add:
DROP DATABASE wordpress_8;
Else you're potentially merging two databases, which can get ugly.
Delete
CREATE DATABASE wordpress_8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
and Imropt again ))
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!