I can perfectly visualize the collation of a given table or database by PHPMyAdmin.
But if I did not have this tool mentioned above, how could I do to find the collation by doing a SQL query manually?
I can perfectly visualize the collation of a given table or database by PHPMyAdmin.
But if I did not have this tool mentioned above, how could I do to find the collation by doing a SQL query manually?
Just this:
SHOW CREATE TABLE nomedatabela
And from the database:
SHOW CREATE DATABASE Syntax
The output is something like this:
CREATE TABLE 't' (
'id' int(11) NOT NULL AUTO_INCREMENT,
's' char(60) DEFAULT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=latin1
--^^^^^^-- Aqui é o Charset padrão.
If any column was defined with a different charset , it will also appear in SHOW CREATE
.
More details in the manual:
You can list the collation of each table in a given table using information_schema , as follows:
SELECT table_name, table_collation FROM information_schema.tables
WHERE table_schema = 'nome_da_base'
If you need to return the collation of each column you can use this query:
SELECT column_name, data_type, collation_name FROM information_schema.columns
WHERE table_name = 'nome_da_tabela'