I can't figure out which is the query to run in order to see the current collation set for a mysql database.
I know I can change it running a query like this:
ALTER DATABASE db_name
[[DEFAULT] CHARACTER SET charset_name]
[[DEFAULT] COLLATE collation_name]
but I don't want to do it without knowing the current value.
I think it's actually possible because in phpmyadmin you can see the current value in the operation tab of your database, but I need to do it via the command line client and after googling a little bit I found no answers.
Probably I will open phpmyadmin code to discover it.. before doing it, does anybody know which is the right query?
Thanks in advance.
To see the default character set and collation for a given database, use these statements: USE db_name; SELECT @@character_set_database, @@collation_database; Alternatively, to display the values without changing the default database: SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.
mysql> show databases; Here is the output that displays all the databases. As you can see above, we have both databases, and we can get the current database name with the help of DATABASE() method.
The default MySQL server character set and collation are latin1 and latin1_swedish_ci , but you can specify character sets at the server, database, table, column, and string literal levels.
Launch the MySQL Command-Line Client. To launch the client, enter the following command in a Command Prompt window: mysql -u root -p . The -p option is needed only if a root password is defined for MySQL. Enter the password when prompted.
Figured out by myself, looking at phpmyadmin code.
Depending on mysql version, the query to run is this:
SELECT DEFAULT_COLLATION_NAME FROM data_dictionary.SCHEMAS WHERE SCHEMA_NAME = 'nameOfMyDb' LIMIT 1;
or
SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'nameOfMyDb' LIMIT 1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With