<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gmads</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gmads"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/Special:Contributions/Gmads"/>
	<updated>2026-06-05T12:19:58Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34555</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34555"/>
		<updated>2012-07-23T20:08:21Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;byte&amp;lt;/span&amp;gt; (or &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;octet&amp;lt;/span&amp;gt;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;character&amp;lt;/span&amp;gt; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;character set&amp;lt;/span&amp;gt;, or a &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;coded character set&amp;lt;/span&amp;gt;, refers to the set of characters and numbers, or &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;code points&amp;lt;/span&amp;gt;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;character encoding&amp;lt;/span&amp;gt;, or a &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;character encoding form&amp;lt;/span&amp;gt;, refers to how the code points are converted (encoded) into &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;code values&amp;lt;/span&amp;gt; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;Unicode&amp;lt;/span&amp;gt; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:* &#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;endianness&amp;lt;/span&amp;gt;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;Byte Order Mark&amp;lt;/span&amp;gt; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;Latin-1&amp;lt;/span&amp;gt;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;Latin-9&amp;lt;/span&amp;gt;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value (hex)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039;&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039;&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039;&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;Collation&amp;lt;/span&amp;gt; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In a database, character encoding only applies to text type columns (e.g. CHAR, VARCHAR, TEXT).&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many database stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;character set&amp;lt;/span&amp;gt; is a set of symbols and encodings, and a &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;collation&amp;lt;/span&amp;gt; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;character set&amp;lt;/span&amp;gt; is used, it should actually be &amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;character encoding&amp;lt;/span&amp;gt; (&amp;lt;span style=&amp;quot;color:#800020;&amp;quot;&amp;gt;charset&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;_ci&amp;lt;/tt&amp;gt; (case insensitive), &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;_cs&amp;lt;/tt&amp;gt; (case sensitive), or &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;_bin&amp;lt;/tt&amp;gt; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in CREATE DATABASE statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in CREATE TABLE statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; therefore they do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every character type column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;db_name&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;db_name&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the CREATE DATABASE statement, then they are taken from the server charset and collation values. These two values can be modified via the ALTER DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;my.ini&amp;lt;/tt&amp;gt; (or &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;my.cnf&amp;lt;/tt&amp;gt;) configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBAs (database administrators), however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database &#039;&#039;db_name&#039;&#039;” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;Db characterset&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character_set&amp;lt;/tt&amp;gt; variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;character_set_database&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;COLLATE latin1_spanish_ci&amp;lt;/span&amp;gt; */&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema (database).&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the SHOW and DESCRIBE commands.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;COLLATE latin1_spanish_ci&amp;lt;/span&amp;gt; NOT NULL,&lt;br /&gt;
   `coll_spa` text &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;COLLATE latin1_spanish_ci&amp;lt;/span&amp;gt;,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;COLLATE=latin1_spanish_ci&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;CHARACTER SET latin1 COLLATE latin1_german1_ci&amp;lt;/span&amp;gt; NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Tables, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query lists all tables in a particular schema that differ from a specific collation (e.g. &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;latin1_swedish_ci&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_collation NOT LIKE &#039;&amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;latin1_swedish_ci&amp;lt;/span&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | test03       | t1_default | utf8                | utf8_unicode_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, displaying character data as hexadecimal values =====&lt;br /&gt;
&lt;br /&gt;
Sometimes it is necessary to confirm how text type data (e.g. CHAR, VARCHAR, TEXT) is actually saved (encoded).&lt;br /&gt;
&lt;br /&gt;
To do this, a SELECT query can be created with an &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;HEX()&amp;lt;/tt&amp;gt; function around the column to be checked.&lt;br /&gt;
&lt;br /&gt;
For example, if we have the string “áéíóú” stored in column &#039;&#039;col_name&#039;&#039;, the following query:&lt;br /&gt;
&lt;br /&gt;
 SELECT &#039;&#039;col_name&#039;&#039;, HEX(&#039;&#039;col_name&#039;&#039;) FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Would give the following output if the string was encoded in latin1:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
 | &#039;&#039;col_name&#039;&#039; | HEX(&#039;&#039;col_name&#039;&#039;) |&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
 | áéíóú    | E1E9EDF3FA    |&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
&lt;br /&gt;
And it would give the following output if the string was encoded in utf8:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
 | &#039;&#039;col_name&#039;&#039; | HEX(&#039;&#039;col_name&#039;&#039;)        |&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
 | áéíóú    | C3A1C3A9C3ADC3B3C3BA |&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In this example it is assumed that in each case the column is defined with the correct character set (latin1 and utf8, respectively).&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. CHAR, VARCHAR, TEXT) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. CHAR, VARCHAR, TEXT) columns in all tables of a particular database, that differ from a specific collation (e.g. &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;latin1_swedish_ci&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;latin1_swedish_ci&amp;lt;/span&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;latin1_swedish_ci&amp;lt;/span&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
=== Dumping a database ===&lt;br /&gt;
&lt;br /&gt;
To backup or transfer databases to another SQL server, MySQL includes a client program called &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysqldump&amp;lt;/tt&amp;gt;. This program generates a text file with a series of SQL statements to recreate the original database, its tables and the corresponding data.&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysqldump&amp;lt;/tt&amp;gt; program can be run in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] db_name [tbl_name ...]&lt;br /&gt;
| dumps database, a table or a series of tables&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --databases db_name ...&lt;br /&gt;
| dumps a series of databases&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --all-databases&lt;br /&gt;
| dumps all databases&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This program is simple to use, but it is important to be familiar with a few of its options, as using a wrong setting could lead to corrupted data.&lt;br /&gt;
&lt;br /&gt;
==== Options ====&lt;br /&gt;
&lt;br /&gt;
===== --default-character-set =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--default-character-set&amp;lt;/tt&amp;gt; option defines &#039;&#039;charset_name&#039;&#039; as the default character set.&lt;br /&gt;
&lt;br /&gt;
This is one of the most critical options, as it specifies:&lt;br /&gt;
&lt;br /&gt;
# The file character encoding to be used or how the file is going to be encoded: as column values from the database are read, they are converted to the character set specified by this option before being saved in the dump file (see, Encoding and decoding).&lt;br /&gt;
# The &#039;&#039;default_character_set&#039;&#039; for the SET NAMES statement when the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; or the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; options are not used.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;latin1&amp;lt;/span&amp;gt; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would generate a &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;latin1&amp;lt;/span&amp;gt; encoded dump file; whereas either of the following:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;utf8&amp;lt;/span&amp;gt; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would generate a &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;utf8&amp;lt;/span&amp;gt; encoded dump file.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a character set is not specified (as shown in the last example), &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysqldump&amp;lt;/tt&amp;gt; will use utf8 by default (versions lower than 4.1.2 use latin1 by default).&lt;br /&gt;
&lt;br /&gt;
===== --set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option adds a SET NAMES &#039;&#039;default_character_set&#039;&#039; statement to the output. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
As the SET NAMES &#039;&#039;character_set&#039;&#039; statement is equivalent to the following three statements:&lt;br /&gt;
&lt;br /&gt;
 SET character_set_client = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_results = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_connection = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
the SET NAMES statement specifies the character set to be used (during the restore of the dump file) by the client to send SQL statements to the server, and the character set that the server should use for sending results back to the client (see, For data encoding).&lt;br /&gt;
&lt;br /&gt;
Since this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;latin1&amp;lt;/span&amp;gt; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would add the following conditional comments at the beginning of the dump file:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;&lt;br /&gt;
 /*!40101 SET NAMES &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;latin1&amp;lt;/span&amp;gt; */;&lt;br /&gt;
&lt;br /&gt;
and the following at the end:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;&lt;br /&gt;
&lt;br /&gt;
where the &amp;quot;SET NAMES &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;latin1&amp;lt;/span&amp;gt;&amp;quot; command will instruct the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysql&amp;lt;/tt&amp;gt; program to use, send and receive data encoded in &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;latin1&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== --skip-set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; option is used to disable the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --no-set-names (-N) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; is equivalent to &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt;, and so this option disables the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option: it indicates that a SET NAMES &#039;&#039;default_character_set&#039;&#039; should not be added to the output.&lt;br /&gt;
&lt;br /&gt;
===== --complete-insert (-c) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--complete-insert&amp;lt;/tt&amp;gt; option indicates to use complete INSERT statements that include column names.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;-c&amp;lt;/span&amp;gt; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;(`id`, `string`)&amp;lt;/span&amp;gt; VALUES (1,&#039;text1&#039;),(2,&#039; text2&#039;);&lt;br /&gt;
&lt;br /&gt;
But the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement without the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --extended-insert (-e) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; indicates to use a multiple-row INSERT syntax that include several VALUES lists. This results in smaller dump files and faster inserts when the file is reloaded. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
Since this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes all the records to be added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;(1,&#039;text1&#039;),(2,&#039;text2&#039;)&amp;lt;/span&amp;gt;;&lt;br /&gt;
&lt;br /&gt;
===== --skip-extended-insert =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--skip-extended-insert&amp;lt;/tt&amp;gt; disables the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-extended-insert &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create multiple INSERT statements, one for each record added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (1,&#039;text1&#039;);&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --result-file (-r) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--result-file&amp;lt;/tt&amp;gt; option directs output to a given file.&lt;br /&gt;
&lt;br /&gt;
Since this option prevents newline characters from being converted to carriage return/newline sequences, it should be used when working in a Windows environment:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;-r&amp;lt;/span&amp;gt; backup.sql&lt;br /&gt;
&lt;br /&gt;
instead of using &amp;quot;&amp;gt;&amp;quot; to redirect output to a file:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &amp;gt; backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --single-transaction =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option issues a BEGIN SQL statement before dumping data from the server, and it should be used with transactional tables (like InnoDB).&lt;br /&gt;
&lt;br /&gt;
Since this option and the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--lock-tables&amp;lt;/tt&amp;gt; option are mutually exclusive, the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--skip-lock-tables&amp;lt;/tt&amp;gt; option should also be used prior to using the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &amp;lt;span style=&amp;quot;color:#CC0000;&amp;quot;&amp;gt;--skip-lock-tables --single-transaction&amp;lt;/span&amp;gt; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--opt&amp;lt;/tt&amp;gt; option is shorthand for the following:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| --add-drop-table&lt;br /&gt;
| Add a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
|-&lt;br /&gt;
| --add-locks&lt;br /&gt;
| Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.&lt;br /&gt;
|-&lt;br /&gt;
| --create-options&lt;br /&gt;
| Include all MySQL-specific table options in CREATE TABLE statements.&lt;br /&gt;
|-&lt;br /&gt;
| --disable-keys&lt;br /&gt;
| For each table, surround the INSERT statements with statements to disable and enable keys.&lt;br /&gt;
|-&lt;br /&gt;
| --extended-insert&lt;br /&gt;
| Use multiple-row INSERT syntax that include several VALUES lists.&lt;br /&gt;
|-&lt;br /&gt;
| --lock-tables&lt;br /&gt;
| Lock all tables before dumping them.&lt;br /&gt;
|-&lt;br /&gt;
| --quick&lt;br /&gt;
| Retrieve rows for a table from the server a row at a time.&lt;br /&gt;
|-&lt;br /&gt;
| --set-charset&lt;br /&gt;
| Add SET NAMES default_character_set to the output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Since all of these options are enabled by default, the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--opt&amp;lt;/tt&amp;gt; option is also enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --skip-opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--skip-opt&amp;lt;/tt&amp;gt; disables the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--opt&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-database =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--add-drop-database&amp;lt;/tt&amp;gt; option adds a DROP DATABASE statement before each CREATE DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-table =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;--add-drop-table&amp;lt;/tt&amp;gt; option adds a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
==== Internal structure of a dump file ====&lt;br /&gt;
&lt;br /&gt;
A dump file usually consists of three different elements: comments, conditional comments and SQL statements.&lt;br /&gt;
&lt;br /&gt;
===== Comments =====&lt;br /&gt;
&lt;br /&gt;
Comments are completely ignored by the &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysql&amp;lt;/tt&amp;gt; client program and only serve to describe what follows. Comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 -- &#039;&#039;comment&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 -- MySQL dump 10.13  Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
&lt;br /&gt;
===== Conditional comments =====&lt;br /&gt;
&lt;br /&gt;
Conditional comments are used to hide SET commands or SQL statements from older versions of &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysql&amp;lt;/tt&amp;gt; (used to restore a dump file). Conditional comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 /*!&#039;&#039;five digit version number&#039;&#039; SET|SQL statement */&lt;br /&gt;
&lt;br /&gt;
For example, the following line, which contains two conditional comments:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test04` /*!40100 DEFAULT CHARACTER SET latin1 */;&lt;br /&gt;
&lt;br /&gt;
would be interpreted differently by each &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;mysql&amp;lt;/tt&amp;gt; version:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! mysql versions&lt;br /&gt;
! would read it as&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 3.23.12&lt;br /&gt;
| CREATE DATABASE `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 3.23.12 and &amp;lt; 4.1.0&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;=4.1.0 (4.01.00)&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04` DEFAULT CHARACTER SET latin1;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conditional comments usually set some variables at the beginning of a block and reset them at the end.&lt;br /&gt;
&lt;br /&gt;
About the variable syntax of the SET command:&lt;br /&gt;
&lt;br /&gt;
* The string &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;@@&#039;&#039;variable_name&#039;&#039;&amp;lt;/tt&amp;gt; can refer to a session value or a global value:&lt;br /&gt;
** When being refered, MySQL returns the session value if it exists and the global value otherwise.&lt;br /&gt;
** When being set (e.g. &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;SET @@variable_name=value&amp;lt;/tt&amp;gt;), it always refers to the session value.&lt;br /&gt;
* The string &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;@variable_name&amp;lt;/tt&amp;gt; refers to a user variable.&lt;br /&gt;
* When a variable doesn&#039;t have a modifier, it is a session variable.&lt;br /&gt;
&lt;br /&gt;
===== SQL statements =====&lt;br /&gt;
&lt;br /&gt;
The actual SQL statements, for example:&lt;br /&gt;
&lt;br /&gt;
 USE `&#039;&#039;db_name&#039;&#039;`;&lt;br /&gt;
 DROP TABLE IF EXISTS `&#039;&#039;tbl_name&#039;&#039;`;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt style=&amp;quot;color:#0000b0;&amp;quot;&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34541</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34541"/>
		<updated>2012-07-23T16:43:44Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* SQL statements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:* &#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value (hex)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039;&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039;&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039;&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In a database, character encoding only applies to text type columns (e.g. CHAR, VARCHAR, TEXT).&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many database stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, it should actually be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; therefore they do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every character type column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;db_name&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;db_name&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt;) configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBAs (database administrators), however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database &#039;&#039;db_name&#039;&#039;” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;Db characterset&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the &amp;lt;tt&amp;gt;character_set&amp;lt;/tt&amp;gt; variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema (database).&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the SHOW and DESCRIBE commands.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Tables, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query lists all tables in a particular schema that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_collation NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | test03       | t1_default | utf8                | utf8_unicode_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, displaying character data as hexadecimal values =====&lt;br /&gt;
&lt;br /&gt;
Sometimes it is necessary to confirm how text type data (e.g. CHAR, VARCHAR, TEXT) is actually saved (encoded).&lt;br /&gt;
&lt;br /&gt;
To do this, a SELECT query can be created with an &amp;lt;tt&amp;gt;HEX()&amp;lt;/tt&amp;gt; function around the column to be checked.&lt;br /&gt;
&lt;br /&gt;
For example, if we have the string “áéíóú” stored in column &#039;&#039;col_name&#039;&#039;, the following query:&lt;br /&gt;
&lt;br /&gt;
 SELECT &#039;&#039;col_name&#039;&#039;, HEX(&#039;&#039;col_name&#039;&#039;) FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Would give the following output if the string was encoded in latin1:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
 | &#039;&#039;col_name&#039;&#039; | HEX(&#039;&#039;col_name&#039;&#039;) |&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
 | áéíóú    | E1E9EDF3FA    |&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
&lt;br /&gt;
And it would give the following output if the string was encoded in utf8:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
 | &#039;&#039;col_name&#039;&#039; | HEX(&#039;&#039;col_name&#039;&#039;)        |&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
 | áéíóú    | C3A1C3A9C3ADC3B3C3BA |&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In this example it is assumed that in each case the column is defined with the correct character set (latin1 and utf8, respectively).&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. CHAR, VARCHAR, TEXT) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. CHAR, VARCHAR, TEXT) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
=== Dumping a database ===&lt;br /&gt;
&lt;br /&gt;
To backup or transfer databases to another SQL server, MySQL includes a client program called &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt;. This program generates a text file with a series of SQL statements to recreate the original database, its tables and the corresponding data.&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; program can be run in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] db_name [tbl_name ...]&lt;br /&gt;
| dumps database, a table or a series of tables&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --databases db_name ...&lt;br /&gt;
| dumps a series of databases&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --all-databases&lt;br /&gt;
| dumps all databases&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This program is simple to use, but it is important to be familiar with a few of its options, as using a wrong setting could lead to corrupted data.&lt;br /&gt;
&lt;br /&gt;
==== Options ====&lt;br /&gt;
&lt;br /&gt;
===== --default-character-set =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--default-character-set&amp;lt;/tt&amp;gt; option defines &#039;&#039;charset_name&#039;&#039; as the default character set.&lt;br /&gt;
&lt;br /&gt;
This is one of the most critical options, as it specifies:&lt;br /&gt;
&lt;br /&gt;
# The file character encoding to be used or how the file is going to be encoded: as column values from the database are read, they are converted to the character set specified by this option before being saved in the dump file (see, Encoding and decoding).&lt;br /&gt;
# The &#039;&#039;default_character_set&#039;&#039; for the SET NAMES statement when the &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; options are not used.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would generate a latin1 encoded dump file; whereas either of the following:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=utf8 &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would generate a utf8 encoded dump file.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a character set is not specified (as shown in the last example), &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; will use utf8 by default (versions lower than 4.1.2 use latin1 by default).&lt;br /&gt;
&lt;br /&gt;
===== --set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option adds a SET NAMES &#039;&#039;default_character_set&#039;&#039; statement to the output. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
As the SET NAMES &#039;&#039;character_set&#039;&#039; statement is equivalent to the following three statements:&lt;br /&gt;
&lt;br /&gt;
 SET character_set_client = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_results = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_connection = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
the SET NAMES statement specifies the character set to be used (during the restore of the dump file) by the client to send SQL statements to the server, and the character set that the server should use for sending results back to the client (see, For data encoding).&lt;br /&gt;
&lt;br /&gt;
Since this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would add the following conditional comments at the beginning of the dump file:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;&lt;br /&gt;
 /*!40101 SET NAMES &#039;&#039;latin1&#039;&#039; */;&lt;br /&gt;
&lt;br /&gt;
and the following at the end:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;&lt;br /&gt;
&lt;br /&gt;
where the &amp;quot;SET NAMES &#039;&#039;latin1&#039;&#039;&amp;quot; command will instruct the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; program to use, send and receive data encoded in latin1.&lt;br /&gt;
&lt;br /&gt;
===== --skip-set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; option is used to disable the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --no-set-names (-N) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; is equivalent to &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt;, and so this option disables the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option: it indicates that a SET NAMES &#039;&#039;default_character_set&#039;&#039; should not be added to the output.&lt;br /&gt;
&lt;br /&gt;
===== --complete-insert (-c) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--complete-insert&amp;lt;/tt&amp;gt; option indicates to use complete INSERT statements that include column names.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;&#039;-c&#039;&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` &#039;&#039;&#039;(`id`, `string`)&#039;&#039;&#039; VALUES (1,&#039;text1&#039;),(2,&#039; text2&#039;);&lt;br /&gt;
&lt;br /&gt;
But the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement without the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --extended-insert (-e) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; indicates to use a multiple-row INSERT syntax that include several VALUES lists. This results in smaller dump files and faster inserts when the file is reloaded. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
Since this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes all the records to be added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --skip-extended-insert =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-extended-insert&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-extended-insert &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create multiple INSERT statements, one for each record added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (1,&#039;text1&#039;);&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --result-file (-r) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--result-file&amp;lt;/tt&amp;gt; option directs output to a given file.&lt;br /&gt;
&lt;br /&gt;
Since this option prevents newline characters from being converted to carriage return/newline sequences, it should be used when working in a Windows environment:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &#039;&#039;&#039;-r&#039;&#039;&#039; backup.sql&lt;br /&gt;
&lt;br /&gt;
instead of using &amp;quot;&amp;gt;&amp;quot; to redirect output to a file:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &amp;gt; backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --single-transaction =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option issues a BEGIN SQL statement before dumping data from the server, and it should be used with transactional tables (like InnoDB).&lt;br /&gt;
&lt;br /&gt;
Since this option and the &amp;lt;tt&amp;gt;--lock-tables&amp;lt;/tt&amp;gt; option are mutually exclusive, the &amp;lt;tt&amp;gt;--skip-lock-tables&amp;lt;/tt&amp;gt; option should also be used prior to using the &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-lock-tables --single-transaction &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is shorthand for the following:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| --add-drop-table&lt;br /&gt;
| Add a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
|-&lt;br /&gt;
| --add-locks&lt;br /&gt;
| Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.&lt;br /&gt;
|-&lt;br /&gt;
| --create-options&lt;br /&gt;
| Include all MySQL-specific table options in CREATE TABLE statements.&lt;br /&gt;
|-&lt;br /&gt;
| --disable-keys&lt;br /&gt;
| For each table, surround the INSERT statements with statements to disable and enable keys.&lt;br /&gt;
|-&lt;br /&gt;
| --extended-insert&lt;br /&gt;
| Use multiple-row INSERT syntax that include several VALUES lists.&lt;br /&gt;
|-&lt;br /&gt;
| --lock-tables&lt;br /&gt;
| Lock all tables before dumping them.&lt;br /&gt;
|-&lt;br /&gt;
| --quick&lt;br /&gt;
| Retrieve rows for a table from the server a row at a time.&lt;br /&gt;
|-&lt;br /&gt;
| --set-charset&lt;br /&gt;
| Add SET NAMES default_character_set to the output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Since all of these options are enabled by default, the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is also enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --skip-opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-opt&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-database =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-database&amp;lt;/tt&amp;gt; option adds a DROP DATABASE statement before each CREATE DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-table =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-table&amp;lt;/tt&amp;gt; option adds a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
==== Internal structure of a dump file ====&lt;br /&gt;
&lt;br /&gt;
A dump file usually consists of three different elements: comments, conditional comments and SQL statements.&lt;br /&gt;
&lt;br /&gt;
===== Comments =====&lt;br /&gt;
&lt;br /&gt;
Comments are completely ignored by the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program and only serve to describe what follows. Comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 -- &#039;&#039;comment&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 -- MySQL dump 10.13  Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
&lt;br /&gt;
===== Conditional comments =====&lt;br /&gt;
&lt;br /&gt;
Conditional comments are used to hide SET commands or SQL statements from older versions of &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; (used to restore a dump file). Conditional comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 /*!&#039;&#039;five digit version number&#039;&#039; SET|SQL &#039;&#039;statement&#039;&#039; */&lt;br /&gt;
&lt;br /&gt;
For example, the following line, which contains two conditional comments:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test04` /*!40100 DEFAULT CHARACTER SET latin1 */;&lt;br /&gt;
&lt;br /&gt;
would be interpreted differently by each &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; version:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! mysql versions&lt;br /&gt;
! would read it as&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 3.23.12&lt;br /&gt;
| CREATE DATABASE `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 3.23.12 and &amp;lt; 4.1.0&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;=4.1.0 (4.01.00)&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04` DEFAULT CHARACTER SET latin1;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conditional comments usually set some variables at the beginning of a block and reset them at the end.&lt;br /&gt;
&lt;br /&gt;
About the variable syntax of the SET command:&lt;br /&gt;
&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@@&#039;&#039;variable_name&#039;&#039;&amp;lt;/tt&amp;gt; can refer to a session value or a global value:&lt;br /&gt;
** When being refered, MySQL returns the session value if it exists and the global value otherwise.&lt;br /&gt;
** When being set (e.g. &amp;lt;tt&amp;gt;SET @@variable_name=value&amp;lt;/tt&amp;gt;), it always refers to the session value.&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@variable_name&amp;lt;/tt&amp;gt; refers to a user variable.&lt;br /&gt;
* When a variable doesn&#039;t have a modifier, it is a session variable.&lt;br /&gt;
&lt;br /&gt;
===== SQL statements =====&lt;br /&gt;
&lt;br /&gt;
The actual SQL statements, for example:&lt;br /&gt;
&lt;br /&gt;
 USE `&#039;&#039;db_name&#039;&#039;`;&lt;br /&gt;
 DROP TABLE IF EXISTS `&#039;&#039;tbl_name&#039;&#039;`;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34540</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34540"/>
		<updated>2012-07-23T16:40:34Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Options */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:* &#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value (hex)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039;&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039;&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039;&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In a database, character encoding only applies to text type columns (e.g. CHAR, VARCHAR, TEXT).&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many database stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, it should actually be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; therefore they do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every character type column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;db_name&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;db_name&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt;) configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBAs (database administrators), however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database &#039;&#039;db_name&#039;&#039;” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;Db characterset&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the &amp;lt;tt&amp;gt;character_set&amp;lt;/tt&amp;gt; variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema (database).&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the SHOW and DESCRIBE commands.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Tables, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query lists all tables in a particular schema that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_collation NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | test03       | t1_default | utf8                | utf8_unicode_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, displaying character data as hexadecimal values =====&lt;br /&gt;
&lt;br /&gt;
Sometimes it is necessary to confirm how text type data (e.g. CHAR, VARCHAR, TEXT) is actually saved (encoded).&lt;br /&gt;
&lt;br /&gt;
To do this, a SELECT query can be created with an &amp;lt;tt&amp;gt;HEX()&amp;lt;/tt&amp;gt; function around the column to be checked.&lt;br /&gt;
&lt;br /&gt;
For example, if we have the string “áéíóú” stored in column &#039;&#039;col_name&#039;&#039;, the following query:&lt;br /&gt;
&lt;br /&gt;
 SELECT &#039;&#039;col_name&#039;&#039;, HEX(&#039;&#039;col_name&#039;&#039;) FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Would give the following output if the string was encoded in latin1:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
 | &#039;&#039;col_name&#039;&#039; | HEX(&#039;&#039;col_name&#039;&#039;) |&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
 | áéíóú    | E1E9EDF3FA    |&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
&lt;br /&gt;
And it would give the following output if the string was encoded in utf8:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
 | &#039;&#039;col_name&#039;&#039; | HEX(&#039;&#039;col_name&#039;&#039;)        |&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
 | áéíóú    | C3A1C3A9C3ADC3B3C3BA |&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In this example it is assumed that in each case the column is defined with the correct character set (latin1 and utf8, respectively).&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. CHAR, VARCHAR, TEXT) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. CHAR, VARCHAR, TEXT) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
=== Dumping a database ===&lt;br /&gt;
&lt;br /&gt;
To backup or transfer databases to another SQL server, MySQL includes a client program called &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt;. This program generates a text file with a series of SQL statements to recreate the original database, its tables and the corresponding data.&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; program can be run in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] db_name [tbl_name ...]&lt;br /&gt;
| dumps database, a table or a series of tables&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --databases db_name ...&lt;br /&gt;
| dumps a series of databases&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --all-databases&lt;br /&gt;
| dumps all databases&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This program is simple to use, but it is important to be familiar with a few of its options, as using a wrong setting could lead to corrupted data.&lt;br /&gt;
&lt;br /&gt;
==== Options ====&lt;br /&gt;
&lt;br /&gt;
===== --default-character-set =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--default-character-set&amp;lt;/tt&amp;gt; option defines &#039;&#039;charset_name&#039;&#039; as the default character set.&lt;br /&gt;
&lt;br /&gt;
This is one of the most critical options, as it specifies:&lt;br /&gt;
&lt;br /&gt;
# The file character encoding to be used or how the file is going to be encoded: as column values from the database are read, they are converted to the character set specified by this option before being saved in the dump file (see, Encoding and decoding).&lt;br /&gt;
# The &#039;&#039;default_character_set&#039;&#039; for the SET NAMES statement when the &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; options are not used.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would generate a latin1 encoded dump file; whereas either of the following:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=utf8 &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would generate a utf8 encoded dump file.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a character set is not specified (as shown in the last example), &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; will use utf8 by default (versions lower than 4.1.2 use latin1 by default).&lt;br /&gt;
&lt;br /&gt;
===== --set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option adds a SET NAMES &#039;&#039;default_character_set&#039;&#039; statement to the output. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
As the SET NAMES &#039;&#039;character_set&#039;&#039; statement is equivalent to the following three statements:&lt;br /&gt;
&lt;br /&gt;
 SET character_set_client = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_results = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_connection = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
the SET NAMES statement specifies the character set to be used (during the restore of the dump file) by the client to send SQL statements to the server, and the character set that the server should use for sending results back to the client (see, For data encoding).&lt;br /&gt;
&lt;br /&gt;
Since this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would add the following conditional comments at the beginning of the dump file:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;&lt;br /&gt;
 /*!40101 SET NAMES &#039;&#039;latin1&#039;&#039; */;&lt;br /&gt;
&lt;br /&gt;
and the following at the end:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;&lt;br /&gt;
&lt;br /&gt;
where the &amp;quot;SET NAMES &#039;&#039;latin1&#039;&#039;&amp;quot; command will instruct the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; program to use, send and receive data encoded in latin1.&lt;br /&gt;
&lt;br /&gt;
===== --skip-set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; option is used to disable the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --no-set-names (-N) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; is equivalent to &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt;, and so this option disables the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option: it indicates that a SET NAMES &#039;&#039;default_character_set&#039;&#039; should not be added to the output.&lt;br /&gt;
&lt;br /&gt;
===== --complete-insert (-c) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--complete-insert&amp;lt;/tt&amp;gt; option indicates to use complete INSERT statements that include column names.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;&#039;-c&#039;&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` &#039;&#039;&#039;(`id`, `string`)&#039;&#039;&#039; VALUES (1,&#039;text1&#039;),(2,&#039; text2&#039;);&lt;br /&gt;
&lt;br /&gt;
But the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement without the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --extended-insert (-e) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; indicates to use a multiple-row INSERT syntax that include several VALUES lists. This results in smaller dump files and faster inserts when the file is reloaded. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
Since this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes all the records to be added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --skip-extended-insert =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-extended-insert&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-extended-insert &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create multiple INSERT statements, one for each record added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (1,&#039;text1&#039;);&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --result-file (-r) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--result-file&amp;lt;/tt&amp;gt; option directs output to a given file.&lt;br /&gt;
&lt;br /&gt;
Since this option prevents newline characters from being converted to carriage return/newline sequences, it should be used when working in a Windows environment:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &#039;&#039;&#039;-r&#039;&#039;&#039; backup.sql&lt;br /&gt;
&lt;br /&gt;
instead of using &amp;quot;&amp;gt;&amp;quot; to redirect output to a file:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &amp;gt; backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --single-transaction =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option issues a BEGIN SQL statement before dumping data from the server, and it should be used with transactional tables (like InnoDB).&lt;br /&gt;
&lt;br /&gt;
Since this option and the &amp;lt;tt&amp;gt;--lock-tables&amp;lt;/tt&amp;gt; option are mutually exclusive, the &amp;lt;tt&amp;gt;--skip-lock-tables&amp;lt;/tt&amp;gt; option should also be used prior to using the &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-lock-tables --single-transaction &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is shorthand for the following:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| --add-drop-table&lt;br /&gt;
| Add a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
|-&lt;br /&gt;
| --add-locks&lt;br /&gt;
| Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.&lt;br /&gt;
|-&lt;br /&gt;
| --create-options&lt;br /&gt;
| Include all MySQL-specific table options in CREATE TABLE statements.&lt;br /&gt;
|-&lt;br /&gt;
| --disable-keys&lt;br /&gt;
| For each table, surround the INSERT statements with statements to disable and enable keys.&lt;br /&gt;
|-&lt;br /&gt;
| --extended-insert&lt;br /&gt;
| Use multiple-row INSERT syntax that include several VALUES lists.&lt;br /&gt;
|-&lt;br /&gt;
| --lock-tables&lt;br /&gt;
| Lock all tables before dumping them.&lt;br /&gt;
|-&lt;br /&gt;
| --quick&lt;br /&gt;
| Retrieve rows for a table from the server a row at a time.&lt;br /&gt;
|-&lt;br /&gt;
| --set-charset&lt;br /&gt;
| Add SET NAMES default_character_set to the output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Since all of these options are enabled by default, the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is also enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --skip-opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-opt&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-database =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-database&amp;lt;/tt&amp;gt; option adds a DROP DATABASE statement before each CREATE DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-table =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-table&amp;lt;/tt&amp;gt; option adds a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
==== Internal structure of a dump file ====&lt;br /&gt;
&lt;br /&gt;
A dump file usually consists of three different elements: comments, conditional comments and SQL statements.&lt;br /&gt;
&lt;br /&gt;
===== Comments =====&lt;br /&gt;
&lt;br /&gt;
Comments are completely ignored by the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program and only serve to describe what follows. Comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 -- &#039;&#039;comment&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 -- MySQL dump 10.13  Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
&lt;br /&gt;
===== Conditional comments =====&lt;br /&gt;
&lt;br /&gt;
Conditional comments are used to hide SET commands or SQL statements from older versions of &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; (used to restore a dump file). Conditional comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 /*!&#039;&#039;five digit version number&#039;&#039; SET|SQL &#039;&#039;statement&#039;&#039; */&lt;br /&gt;
&lt;br /&gt;
For example, the following line, which contains two conditional comments:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test04` /*!40100 DEFAULT CHARACTER SET latin1 */;&lt;br /&gt;
&lt;br /&gt;
would be interpreted differently by each &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; version:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! mysql versions&lt;br /&gt;
! would read it as&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 3.23.12&lt;br /&gt;
| CREATE DATABASE `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 3.23.12 and &amp;lt; 4.1.0&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;=4.1.0 (4.01.00)&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04` DEFAULT CHARACTER SET latin1;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conditional comments usually set some variables at the beginning of a block and reset them at the end.&lt;br /&gt;
&lt;br /&gt;
About the variable syntax of the SET command:&lt;br /&gt;
&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@@&#039;&#039;variable_name&#039;&#039;&amp;lt;/tt&amp;gt; can refer to a session value or a global value:&lt;br /&gt;
** When being refered, MySQL returns the session value if it exists and the global value otherwise.&lt;br /&gt;
** When being set (e.g. &amp;lt;tt&amp;gt;SET @@variable_name=value&amp;lt;/tt&amp;gt;), it always refers to the session value.&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@variable_name&amp;lt;/tt&amp;gt; refers to a user variable.&lt;br /&gt;
* When a variable doesn&#039;t have a modifier, it is a session variable.&lt;br /&gt;
&lt;br /&gt;
===== SQL statements =====&lt;br /&gt;
&lt;br /&gt;
The actual SQL statements, for example:&lt;br /&gt;
&lt;br /&gt;
 USE `test04`;&lt;br /&gt;
 DROP TABLE IF EXISTS `t1_latin`;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34539</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34539"/>
		<updated>2012-07-23T16:18:11Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Columns, with different character set and collation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:* &#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value (hex)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039;&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039;&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039;&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In a database, character encoding only applies to text type columns (e.g. CHAR, VARCHAR, TEXT).&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many database stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, it should actually be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; therefore they do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every character type column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;db_name&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;db_name&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt;) configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBAs (database administrators), however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database &#039;&#039;db_name&#039;&#039;” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;Db characterset&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the &amp;lt;tt&amp;gt;character_set&amp;lt;/tt&amp;gt; variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema (database).&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the SHOW and DESCRIBE commands.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Tables, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query lists all tables in a particular schema that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_collation NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | test03       | t1_default | utf8                | utf8_unicode_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, displaying character data as hexadecimal values =====&lt;br /&gt;
&lt;br /&gt;
Sometimes it is necessary to confirm how text type data (e.g. CHAR, VARCHAR, TEXT) is actually saved (encoded).&lt;br /&gt;
&lt;br /&gt;
To do this, a SELECT query can be created with an &amp;lt;tt&amp;gt;HEX()&amp;lt;/tt&amp;gt; function around the column to be checked.&lt;br /&gt;
&lt;br /&gt;
For example, if we have the string “áéíóú” stored in column &#039;&#039;col_name&#039;&#039;, the following query:&lt;br /&gt;
&lt;br /&gt;
 SELECT &#039;&#039;col_name&#039;&#039;, HEX(&#039;&#039;col_name&#039;&#039;) FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Would give the following output if the string was encoded in latin1:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
 | &#039;&#039;col_name&#039;&#039; | HEX(&#039;&#039;col_name&#039;&#039;) |&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
 | áéíóú    | E1E9EDF3FA    |&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
&lt;br /&gt;
And it would give the following output if the string was encoded in utf8:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
 | &#039;&#039;col_name&#039;&#039; | HEX(&#039;&#039;col_name&#039;&#039;)        |&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
 | áéíóú    | C3A1C3A9C3ADC3B3C3BA |&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In this example it is assumed that in each case the column is defined with the correct character set (latin1 and utf8, respectively).&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. CHAR, VARCHAR, TEXT) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. CHAR, VARCHAR, TEXT) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
=== Dumping a database ===&lt;br /&gt;
&lt;br /&gt;
To backup or transfer databases to another SQL server, MySQL includes a client program called &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt;. This program generates a text file with a series of SQL statements to recreate the original database, its tables and the corresponding data.&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; program can be run in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] db_name [tbl_name ...]&lt;br /&gt;
| dumps database, a table or a series of tables&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --databases db_name ...&lt;br /&gt;
| dumps a series of databases&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --all-databases&lt;br /&gt;
| dumps all databases&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This program is simple to use, but it is important to be familiar with a few of its options, as using a wrong setting could lead to corrupted data.&lt;br /&gt;
&lt;br /&gt;
==== Options ====&lt;br /&gt;
&lt;br /&gt;
===== --default-character-set =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--default-character-set&amp;lt;/tt&amp;gt; option sets &#039;&#039;charset_name&#039;&#039; as the default character set.&lt;br /&gt;
&lt;br /&gt;
This option specifies the file character encoding to be used or how the file is going to be encoded: as column values from the database are read, they are converted to the character set specified by this option before being saved in the dump file.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would generate a latin1 encoded dump file (see, Encoding and decoding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a character set is not specified, &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; will use utf8 by default (versions lower than 4.1.2 use latin1 by default).&lt;br /&gt;
&lt;br /&gt;
===== --set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option adds a SET NAMES &#039;&#039;default_character_set&#039;&#039; statement to the output. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
The SET NAMES statement specifies the character set used by the client to send SQL statements to the server, and the character set that the server should use for sending results back to the client (see, For data encoding).&lt;br /&gt;
&lt;br /&gt;
A SET NAMES &#039;&#039;character_set&#039;&#039; statement is equivalent to the following three statements:&lt;br /&gt;
&lt;br /&gt;
 SET character_set_client = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_results = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_connection = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would add the following conditional comments at the beginning of the dump file:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;&lt;br /&gt;
 /*!40101 SET NAMES &#039;&#039;latin1&#039;&#039; */;&lt;br /&gt;
&lt;br /&gt;
and the following at the end:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;SET NAMES latin1&amp;quot; command will instruct the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; program to use, send and receive data encoded in latin1.&lt;br /&gt;
&lt;br /&gt;
===== --skip-set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; option is used to disable the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --no-set-names (-N) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; is equivalent to &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt;, and so this option disables the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option: it doesn’t add a SET NAMES &#039;&#039;default_character_set&#039;&#039; to the output.&lt;br /&gt;
&lt;br /&gt;
===== --complete-insert (-c) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--complete-insert&amp;lt;/tt&amp;gt; option indicates to use complete INSERT statements that include column names.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;&#039;-c&#039;&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` &#039;&#039;&#039;(`id`, `string`)&#039;&#039;&#039; VALUES (1,&#039;text1&#039;),(2,&#039; text2&#039;);&lt;br /&gt;
&lt;br /&gt;
But the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement without the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --extended-insert (-e) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; indicates to use a multiple-row INSERT syntax that include several VALUES lists. This results in smaller dump files and faster inserts when the file is reloaded. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes all the records to be added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --skip-extended-insert =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-extended-insert&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-extended-insert &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create multiple INSERT statements, one for each record added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (1,&#039;text1&#039;);&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --result-file (-r) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--result-file&amp;lt;/tt&amp;gt; option directs output to a given file.&lt;br /&gt;
&lt;br /&gt;
As this option prevents newline characters from being converted to carriage return/newline sequences, it should be used when working in a Windows environment:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &#039;&#039;&#039;-r&#039;&#039;&#039; backup.sql&lt;br /&gt;
&lt;br /&gt;
instead of using &amp;quot;&amp;gt;&amp;quot; to redirect output to a file:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &amp;gt; backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --single-transaction =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option issues a BEGIN SQL statement before dumping data from the server, and it should be used with transactional tables (like InnoDB).&lt;br /&gt;
&lt;br /&gt;
As this option and the &amp;lt;tt&amp;gt;--lock-tables&amp;lt;/tt&amp;gt; option are mutually exclusive, the &amp;lt;tt&amp;gt;--skip-lock-tables&amp;lt;/tt&amp;gt; option should also be used prior to using the &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-lock-tables --single-transaction &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is shorthand for the following:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| --add-drop-table&lt;br /&gt;
| Add a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
|-&lt;br /&gt;
| --add-locks&lt;br /&gt;
| Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.&lt;br /&gt;
|-&lt;br /&gt;
| --create-options&lt;br /&gt;
| Include all MySQL-specific table options in CREATE TABLE statements.&lt;br /&gt;
|-&lt;br /&gt;
| --disable-keys&lt;br /&gt;
| For each table, surround the INSERT statements with statements to disable and enable keys.&lt;br /&gt;
|-&lt;br /&gt;
| --extended-insert&lt;br /&gt;
| Use multiple-row INSERT syntax that include several VALUES lists.&lt;br /&gt;
|-&lt;br /&gt;
| --lock-tables&lt;br /&gt;
| Lock all tables before dumping them.&lt;br /&gt;
|-&lt;br /&gt;
| --quick&lt;br /&gt;
| Retrieve rows for a table from the server a row at a time.&lt;br /&gt;
|-&lt;br /&gt;
| --set-charset&lt;br /&gt;
| Add SET NAMES default_character_set to the output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As all of these options are enabled by default, the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is also enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --skip-opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-opt&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-database =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-database&amp;lt;/tt&amp;gt; option adds a DROP DATABASE statement before each CREATE DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-table =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-table&amp;lt;/tt&amp;gt; option adds a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
==== Internal structure of a dump file ====&lt;br /&gt;
&lt;br /&gt;
A dump file usually consists of three different elements: comments, conditional comments and SQL statements.&lt;br /&gt;
&lt;br /&gt;
===== Comments =====&lt;br /&gt;
&lt;br /&gt;
Comments are completely ignored by the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program and only serve to describe what follows. Comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 -- &#039;&#039;comment&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 -- MySQL dump 10.13  Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
&lt;br /&gt;
===== Conditional comments =====&lt;br /&gt;
&lt;br /&gt;
Conditional comments are used to hide SET commands or SQL statements from older versions of &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; (used to restore a dump file). Conditional comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 /*!&#039;&#039;five digit version number&#039;&#039; SET|SQL &#039;&#039;statement&#039;&#039; */&lt;br /&gt;
&lt;br /&gt;
For example, the following line, which contains two conditional comments:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test04` /*!40100 DEFAULT CHARACTER SET latin1 */;&lt;br /&gt;
&lt;br /&gt;
would be interpreted differently by each &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; version:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! mysql versions&lt;br /&gt;
! would read it as&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 3.23.12&lt;br /&gt;
| CREATE DATABASE `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 3.23.12 and &amp;lt; 4.1.0&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;=4.1.0 (4.01.00)&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04` DEFAULT CHARACTER SET latin1;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conditional comments usually set some variables at the beginning of a block and reset them at the end.&lt;br /&gt;
&lt;br /&gt;
About the variable syntax of the SET command:&lt;br /&gt;
&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@@&#039;&#039;variable_name&#039;&#039;&amp;lt;/tt&amp;gt; can refer to a session value or a global value:&lt;br /&gt;
** When being refered, MySQL returns the session value if it exists and the global value otherwise.&lt;br /&gt;
** When being set (e.g. &amp;lt;tt&amp;gt;SET @@variable_name=value&amp;lt;/tt&amp;gt;), it always refers to the session value.&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@variable_name&amp;lt;/tt&amp;gt; refers to a user variable.&lt;br /&gt;
* When a variable doesn&#039;t have a modifier, it is a session variable.&lt;br /&gt;
&lt;br /&gt;
===== SQL statements =====&lt;br /&gt;
&lt;br /&gt;
The actual SQL statements, for example:&lt;br /&gt;
&lt;br /&gt;
 USE `test04`;&lt;br /&gt;
 DROP TABLE IF EXISTS `t1_latin`;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34538</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34538"/>
		<updated>2012-07-23T16:17:27Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Columns, character set and collation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:* &#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value (hex)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039;&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039;&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039;&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In a database, character encoding only applies to text type columns (e.g. CHAR, VARCHAR, TEXT).&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many database stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, it should actually be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; therefore they do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every character type column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;db_name&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;db_name&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt;) configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBAs (database administrators), however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database &#039;&#039;db_name&#039;&#039;” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;Db characterset&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the &amp;lt;tt&amp;gt;character_set&amp;lt;/tt&amp;gt; variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema (database).&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the SHOW and DESCRIBE commands.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Tables, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query lists all tables in a particular schema that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_collation NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | test03       | t1_default | utf8                | utf8_unicode_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, displaying character data as hexadecimal values =====&lt;br /&gt;
&lt;br /&gt;
Sometimes it is necessary to confirm how text type data (e.g. CHAR, VARCHAR, TEXT) is actually saved (encoded).&lt;br /&gt;
&lt;br /&gt;
To do this, a SELECT query can be created with an &amp;lt;tt&amp;gt;HEX()&amp;lt;/tt&amp;gt; function around the column to be checked.&lt;br /&gt;
&lt;br /&gt;
For example, if we have the string “áéíóú” stored in column &#039;&#039;col_name&#039;&#039;, the following query:&lt;br /&gt;
&lt;br /&gt;
 SELECT &#039;&#039;col_name&#039;&#039;, HEX(&#039;&#039;col_name&#039;&#039;) FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Would give the following output if the string was encoded in latin1:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
 | &#039;&#039;col_name&#039;&#039; | HEX(&#039;&#039;col_name&#039;&#039;) |&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
 | áéíóú    | E1E9EDF3FA    |&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
&lt;br /&gt;
And it would give the following output if the string was encoded in utf8:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
 | &#039;&#039;col_name&#039;&#039; | HEX(&#039;&#039;col_name&#039;&#039;)        |&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
 | áéíóú    | C3A1C3A9C3ADC3B3C3BA |&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In this example it is assumed that in each case the column is defined with the correct character set (latin1 and utf8, respectively).&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. CHAR, VARCHAR, TEXT) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
=== Dumping a database ===&lt;br /&gt;
&lt;br /&gt;
To backup or transfer databases to another SQL server, MySQL includes a client program called &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt;. This program generates a text file with a series of SQL statements to recreate the original database, its tables and the corresponding data.&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; program can be run in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] db_name [tbl_name ...]&lt;br /&gt;
| dumps database, a table or a series of tables&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --databases db_name ...&lt;br /&gt;
| dumps a series of databases&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --all-databases&lt;br /&gt;
| dumps all databases&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This program is simple to use, but it is important to be familiar with a few of its options, as using a wrong setting could lead to corrupted data.&lt;br /&gt;
&lt;br /&gt;
==== Options ====&lt;br /&gt;
&lt;br /&gt;
===== --default-character-set =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--default-character-set&amp;lt;/tt&amp;gt; option sets &#039;&#039;charset_name&#039;&#039; as the default character set.&lt;br /&gt;
&lt;br /&gt;
This option specifies the file character encoding to be used or how the file is going to be encoded: as column values from the database are read, they are converted to the character set specified by this option before being saved in the dump file.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would generate a latin1 encoded dump file (see, Encoding and decoding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a character set is not specified, &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; will use utf8 by default (versions lower than 4.1.2 use latin1 by default).&lt;br /&gt;
&lt;br /&gt;
===== --set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option adds a SET NAMES &#039;&#039;default_character_set&#039;&#039; statement to the output. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
The SET NAMES statement specifies the character set used by the client to send SQL statements to the server, and the character set that the server should use for sending results back to the client (see, For data encoding).&lt;br /&gt;
&lt;br /&gt;
A SET NAMES &#039;&#039;character_set&#039;&#039; statement is equivalent to the following three statements:&lt;br /&gt;
&lt;br /&gt;
 SET character_set_client = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_results = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_connection = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would add the following conditional comments at the beginning of the dump file:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;&lt;br /&gt;
 /*!40101 SET NAMES &#039;&#039;latin1&#039;&#039; */;&lt;br /&gt;
&lt;br /&gt;
and the following at the end:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;SET NAMES latin1&amp;quot; command will instruct the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; program to use, send and receive data encoded in latin1.&lt;br /&gt;
&lt;br /&gt;
===== --skip-set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; option is used to disable the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --no-set-names (-N) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; is equivalent to &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt;, and so this option disables the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option: it doesn’t add a SET NAMES &#039;&#039;default_character_set&#039;&#039; to the output.&lt;br /&gt;
&lt;br /&gt;
===== --complete-insert (-c) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--complete-insert&amp;lt;/tt&amp;gt; option indicates to use complete INSERT statements that include column names.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;&#039;-c&#039;&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` &#039;&#039;&#039;(`id`, `string`)&#039;&#039;&#039; VALUES (1,&#039;text1&#039;),(2,&#039; text2&#039;);&lt;br /&gt;
&lt;br /&gt;
But the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement without the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --extended-insert (-e) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; indicates to use a multiple-row INSERT syntax that include several VALUES lists. This results in smaller dump files and faster inserts when the file is reloaded. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes all the records to be added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --skip-extended-insert =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-extended-insert&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-extended-insert &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create multiple INSERT statements, one for each record added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (1,&#039;text1&#039;);&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --result-file (-r) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--result-file&amp;lt;/tt&amp;gt; option directs output to a given file.&lt;br /&gt;
&lt;br /&gt;
As this option prevents newline characters from being converted to carriage return/newline sequences, it should be used when working in a Windows environment:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &#039;&#039;&#039;-r&#039;&#039;&#039; backup.sql&lt;br /&gt;
&lt;br /&gt;
instead of using &amp;quot;&amp;gt;&amp;quot; to redirect output to a file:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &amp;gt; backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --single-transaction =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option issues a BEGIN SQL statement before dumping data from the server, and it should be used with transactional tables (like InnoDB).&lt;br /&gt;
&lt;br /&gt;
As this option and the &amp;lt;tt&amp;gt;--lock-tables&amp;lt;/tt&amp;gt; option are mutually exclusive, the &amp;lt;tt&amp;gt;--skip-lock-tables&amp;lt;/tt&amp;gt; option should also be used prior to using the &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-lock-tables --single-transaction &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is shorthand for the following:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| --add-drop-table&lt;br /&gt;
| Add a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
|-&lt;br /&gt;
| --add-locks&lt;br /&gt;
| Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.&lt;br /&gt;
|-&lt;br /&gt;
| --create-options&lt;br /&gt;
| Include all MySQL-specific table options in CREATE TABLE statements.&lt;br /&gt;
|-&lt;br /&gt;
| --disable-keys&lt;br /&gt;
| For each table, surround the INSERT statements with statements to disable and enable keys.&lt;br /&gt;
|-&lt;br /&gt;
| --extended-insert&lt;br /&gt;
| Use multiple-row INSERT syntax that include several VALUES lists.&lt;br /&gt;
|-&lt;br /&gt;
| --lock-tables&lt;br /&gt;
| Lock all tables before dumping them.&lt;br /&gt;
|-&lt;br /&gt;
| --quick&lt;br /&gt;
| Retrieve rows for a table from the server a row at a time.&lt;br /&gt;
|-&lt;br /&gt;
| --set-charset&lt;br /&gt;
| Add SET NAMES default_character_set to the output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As all of these options are enabled by default, the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is also enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --skip-opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-opt&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-database =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-database&amp;lt;/tt&amp;gt; option adds a DROP DATABASE statement before each CREATE DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-table =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-table&amp;lt;/tt&amp;gt; option adds a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
==== Internal structure of a dump file ====&lt;br /&gt;
&lt;br /&gt;
A dump file usually consists of three different elements: comments, conditional comments and SQL statements.&lt;br /&gt;
&lt;br /&gt;
===== Comments =====&lt;br /&gt;
&lt;br /&gt;
Comments are completely ignored by the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program and only serve to describe what follows. Comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 -- &#039;&#039;comment&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 -- MySQL dump 10.13  Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
&lt;br /&gt;
===== Conditional comments =====&lt;br /&gt;
&lt;br /&gt;
Conditional comments are used to hide SET commands or SQL statements from older versions of &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; (used to restore a dump file). Conditional comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 /*!&#039;&#039;five digit version number&#039;&#039; SET|SQL &#039;&#039;statement&#039;&#039; */&lt;br /&gt;
&lt;br /&gt;
For example, the following line, which contains two conditional comments:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test04` /*!40100 DEFAULT CHARACTER SET latin1 */;&lt;br /&gt;
&lt;br /&gt;
would be interpreted differently by each &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; version:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! mysql versions&lt;br /&gt;
! would read it as&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 3.23.12&lt;br /&gt;
| CREATE DATABASE `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 3.23.12 and &amp;lt; 4.1.0&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;=4.1.0 (4.01.00)&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04` DEFAULT CHARACTER SET latin1;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conditional comments usually set some variables at the beginning of a block and reset them at the end.&lt;br /&gt;
&lt;br /&gt;
About the variable syntax of the SET command:&lt;br /&gt;
&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@@&#039;&#039;variable_name&#039;&#039;&amp;lt;/tt&amp;gt; can refer to a session value or a global value:&lt;br /&gt;
** When being refered, MySQL returns the session value if it exists and the global value otherwise.&lt;br /&gt;
** When being set (e.g. &amp;lt;tt&amp;gt;SET @@variable_name=value&amp;lt;/tt&amp;gt;), it always refers to the session value.&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@variable_name&amp;lt;/tt&amp;gt; refers to a user variable.&lt;br /&gt;
* When a variable doesn&#039;t have a modifier, it is a session variable.&lt;br /&gt;
&lt;br /&gt;
===== SQL statements =====&lt;br /&gt;
&lt;br /&gt;
The actual SQL statements, for example:&lt;br /&gt;
&lt;br /&gt;
 USE `test04`;&lt;br /&gt;
 DROP TABLE IF EXISTS `t1_latin`;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34537</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34537"/>
		<updated>2012-07-23T16:16:30Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Columns, character set and collation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:* &#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value (hex)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039;&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039;&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039;&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In a database, character encoding only applies to text type columns (e.g. CHAR, VARCHAR, TEXT).&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many database stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, it should actually be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; therefore they do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every character type column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;db_name&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;db_name&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt;) configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBAs (database administrators), however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database &#039;&#039;db_name&#039;&#039;” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;Db characterset&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the &amp;lt;tt&amp;gt;character_set&amp;lt;/tt&amp;gt; variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema (database).&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the SHOW and DESCRIBE commands.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Tables, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query lists all tables in a particular schema that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_collation NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | test03       | t1_default | utf8                | utf8_unicode_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, displaying character data as hexadecimal values =====&lt;br /&gt;
&lt;br /&gt;
Sometimes it is necessary to confirm how text type data (e.g. CHAR, VARCHAR, TEXT) is actually saved (encoded).&lt;br /&gt;
&lt;br /&gt;
To do this, a SELECT query can be created with an &amp;lt;tt&amp;gt;HEX()&amp;lt;/tt&amp;gt; function around the column to be checked.&lt;br /&gt;
&lt;br /&gt;
For example, if we have the string “áéíóú” stored in column &#039;&#039;col_name&#039;&#039;, the following query:&lt;br /&gt;
&lt;br /&gt;
 SELECT &#039;&#039;col_name&#039;&#039;, HEX(&#039;&#039;col_name&#039;&#039;) FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Would give the following output if the string was encoded in latin1:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
 | &#039;&#039;col_name&#039;&#039; | HEX(&#039;&#039;col_name&#039;&#039;) |&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
 | áéíóú    | E1E9EDF3FA    |&lt;br /&gt;
 +----------+---------------+&lt;br /&gt;
&lt;br /&gt;
And it would give the following output if the string was encoded in utf8:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
 | &#039;&#039;col_name&#039;&#039; | HEX(&#039;&#039;col_name&#039;&#039;)        |&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
 | áéíóú    | C3A1C3A9C3ADC3B3C3BA |&lt;br /&gt;
 +----------+----------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In this example it is assumed that in each case the column is defined with the correct character set (latin1 and utf8, respectively).&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
=== Dumping a database ===&lt;br /&gt;
&lt;br /&gt;
To backup or transfer databases to another SQL server, MySQL includes a client program called &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt;. This program generates a text file with a series of SQL statements to recreate the original database, its tables and the corresponding data.&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; program can be run in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] db_name [tbl_name ...]&lt;br /&gt;
| dumps database, a table or a series of tables&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --databases db_name ...&lt;br /&gt;
| dumps a series of databases&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --all-databases&lt;br /&gt;
| dumps all databases&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This program is simple to use, but it is important to be familiar with a few of its options, as using a wrong setting could lead to corrupted data.&lt;br /&gt;
&lt;br /&gt;
==== Options ====&lt;br /&gt;
&lt;br /&gt;
===== --default-character-set =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--default-character-set&amp;lt;/tt&amp;gt; option sets &#039;&#039;charset_name&#039;&#039; as the default character set.&lt;br /&gt;
&lt;br /&gt;
This option specifies the file character encoding to be used or how the file is going to be encoded: as column values from the database are read, they are converted to the character set specified by this option before being saved in the dump file.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would generate a latin1 encoded dump file (see, Encoding and decoding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a character set is not specified, &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; will use utf8 by default (versions lower than 4.1.2 use latin1 by default).&lt;br /&gt;
&lt;br /&gt;
===== --set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option adds a SET NAMES &#039;&#039;default_character_set&#039;&#039; statement to the output. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
The SET NAMES statement specifies the character set used by the client to send SQL statements to the server, and the character set that the server should use for sending results back to the client (see, For data encoding).&lt;br /&gt;
&lt;br /&gt;
A SET NAMES &#039;&#039;character_set&#039;&#039; statement is equivalent to the following three statements:&lt;br /&gt;
&lt;br /&gt;
 SET character_set_client = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_results = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_connection = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would add the following conditional comments at the beginning of the dump file:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;&lt;br /&gt;
 /*!40101 SET NAMES &#039;&#039;latin1&#039;&#039; */;&lt;br /&gt;
&lt;br /&gt;
and the following at the end:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;SET NAMES latin1&amp;quot; command will instruct the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; program to use, send and receive data encoded in latin1.&lt;br /&gt;
&lt;br /&gt;
===== --skip-set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; option is used to disable the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --no-set-names (-N) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; is equivalent to &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt;, and so this option disables the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option: it doesn’t add a SET NAMES &#039;&#039;default_character_set&#039;&#039; to the output.&lt;br /&gt;
&lt;br /&gt;
===== --complete-insert (-c) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--complete-insert&amp;lt;/tt&amp;gt; option indicates to use complete INSERT statements that include column names.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;&#039;-c&#039;&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` &#039;&#039;&#039;(`id`, `string`)&#039;&#039;&#039; VALUES (1,&#039;text1&#039;),(2,&#039; text2&#039;);&lt;br /&gt;
&lt;br /&gt;
But the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement without the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --extended-insert (-e) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; indicates to use a multiple-row INSERT syntax that include several VALUES lists. This results in smaller dump files and faster inserts when the file is reloaded. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes all the records to be added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --skip-extended-insert =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-extended-insert&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-extended-insert &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create multiple INSERT statements, one for each record added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (1,&#039;text1&#039;);&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --result-file (-r) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--result-file&amp;lt;/tt&amp;gt; option directs output to a given file.&lt;br /&gt;
&lt;br /&gt;
As this option prevents newline characters from being converted to carriage return/newline sequences, it should be used when working in a Windows environment:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &#039;&#039;&#039;-r&#039;&#039;&#039; backup.sql&lt;br /&gt;
&lt;br /&gt;
instead of using &amp;quot;&amp;gt;&amp;quot; to redirect output to a file:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &amp;gt; backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --single-transaction =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option issues a BEGIN SQL statement before dumping data from the server, and it should be used with transactional tables (like InnoDB).&lt;br /&gt;
&lt;br /&gt;
As this option and the &amp;lt;tt&amp;gt;--lock-tables&amp;lt;/tt&amp;gt; option are mutually exclusive, the &amp;lt;tt&amp;gt;--skip-lock-tables&amp;lt;/tt&amp;gt; option should also be used prior to using the &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-lock-tables --single-transaction &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is shorthand for the following:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| --add-drop-table&lt;br /&gt;
| Add a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
|-&lt;br /&gt;
| --add-locks&lt;br /&gt;
| Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.&lt;br /&gt;
|-&lt;br /&gt;
| --create-options&lt;br /&gt;
| Include all MySQL-specific table options in CREATE TABLE statements.&lt;br /&gt;
|-&lt;br /&gt;
| --disable-keys&lt;br /&gt;
| For each table, surround the INSERT statements with statements to disable and enable keys.&lt;br /&gt;
|-&lt;br /&gt;
| --extended-insert&lt;br /&gt;
| Use multiple-row INSERT syntax that include several VALUES lists.&lt;br /&gt;
|-&lt;br /&gt;
| --lock-tables&lt;br /&gt;
| Lock all tables before dumping them.&lt;br /&gt;
|-&lt;br /&gt;
| --quick&lt;br /&gt;
| Retrieve rows for a table from the server a row at a time.&lt;br /&gt;
|-&lt;br /&gt;
| --set-charset&lt;br /&gt;
| Add SET NAMES default_character_set to the output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As all of these options are enabled by default, the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is also enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --skip-opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-opt&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-database =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-database&amp;lt;/tt&amp;gt; option adds a DROP DATABASE statement before each CREATE DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-table =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-table&amp;lt;/tt&amp;gt; option adds a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
==== Internal structure of a dump file ====&lt;br /&gt;
&lt;br /&gt;
A dump file usually consists of three different elements: comments, conditional comments and SQL statements.&lt;br /&gt;
&lt;br /&gt;
===== Comments =====&lt;br /&gt;
&lt;br /&gt;
Comments are completely ignored by the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program and only serve to describe what follows. Comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 -- &#039;&#039;comment&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 -- MySQL dump 10.13  Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
&lt;br /&gt;
===== Conditional comments =====&lt;br /&gt;
&lt;br /&gt;
Conditional comments are used to hide SET commands or SQL statements from older versions of &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; (used to restore a dump file). Conditional comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 /*!&#039;&#039;five digit version number&#039;&#039; SET|SQL &#039;&#039;statement&#039;&#039; */&lt;br /&gt;
&lt;br /&gt;
For example, the following line, which contains two conditional comments:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test04` /*!40100 DEFAULT CHARACTER SET latin1 */;&lt;br /&gt;
&lt;br /&gt;
would be interpreted differently by each &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; version:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! mysql versions&lt;br /&gt;
! would read it as&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 3.23.12&lt;br /&gt;
| CREATE DATABASE `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 3.23.12 and &amp;lt; 4.1.0&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;=4.1.0 (4.01.00)&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04` DEFAULT CHARACTER SET latin1;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conditional comments usually set some variables at the beginning of a block and reset them at the end.&lt;br /&gt;
&lt;br /&gt;
About the variable syntax of the SET command:&lt;br /&gt;
&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@@&#039;&#039;variable_name&#039;&#039;&amp;lt;/tt&amp;gt; can refer to a session value or a global value:&lt;br /&gt;
** When being refered, MySQL returns the session value if it exists and the global value otherwise.&lt;br /&gt;
** When being set (e.g. &amp;lt;tt&amp;gt;SET @@variable_name=value&amp;lt;/tt&amp;gt;), it always refers to the session value.&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@variable_name&amp;lt;/tt&amp;gt; refers to a user variable.&lt;br /&gt;
* When a variable doesn&#039;t have a modifier, it is a session variable.&lt;br /&gt;
&lt;br /&gt;
===== SQL statements =====&lt;br /&gt;
&lt;br /&gt;
The actual SQL statements, for example:&lt;br /&gt;
&lt;br /&gt;
 USE `test04`;&lt;br /&gt;
 DROP TABLE IF EXISTS `t1_latin`;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34536</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34536"/>
		<updated>2012-07-23T16:12:02Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Encoding and decoding */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:* &#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value (hex)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039;&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039;&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039;&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. In a database, character encoding only applies to text type columns (e.g. CHAR, VARCHAR, TEXT).&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many database stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, it should actually be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; therefore they do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every character type column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;db_name&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;db_name&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt;) configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBAs (database administrators), however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database &#039;&#039;db_name&#039;&#039;” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;Db characterset&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the &amp;lt;tt&amp;gt;character_set&amp;lt;/tt&amp;gt; variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema (database).&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the SHOW and DESCRIBE commands.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Tables, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query lists all tables in a particular schema that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_collation NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | test03       | t1_default | utf8                | utf8_unicode_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
=== Dumping a database ===&lt;br /&gt;
&lt;br /&gt;
To backup or transfer databases to another SQL server, MySQL includes a client program called &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt;. This program generates a text file with a series of SQL statements to recreate the original database, its tables and the corresponding data.&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; program can be run in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] db_name [tbl_name ...]&lt;br /&gt;
| dumps database, a table or a series of tables&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --databases db_name ...&lt;br /&gt;
| dumps a series of databases&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --all-databases&lt;br /&gt;
| dumps all databases&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This program is simple to use, but it is important to be familiar with a few of its options, as using a wrong setting could lead to corrupted data.&lt;br /&gt;
&lt;br /&gt;
==== Options ====&lt;br /&gt;
&lt;br /&gt;
===== --default-character-set =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--default-character-set&amp;lt;/tt&amp;gt; option sets &#039;&#039;charset_name&#039;&#039; as the default character set.&lt;br /&gt;
&lt;br /&gt;
This option specifies the file character encoding to be used or how the file is going to be encoded: as column values from the database are read, they are converted to the character set specified by this option before being saved in the dump file.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would generate a latin1 encoded dump file (see, Encoding and decoding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a character set is not specified, &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; will use utf8 by default (versions lower than 4.1.2 use latin1 by default).&lt;br /&gt;
&lt;br /&gt;
===== --set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option adds a SET NAMES &#039;&#039;default_character_set&#039;&#039; statement to the output. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
The SET NAMES statement specifies the character set used by the client to send SQL statements to the server, and the character set that the server should use for sending results back to the client (see, For data encoding).&lt;br /&gt;
&lt;br /&gt;
A SET NAMES &#039;&#039;character_set&#039;&#039; statement is equivalent to the following three statements:&lt;br /&gt;
&lt;br /&gt;
 SET character_set_client = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_results = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_connection = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would add the following conditional comments at the beginning of the dump file:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;&lt;br /&gt;
 /*!40101 SET NAMES &#039;&#039;latin1&#039;&#039; */;&lt;br /&gt;
&lt;br /&gt;
and the following at the end:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;SET NAMES latin1&amp;quot; command will instruct the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; program to use, send and receive data encoded in latin1.&lt;br /&gt;
&lt;br /&gt;
===== --skip-set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; option is used to disable the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --no-set-names (-N) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; is equivalent to &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt;, and so this option disables the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option: it doesn’t add a SET NAMES &#039;&#039;default_character_set&#039;&#039; to the output.&lt;br /&gt;
&lt;br /&gt;
===== --complete-insert (-c) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--complete-insert&amp;lt;/tt&amp;gt; option indicates to use complete INSERT statements that include column names.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;&#039;-c&#039;&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` &#039;&#039;&#039;(`id`, `string`)&#039;&#039;&#039; VALUES (1,&#039;text1&#039;),(2,&#039; text2&#039;);&lt;br /&gt;
&lt;br /&gt;
But the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement without the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --extended-insert (-e) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; indicates to use a multiple-row INSERT syntax that include several VALUES lists. This results in smaller dump files and faster inserts when the file is reloaded. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes all the records to be added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --skip-extended-insert =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-extended-insert&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-extended-insert &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create multiple INSERT statements, one for each record added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (1,&#039;text1&#039;);&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --result-file (-r) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--result-file&amp;lt;/tt&amp;gt; option directs output to a given file.&lt;br /&gt;
&lt;br /&gt;
As this option prevents newline characters from being converted to carriage return/newline sequences, it should be used when working in a Windows environment:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &#039;&#039;&#039;-r&#039;&#039;&#039; backup.sql&lt;br /&gt;
&lt;br /&gt;
instead of using &amp;quot;&amp;gt;&amp;quot; to redirect output to a file:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &amp;gt; backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --single-transaction =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option issues a BEGIN SQL statement before dumping data from the server, and it should be used with transactional tables (like InnoDB).&lt;br /&gt;
&lt;br /&gt;
As this option and the &amp;lt;tt&amp;gt;--lock-tables&amp;lt;/tt&amp;gt; option are mutually exclusive, the &amp;lt;tt&amp;gt;--skip-lock-tables&amp;lt;/tt&amp;gt; option should also be used prior to using the &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-lock-tables --single-transaction &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is shorthand for the following:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| --add-drop-table&lt;br /&gt;
| Add a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
|-&lt;br /&gt;
| --add-locks&lt;br /&gt;
| Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.&lt;br /&gt;
|-&lt;br /&gt;
| --create-options&lt;br /&gt;
| Include all MySQL-specific table options in CREATE TABLE statements.&lt;br /&gt;
|-&lt;br /&gt;
| --disable-keys&lt;br /&gt;
| For each table, surround the INSERT statements with statements to disable and enable keys.&lt;br /&gt;
|-&lt;br /&gt;
| --extended-insert&lt;br /&gt;
| Use multiple-row INSERT syntax that include several VALUES lists.&lt;br /&gt;
|-&lt;br /&gt;
| --lock-tables&lt;br /&gt;
| Lock all tables before dumping them.&lt;br /&gt;
|-&lt;br /&gt;
| --quick&lt;br /&gt;
| Retrieve rows for a table from the server a row at a time.&lt;br /&gt;
|-&lt;br /&gt;
| --set-charset&lt;br /&gt;
| Add SET NAMES default_character_set to the output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As all of these options are enabled by default, the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is also enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --skip-opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-opt&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-database =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-database&amp;lt;/tt&amp;gt; option adds a DROP DATABASE statement before each CREATE DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-table =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-table&amp;lt;/tt&amp;gt; option adds a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
==== Internal structure of a dump file ====&lt;br /&gt;
&lt;br /&gt;
A dump file usually consists of three different elements: comments, conditional comments and SQL statements.&lt;br /&gt;
&lt;br /&gt;
===== Comments =====&lt;br /&gt;
&lt;br /&gt;
Comments are completely ignored by the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program and only serve to describe what follows. Comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 -- &#039;&#039;comment&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 -- MySQL dump 10.13  Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
&lt;br /&gt;
===== Conditional comments =====&lt;br /&gt;
&lt;br /&gt;
Conditional comments are used to hide SET commands or SQL statements from older versions of &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; (used to restore a dump file). Conditional comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 /*!&#039;&#039;five digit version number&#039;&#039; SET|SQL &#039;&#039;statement&#039;&#039; */&lt;br /&gt;
&lt;br /&gt;
For example, the following line, which contains two conditional comments:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test04` /*!40100 DEFAULT CHARACTER SET latin1 */;&lt;br /&gt;
&lt;br /&gt;
would be interpreted differently by each &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; version:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! mysql versions&lt;br /&gt;
! would read it as&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 3.23.12&lt;br /&gt;
| CREATE DATABASE `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 3.23.12 and &amp;lt; 4.1.0&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;=4.1.0 (4.01.00)&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04` DEFAULT CHARACTER SET latin1;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conditional comments usually set some variables at the beginning of a block and reset them at the end.&lt;br /&gt;
&lt;br /&gt;
About the variable syntax of the SET command:&lt;br /&gt;
&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@@&#039;&#039;variable_name&#039;&#039;&amp;lt;/tt&amp;gt; can refer to a session value or a global value:&lt;br /&gt;
** When being refered, MySQL returns the session value if it exists and the global value otherwise.&lt;br /&gt;
** When being set (e.g. &amp;lt;tt&amp;gt;SET @@variable_name=value&amp;lt;/tt&amp;gt;), it always refers to the session value.&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@variable_name&amp;lt;/tt&amp;gt; refers to a user variable.&lt;br /&gt;
* When a variable doesn&#039;t have a modifier, it is a session variable.&lt;br /&gt;
&lt;br /&gt;
===== SQL statements =====&lt;br /&gt;
&lt;br /&gt;
The actual SQL statements, for example:&lt;br /&gt;
&lt;br /&gt;
 USE `test04`;&lt;br /&gt;
 DROP TABLE IF EXISTS `t1_latin`;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34530</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34530"/>
		<updated>2012-07-22T23:12:48Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Gathering information (2) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:* &#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value (hex)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039;&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039;&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039;&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many database stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, it should actually be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; therefore they do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every character type column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;db_name&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;db_name&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt;) configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBAs (database administrators), however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database &#039;&#039;db_name&#039;&#039;” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;Db characterset&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the &amp;lt;tt&amp;gt;character_set&amp;lt;/tt&amp;gt; variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema (database).&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the SHOW and DESCRIBE commands.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Tables, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query lists all tables in a particular schema that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_collation NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | test03       | t1_default | utf8                | utf8_unicode_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
=== Dumping a database ===&lt;br /&gt;
&lt;br /&gt;
To backup or transfer databases to another SQL server, MySQL includes a client program called &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt;. This program generates a text file with a series of SQL statements to recreate the original database, its tables and the corresponding data.&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; program can be run in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] db_name [tbl_name ...]&lt;br /&gt;
| dumps database, a table or a series of tables&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --databases db_name ...&lt;br /&gt;
| dumps a series of databases&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --all-databases&lt;br /&gt;
| dumps all databases&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This program is simple to use, but it is important to be familiar with a few of its options, as using a wrong setting could lead to corrupted data.&lt;br /&gt;
&lt;br /&gt;
==== Options ====&lt;br /&gt;
&lt;br /&gt;
===== --default-character-set =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--default-character-set&amp;lt;/tt&amp;gt; option sets &#039;&#039;charset_name&#039;&#039; as the default character set.&lt;br /&gt;
&lt;br /&gt;
This option specifies the file character encoding to be used or how the file is going to be encoded: as column values from the database are read, they are converted to the character set specified by this option before being saved in the dump file.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would generate a latin1 encoded dump file (see, Encoding and decoding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a character set is not specified, &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; will use utf8 by default (versions lower than 4.1.2 use latin1 by default).&lt;br /&gt;
&lt;br /&gt;
===== --set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option adds a SET NAMES &#039;&#039;default_character_set&#039;&#039; statement to the output. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
The SET NAMES statement specifies the character set used by the client to send SQL statements to the server, and the character set that the server should use for sending results back to the client (see, For data encoding).&lt;br /&gt;
&lt;br /&gt;
A SET NAMES &#039;&#039;character_set&#039;&#039; statement is equivalent to the following three statements:&lt;br /&gt;
&lt;br /&gt;
 SET character_set_client = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_results = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_connection = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would add the following conditional comments at the beginning of the dump file:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;&lt;br /&gt;
 /*!40101 SET NAMES &#039;&#039;latin1&#039;&#039; */;&lt;br /&gt;
&lt;br /&gt;
and the following at the end:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;SET NAMES latin1&amp;quot; command will instruct the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; program to use, send and receive data encoded in latin1.&lt;br /&gt;
&lt;br /&gt;
===== --skip-set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; option is used to disable the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --no-set-names (-N) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; is equivalent to &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt;, and so this option disables the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option: it doesn’t add a SET NAMES &#039;&#039;default_character_set&#039;&#039; to the output.&lt;br /&gt;
&lt;br /&gt;
===== --complete-insert (-c) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--complete-insert&amp;lt;/tt&amp;gt; option indicates to use complete INSERT statements that include column names.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;&#039;-c&#039;&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` &#039;&#039;&#039;(`id`, `string`)&#039;&#039;&#039; VALUES (1,&#039;text1&#039;),(2,&#039; text2&#039;);&lt;br /&gt;
&lt;br /&gt;
But the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement without the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --extended-insert (-e) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; indicates to use a multiple-row INSERT syntax that include several VALUES lists. This results in smaller dump files and faster inserts when the file is reloaded. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes all the records to be added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --skip-extended-insert =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-extended-insert&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-extended-insert &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create multiple INSERT statements, one for each record added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (1,&#039;text1&#039;);&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --result-file (-r) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--result-file&amp;lt;/tt&amp;gt; option directs output to a given file.&lt;br /&gt;
&lt;br /&gt;
As this option prevents newline characters from being converted to carriage return/newline sequences, it should be used when working in a Windows environment:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &#039;&#039;&#039;-r&#039;&#039;&#039; backup.sql&lt;br /&gt;
&lt;br /&gt;
instead of using &amp;quot;&amp;gt;&amp;quot; to redirect output to a file:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &amp;gt; backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --single-transaction =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option issues a BEGIN SQL statement before dumping data from the server, and it should be used with transactional tables (like InnoDB).&lt;br /&gt;
&lt;br /&gt;
As this option and the &amp;lt;tt&amp;gt;--lock-tables&amp;lt;/tt&amp;gt; option are mutually exclusive, the &amp;lt;tt&amp;gt;--skip-lock-tables&amp;lt;/tt&amp;gt; option should also be used prior to using the &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-lock-tables --single-transaction &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is shorthand for the following:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| --add-drop-table&lt;br /&gt;
| Add a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
|-&lt;br /&gt;
| --add-locks&lt;br /&gt;
| Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.&lt;br /&gt;
|-&lt;br /&gt;
| --create-options&lt;br /&gt;
| Include all MySQL-specific table options in CREATE TABLE statements.&lt;br /&gt;
|-&lt;br /&gt;
| --disable-keys&lt;br /&gt;
| For each table, surround the INSERT statements with statements to disable and enable keys.&lt;br /&gt;
|-&lt;br /&gt;
| --extended-insert&lt;br /&gt;
| Use multiple-row INSERT syntax that include several VALUES lists.&lt;br /&gt;
|-&lt;br /&gt;
| --lock-tables&lt;br /&gt;
| Lock all tables before dumping them.&lt;br /&gt;
|-&lt;br /&gt;
| --quick&lt;br /&gt;
| Retrieve rows for a table from the server a row at a time.&lt;br /&gt;
|-&lt;br /&gt;
| --set-charset&lt;br /&gt;
| Add SET NAMES default_character_set to the output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As all of these options are enabled by default, the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is also enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --skip-opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-opt&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-database =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-database&amp;lt;/tt&amp;gt; option adds a DROP DATABASE statement before each CREATE DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-table =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-table&amp;lt;/tt&amp;gt; option adds a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
==== Internal structure of a dump file ====&lt;br /&gt;
&lt;br /&gt;
A dump file usually consists of three different elements: comments, conditional comments and SQL statements.&lt;br /&gt;
&lt;br /&gt;
===== Comments =====&lt;br /&gt;
&lt;br /&gt;
Comments are completely ignored by the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program and only serve to describe what follows. Comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 -- &#039;&#039;comment&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 -- MySQL dump 10.13  Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
&lt;br /&gt;
===== Conditional comments =====&lt;br /&gt;
&lt;br /&gt;
Conditional comments are used to hide SET commands or SQL statements from older versions of &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; (used to restore a dump file). Conditional comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 /*!&#039;&#039;five digit version number&#039;&#039; SET|SQL &#039;&#039;statement&#039;&#039; */&lt;br /&gt;
&lt;br /&gt;
For example, the following line, which contains two conditional comments:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test04` /*!40100 DEFAULT CHARACTER SET latin1 */;&lt;br /&gt;
&lt;br /&gt;
would be interpreted differently by each &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; version:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! mysql versions&lt;br /&gt;
! would read it as&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 3.23.12&lt;br /&gt;
| CREATE DATABASE `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 3.23.12 and &amp;lt; 4.1.0&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;=4.1.0 (4.01.00)&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04` DEFAULT CHARACTER SET latin1;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conditional comments usually set some variables at the beginning of a block and reset them at the end.&lt;br /&gt;
&lt;br /&gt;
About the variable syntax of the SET command:&lt;br /&gt;
&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@@&#039;&#039;variable_name&#039;&#039;&amp;lt;/tt&amp;gt; can refer to a session value or a global value:&lt;br /&gt;
** When being refered, MySQL returns the session value if it exists and the global value otherwise.&lt;br /&gt;
** When being set (e.g. &amp;lt;tt&amp;gt;SET @@variable_name=value&amp;lt;/tt&amp;gt;), it always refers to the session value.&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@variable_name&amp;lt;/tt&amp;gt; refers to a user variable.&lt;br /&gt;
* When a variable doesn&#039;t have a modifier, it is a session variable.&lt;br /&gt;
&lt;br /&gt;
===== SQL statements =====&lt;br /&gt;
&lt;br /&gt;
The actual SQL statements, for example:&lt;br /&gt;
&lt;br /&gt;
 USE `test04`;&lt;br /&gt;
 DROP TABLE IF EXISTS `t1_latin`;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34529</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34529"/>
		<updated>2012-07-22T23:11:51Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:* &#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value (hex)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039;&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039;&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039;&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many database stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, it should actually be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; therefore they do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every character type column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;db_name&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;db_name&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt;) configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBAs (database administrators), however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. These commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;Db characterset&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the &amp;lt;tt&amp;gt;character_set&amp;lt;/tt&amp;gt; variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a database hasn’t been set active, the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema (database).&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the SHOW and DESCRIBE commands.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Tables, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query lists all tables in a particular schema that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_collation NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
 | test03       | t1_default | utf8                | utf8_unicode_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-----------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
=== Dumping a database ===&lt;br /&gt;
&lt;br /&gt;
To backup or transfer databases to another SQL server, MySQL includes a client program called &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt;. This program generates a text file with a series of SQL statements to recreate the original database, its tables and the corresponding data.&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; program can be run in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] db_name [tbl_name ...]&lt;br /&gt;
| dumps database, a table or a series of tables&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --databases db_name ...&lt;br /&gt;
| dumps a series of databases&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --all-databases&lt;br /&gt;
| dumps all databases&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This program is simple to use, but it is important to be familiar with a few of its options, as using a wrong setting could lead to corrupted data.&lt;br /&gt;
&lt;br /&gt;
==== Options ====&lt;br /&gt;
&lt;br /&gt;
===== --default-character-set =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--default-character-set&amp;lt;/tt&amp;gt; option sets &#039;&#039;charset_name&#039;&#039; as the default character set.&lt;br /&gt;
&lt;br /&gt;
This option specifies the file character encoding to be used or how the file is going to be encoded: as column values from the database are read, they are converted to the character set specified by this option before being saved in the dump file.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would generate a latin1 encoded dump file (see, Encoding and decoding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a character set is not specified, &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; will use utf8 by default (versions lower than 4.1.2 use latin1 by default).&lt;br /&gt;
&lt;br /&gt;
===== --set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option adds a SET NAMES &#039;&#039;default_character_set&#039;&#039; statement to the output. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
The SET NAMES statement specifies the character set used by the client to send SQL statements to the server, and the character set that the server should use for sending results back to the client (see, For data encoding).&lt;br /&gt;
&lt;br /&gt;
A SET NAMES &#039;&#039;character_set&#039;&#039; statement is equivalent to the following three statements:&lt;br /&gt;
&lt;br /&gt;
 SET character_set_client = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_results = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_connection = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would add the following conditional comments at the beginning of the dump file:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;&lt;br /&gt;
 /*!40101 SET NAMES &#039;&#039;latin1&#039;&#039; */;&lt;br /&gt;
&lt;br /&gt;
and the following at the end:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;SET NAMES latin1&amp;quot; command will instruct the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; program to use, send and receive data encoded in latin1.&lt;br /&gt;
&lt;br /&gt;
===== --skip-set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; option is used to disable the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --no-set-names (-N) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; is equivalent to &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt;, and so this option disables the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option: it doesn’t add a SET NAMES &#039;&#039;default_character_set&#039;&#039; to the output.&lt;br /&gt;
&lt;br /&gt;
===== --complete-insert (-c) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--complete-insert&amp;lt;/tt&amp;gt; option indicates to use complete INSERT statements that include column names.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;&#039;-c&#039;&#039;&#039; &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` &#039;&#039;&#039;(`id`, `string`)&#039;&#039;&#039; VALUES (1,&#039;text1&#039;),(2,&#039; text2&#039;);&lt;br /&gt;
&lt;br /&gt;
But the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement without the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --extended-insert (-e) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; indicates to use a multiple-row INSERT syntax that include several VALUES lists. This results in smaller dump files and faster inserts when the file is reloaded. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes all the records to be added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --skip-extended-insert =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-extended-insert&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-extended-insert &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
would create multiple INSERT statements, one for each record added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (1,&#039;text1&#039;);&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --result-file (-r) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--result-file&amp;lt;/tt&amp;gt; option directs output to a given file.&lt;br /&gt;
&lt;br /&gt;
As this option prevents newline characters from being converted to carriage return/newline sequences, it should be used when working in a Windows environment:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &#039;&#039;&#039;-r&#039;&#039;&#039; backup.sql&lt;br /&gt;
&lt;br /&gt;
instead of using &amp;quot;&amp;gt;&amp;quot; to redirect output to a file:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;db_name&#039;&#039; &amp;gt; backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --single-transaction =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option issues a BEGIN SQL statement before dumping data from the server, and it should be used with transactional tables (like InnoDB).&lt;br /&gt;
&lt;br /&gt;
As this option and the &amp;lt;tt&amp;gt;--lock-tables&amp;lt;/tt&amp;gt; option are mutually exclusive, the &amp;lt;tt&amp;gt;--skip-lock-tables&amp;lt;/tt&amp;gt; option should also be used prior to using the &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-lock-tables --single-transaction &#039;&#039;db_name&#039;&#039; -r backup.sql&lt;br /&gt;
&lt;br /&gt;
===== --opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is shorthand for the following:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| --add-drop-table&lt;br /&gt;
| Add a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
|-&lt;br /&gt;
| --add-locks&lt;br /&gt;
| Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.&lt;br /&gt;
|-&lt;br /&gt;
| --create-options&lt;br /&gt;
| Include all MySQL-specific table options in CREATE TABLE statements.&lt;br /&gt;
|-&lt;br /&gt;
| --disable-keys&lt;br /&gt;
| For each table, surround the INSERT statements with statements to disable and enable keys.&lt;br /&gt;
|-&lt;br /&gt;
| --extended-insert&lt;br /&gt;
| Use multiple-row INSERT syntax that include several VALUES lists.&lt;br /&gt;
|-&lt;br /&gt;
| --lock-tables&lt;br /&gt;
| Lock all tables before dumping them.&lt;br /&gt;
|-&lt;br /&gt;
| --quick&lt;br /&gt;
| Retrieve rows for a table from the server a row at a time.&lt;br /&gt;
|-&lt;br /&gt;
| --set-charset&lt;br /&gt;
| Add SET NAMES default_character_set to the output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As all of these options are enabled by default, the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is also enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --skip-opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-opt&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-database =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-database&amp;lt;/tt&amp;gt; option adds a DROP DATABASE statement before each CREATE DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-table =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-table&amp;lt;/tt&amp;gt; option adds a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
==== Internal structure of a dump file ====&lt;br /&gt;
&lt;br /&gt;
A dump file usually consists of three different elements: comments, conditional comments and SQL statements.&lt;br /&gt;
&lt;br /&gt;
===== Comments =====&lt;br /&gt;
&lt;br /&gt;
Comments are completely ignored by the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program and only serve to describe what follows. Comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 -- &#039;&#039;comment&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 -- MySQL dump 10.13  Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
&lt;br /&gt;
===== Conditional comments =====&lt;br /&gt;
&lt;br /&gt;
Conditional comments are used to hide SET commands or SQL statements from older versions of &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; (used to restore a dump file). Conditional comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 /*!&#039;&#039;five digit version number&#039;&#039; SET|SQL &#039;&#039;statement&#039;&#039; */&lt;br /&gt;
&lt;br /&gt;
For example, the following line, which contains two conditional comments:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test04` /*!40100 DEFAULT CHARACTER SET latin1 */;&lt;br /&gt;
&lt;br /&gt;
would be interpreted differently by each &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; version:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! mysql versions&lt;br /&gt;
! would read it as&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 3.23.12&lt;br /&gt;
| CREATE DATABASE `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 3.23.12 and &amp;lt; 4.1.0&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;=4.1.0 (4.01.00)&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04` DEFAULT CHARACTER SET latin1;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conditional comments usually set some variables at the beginning of a block and reset them at the end.&lt;br /&gt;
&lt;br /&gt;
About the variable syntax of the SET command:&lt;br /&gt;
&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@@&#039;&#039;variable_name&#039;&#039;&amp;lt;/tt&amp;gt; can refer to a session value or a global value:&lt;br /&gt;
** When being refered, MySQL returns the session value if it exists and the global value otherwise.&lt;br /&gt;
** When being set (e.g. &amp;lt;tt&amp;gt;SET @@variable_name=value&amp;lt;/tt&amp;gt;), it always refers to the session value.&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@variable_name&amp;lt;/tt&amp;gt; refers to a user variable.&lt;br /&gt;
* When a variable doesn&#039;t have a modifier, it is a session variable.&lt;br /&gt;
&lt;br /&gt;
===== SQL statements =====&lt;br /&gt;
&lt;br /&gt;
The actual SQL statements, for example:&lt;br /&gt;
&lt;br /&gt;
 USE `test04`;&lt;br /&gt;
 DROP TABLE IF EXISTS `t1_latin`;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34526</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34526"/>
		<updated>2012-07-22T07:17:20Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Conditional comments */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Also include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
=== Dumping a database ===&lt;br /&gt;
&lt;br /&gt;
To backup or transfer databases to another SQL server, MySQL includes a client program called &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt;. This program generates a text file with a series of SQL statements to recreate the original database, its tables and the corresponding data.&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; program can be run in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] db_name [tbl_name ...]&lt;br /&gt;
| dumps database, a table or a series of tables&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --databases db_name ...&lt;br /&gt;
| dumps a series of databases&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --all-databases&lt;br /&gt;
| dumps all databases&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This program is simple to use, but it is important to be familiar with a few of its options, as using a wrong setting could lead to corrupted data.&lt;br /&gt;
&lt;br /&gt;
==== Options ====&lt;br /&gt;
&lt;br /&gt;
===== --default-character-set =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--default-character-set&amp;lt;/tt&amp;gt; option sets &#039;&#039;charset_name&#039;&#039; as the default character set. It specifies the file character encoding to be used or how the file is going to be encoded, that is, column values are converted to the character set specified by this option.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would generate a latin1 encoded dump file (see, Encoding and decoding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a character set is not specified, mysqldump will use utf8 by default (versions lower than 4.1.2 use latin1 by default).&lt;br /&gt;
&lt;br /&gt;
===== --set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option adds a SET NAMES &#039;&#039;default_character_set&#039;&#039; statement to the output. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
The SET NAMES statement specifies the character set used by the client to send SQL statements to the server, and the character set that the server should use for sending results back to the client (see, For data encoding).&lt;br /&gt;
&lt;br /&gt;
A SET NAMES &#039;&#039;character_set&#039;&#039; statement is equivalent to the following three statements:&lt;br /&gt;
&lt;br /&gt;
 SET character_set_client = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_results = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_connection = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would add the following conditional comments at the beginning of the dump file:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;&lt;br /&gt;
 /*!40101 SET NAMES &#039;&#039;latin1&#039;&#039; */;&lt;br /&gt;
&lt;br /&gt;
and the following at the end:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;&lt;br /&gt;
&lt;br /&gt;
This would tell the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; program that it should use, send and receive data encoded in latin1.&lt;br /&gt;
&lt;br /&gt;
===== --skip-set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; option is used to disable the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --no-set-names (-N) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; is equivalent to &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt;, and so this option disables the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option: it doesn’t add a SET NAMES &#039;&#039;default_character_set&#039;&#039; to the output.&lt;br /&gt;
&lt;br /&gt;
===== --complete-insert (-c) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--complete-insert&amp;lt;/tt&amp;gt; option indicates to use complete INSERT statements that include column names.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;&#039;-c&#039;&#039;&#039; test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` &#039;&#039;&#039;(`id`, `string`)&#039;&#039;&#039; VALUES (1,&#039;text1&#039;),(2,&#039; text2&#039;);&lt;br /&gt;
&lt;br /&gt;
But the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement without the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --extended-insert (-e) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; indicates to use a multiple-row INSERT syntax that include several VALUES lists. This results in smaller dump files and faster inserts when the file is reloaded. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes all the records to be added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --skip-extended-insert =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-extended-insert&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-extended-insert test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would create multiple INSERT statements, one for each record added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (1,&#039;text1&#039;);&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --result-file (-r) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--result-file&amp;lt;/tt&amp;gt; option directs output to a given file.&lt;br /&gt;
&lt;br /&gt;
As this option prevents newline characters from being converted to carriage return/newline sequences, in a Windows environment it should be used:&lt;br /&gt;
&lt;br /&gt;
 mysqldump test04 &#039;&#039;&#039;-r&#039;&#039;&#039; test04.sql&lt;br /&gt;
&lt;br /&gt;
instead of using &amp;quot;&amp;gt;&amp;quot; to redirect output to file:&lt;br /&gt;
&lt;br /&gt;
 mysqldump test04 &amp;gt; test04.sql&lt;br /&gt;
&lt;br /&gt;
===== --single-transaction =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option issues a BEGIN SQL statement before dumping data from the server, and it should be used with transactional tables (like InnoDB).&lt;br /&gt;
&lt;br /&gt;
As this option and the &amp;lt;tt&amp;gt;--lock-tables&amp;lt;/tt&amp;gt; option are mutually exclusive, the &amp;lt;tt&amp;gt;--skip-lock-tables&amp;lt;/tt&amp;gt; option should also be used prior to using the &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-lock-tables --single-transaction test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
===== --opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is shorthand for the following:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| --add-drop-table&lt;br /&gt;
| Add a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
|-&lt;br /&gt;
| --add-locks&lt;br /&gt;
| Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.&lt;br /&gt;
|-&lt;br /&gt;
| --create-options&lt;br /&gt;
| Include all MySQL-specific table options in CREATE TABLE statements.&lt;br /&gt;
|-&lt;br /&gt;
| --disable-keys&lt;br /&gt;
| For each table, surround the INSERT statements with statements to disable and enable keys.&lt;br /&gt;
|-&lt;br /&gt;
| --extended-insert&lt;br /&gt;
| Use multiple-row INSERT syntax that include several VALUES lists.&lt;br /&gt;
|-&lt;br /&gt;
| --lock-tables&lt;br /&gt;
| Lock all tables before dumping them.&lt;br /&gt;
|-&lt;br /&gt;
| --quick&lt;br /&gt;
| Retrieve rows for a table from the server a row at a time.&lt;br /&gt;
|-&lt;br /&gt;
| --set-charset&lt;br /&gt;
| Add SET NAMES default_character_set to the output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As all of these options are enabled by default, the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is also enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --skip-opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-opt&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-database =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-database&amp;lt;/tt&amp;gt; option adds a DROP DATABASE statement before each CREATE DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-table =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-table&amp;lt;/tt&amp;gt; option adds a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
==== Internal structure of a dump file ====&lt;br /&gt;
&lt;br /&gt;
A dump file usually consists of three different elements: comments, conditional comments and SQL statements.&lt;br /&gt;
&lt;br /&gt;
===== Comments =====&lt;br /&gt;
&lt;br /&gt;
Comments are completely ignored by the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program and only serve to describe what follows. Comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 -- &#039;&#039;comment&#039;&#039; (e.g. -- MySQL dump 10.13  Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
&lt;br /&gt;
===== Conditional comments =====&lt;br /&gt;
&lt;br /&gt;
Conditional comments are used to hide SET commands or SQL statements from older versions of &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; (used to restore a dump file). Conditional comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 /*!&#039;&#039;five digit version number&#039;&#039; (e.g. /*!40101 or /*!40103)&lt;br /&gt;
 SET &#039;&#039;statement&#039;&#039; (e.g. SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT or SET NAMES utf8)&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
For example, the following line, which contains two conditional comments:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test04` /*!40100 DEFAULT CHARACTER SET latin1 */;&lt;br /&gt;
&lt;br /&gt;
would be interpreted differently by each &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; version:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! mysql versions&lt;br /&gt;
! would read it as&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 3.23.12&lt;br /&gt;
| CREATE DATABASE `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 3.23.12 and &amp;lt; 4.1.0&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;=4.1.0 (4.01.00)&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04` DEFAULT CHARACTER SET latin1;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conditional comments usually set some variables at the beginning of a block and reset them at the end.&lt;br /&gt;
&lt;br /&gt;
About the variable syntax of the SET command:&lt;br /&gt;
&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@@&#039;&#039;variable_name&#039;&#039;&amp;lt;/tt&amp;gt; can refer to a session value or a global value:&lt;br /&gt;
** When being refered, MySQL returns the session value if it exists and the global value otherwise.&lt;br /&gt;
** When being set (e.g. &amp;lt;tt&amp;gt;SET @@variable_name=value&amp;lt;/tt&amp;gt;), it always refers to the session value.&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@variable_name&amp;lt;/tt&amp;gt; refers to a user variable.&lt;br /&gt;
* When a variable doesn&#039;t have a modifier, it is a session variable.&lt;br /&gt;
&lt;br /&gt;
===== SQL statements =====&lt;br /&gt;
&lt;br /&gt;
The actual SQL statements, for example:&lt;br /&gt;
&lt;br /&gt;
 USE `test04`;&lt;br /&gt;
 DROP TABLE IF EXISTS `t1_latin`;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34525</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34525"/>
		<updated>2012-07-22T07:10:21Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* --set-charset */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Also include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
=== Dumping a database ===&lt;br /&gt;
&lt;br /&gt;
To backup or transfer databases to another SQL server, MySQL includes a client program called &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt;. This program generates a text file with a series of SQL statements to recreate the original database, its tables and the corresponding data.&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; program can be run in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] db_name [tbl_name ...]&lt;br /&gt;
| dumps database, a table or a series of tables&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --databases db_name ...&lt;br /&gt;
| dumps a series of databases&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --all-databases&lt;br /&gt;
| dumps all databases&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This program is simple to use, but it is important to be familiar with a few of its options, as using a wrong setting could lead to corrupted data.&lt;br /&gt;
&lt;br /&gt;
==== Options ====&lt;br /&gt;
&lt;br /&gt;
===== --default-character-set =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--default-character-set&amp;lt;/tt&amp;gt; option sets &#039;&#039;charset_name&#039;&#039; as the default character set. It specifies the file character encoding to be used or how the file is going to be encoded, that is, column values are converted to the character set specified by this option.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would generate a latin1 encoded dump file (see, Encoding and decoding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a character set is not specified, mysqldump will use utf8 by default (versions lower than 4.1.2 use latin1 by default).&lt;br /&gt;
&lt;br /&gt;
===== --set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option adds a SET NAMES &#039;&#039;default_character_set&#039;&#039; statement to the output. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
The SET NAMES statement specifies the character set used by the client to send SQL statements to the server, and the character set that the server should use for sending results back to the client (see, For data encoding).&lt;br /&gt;
&lt;br /&gt;
A SET NAMES &#039;&#039;character_set&#039;&#039; statement is equivalent to the following three statements:&lt;br /&gt;
&lt;br /&gt;
 SET character_set_client = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_results = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_connection = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would add the following conditional comments at the beginning of the dump file:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;&lt;br /&gt;
 /*!40101 SET NAMES &#039;&#039;latin1&#039;&#039; */;&lt;br /&gt;
&lt;br /&gt;
and the following at the end:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;&lt;br /&gt;
&lt;br /&gt;
This would tell the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; program that it should use, send and receive data encoded in latin1.&lt;br /&gt;
&lt;br /&gt;
===== --skip-set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; option is used to disable the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --no-set-names (-N) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; is equivalent to &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt;, and so this option disables the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option: it doesn’t add a SET NAMES &#039;&#039;default_character_set&#039;&#039; to the output.&lt;br /&gt;
&lt;br /&gt;
===== --complete-insert (-c) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--complete-insert&amp;lt;/tt&amp;gt; option indicates to use complete INSERT statements that include column names.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;&#039;-c&#039;&#039;&#039; test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` &#039;&#039;&#039;(`id`, `string`)&#039;&#039;&#039; VALUES (1,&#039;text1&#039;),(2,&#039; text2&#039;);&lt;br /&gt;
&lt;br /&gt;
But the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement without the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --extended-insert (-e) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; indicates to use a multiple-row INSERT syntax that include several VALUES lists. This results in smaller dump files and faster inserts when the file is reloaded. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes all the records to be added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --skip-extended-insert =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-extended-insert&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-extended-insert test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would create multiple INSERT statements, one for each record added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (1,&#039;text1&#039;);&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --result-file (-r) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--result-file&amp;lt;/tt&amp;gt; option directs output to a given file.&lt;br /&gt;
&lt;br /&gt;
As this option prevents newline characters from being converted to carriage return/newline sequences, in a Windows environment it should be used:&lt;br /&gt;
&lt;br /&gt;
 mysqldump test04 &#039;&#039;&#039;-r&#039;&#039;&#039; test04.sql&lt;br /&gt;
&lt;br /&gt;
instead of using &amp;quot;&amp;gt;&amp;quot; to redirect output to file:&lt;br /&gt;
&lt;br /&gt;
 mysqldump test04 &amp;gt; test04.sql&lt;br /&gt;
&lt;br /&gt;
===== --single-transaction =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option issues a BEGIN SQL statement before dumping data from the server, and it should be used with transactional tables (like InnoDB).&lt;br /&gt;
&lt;br /&gt;
As this option and the &amp;lt;tt&amp;gt;--lock-tables&amp;lt;/tt&amp;gt; option are mutually exclusive, the &amp;lt;tt&amp;gt;--skip-lock-tables&amp;lt;/tt&amp;gt; option should also be used prior to using the &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-lock-tables --single-transaction test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
===== --opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is shorthand for the following:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| --add-drop-table&lt;br /&gt;
| Add a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
|-&lt;br /&gt;
| --add-locks&lt;br /&gt;
| Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.&lt;br /&gt;
|-&lt;br /&gt;
| --create-options&lt;br /&gt;
| Include all MySQL-specific table options in CREATE TABLE statements.&lt;br /&gt;
|-&lt;br /&gt;
| --disable-keys&lt;br /&gt;
| For each table, surround the INSERT statements with statements to disable and enable keys.&lt;br /&gt;
|-&lt;br /&gt;
| --extended-insert&lt;br /&gt;
| Use multiple-row INSERT syntax that include several VALUES lists.&lt;br /&gt;
|-&lt;br /&gt;
| --lock-tables&lt;br /&gt;
| Lock all tables before dumping them.&lt;br /&gt;
|-&lt;br /&gt;
| --quick&lt;br /&gt;
| Retrieve rows for a table from the server a row at a time.&lt;br /&gt;
|-&lt;br /&gt;
| --set-charset&lt;br /&gt;
| Add SET NAMES default_character_set to the output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As all of these options are enabled by default, the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is also enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --skip-opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-opt&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-database =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-database&amp;lt;/tt&amp;gt; option adds a DROP DATABASE statement before each CREATE DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-table =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-table&amp;lt;/tt&amp;gt; option adds a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
==== Internal structure of a dump file ====&lt;br /&gt;
&lt;br /&gt;
A dump file usually consists of three different elements: comments, conditional comments and SQL statements.&lt;br /&gt;
&lt;br /&gt;
===== Comments =====&lt;br /&gt;
&lt;br /&gt;
Comments are completely ignored by the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program and only serve to describe what follows. Comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 -- &#039;&#039;comment&#039;&#039; (e.g. -- MySQL dump 10.13  Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
&lt;br /&gt;
===== Conditional comments =====&lt;br /&gt;
&lt;br /&gt;
Conditional comments are used to hide SET commands or SQL statements from older versions of &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; (used to restore a dump file). Conditional comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 /*!&#039;&#039;five digit version number&#039;&#039; (e.g. /*!40101 or /*!40103)&lt;br /&gt;
 SET &#039;&#039;statement&#039;&#039; (e.g. SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT or SET NAMES utf8)&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
For example, the following conditional comment:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test04` /*!40100 DEFAULT CHARACTER SET latin1 */;&lt;br /&gt;
&lt;br /&gt;
would be interpreted differently by each &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; version:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! mysql versions&lt;br /&gt;
! would read it as&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 3.23.12&lt;br /&gt;
| CREATE DATABASE `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 3.23.12 and &amp;lt; 4.1.0&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;=4.1.0 (4.01.00)&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04` DEFAULT CHARACTER SET latin1;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conditional comments usually set some variables at the beginning of a block and reset them at the end.&lt;br /&gt;
&lt;br /&gt;
About the variable syntax of the SET command:&lt;br /&gt;
&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@@&#039;&#039;variable_name&#039;&#039;&amp;lt;/tt&amp;gt; can refer to a session value or a global value:&lt;br /&gt;
| * When being refered, MySQL returns the session value if it exists and the global value otherwise.&lt;br /&gt;
| * When being set (e.g. &amp;lt;tt&amp;gt;SET @@variable_name=value&amp;lt;/tt&amp;gt;), it always refers to the session value.&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@variable_name&amp;lt;/tt&amp;gt; refers to a user variable.&lt;br /&gt;
* When a variable doesn&#039;t have a modifier, it is a session variable.&lt;br /&gt;
&lt;br /&gt;
===== SQL statements =====&lt;br /&gt;
&lt;br /&gt;
The actual SQL statements, for example:&lt;br /&gt;
&lt;br /&gt;
 USE `test04`;&lt;br /&gt;
 DROP TABLE IF EXISTS `t1_latin`;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34524</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34524"/>
		<updated>2012-07-22T07:06:18Z</updated>

		<summary type="html">&lt;p&gt;Gmads: Dumping a database&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Also include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
=== Dumping a database ===&lt;br /&gt;
&lt;br /&gt;
To backup or transfer databases to another SQL server, MySQL includes a client program called &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt;. This program generates a text file with a series of SQL statements to recreate the original database, its tables and the corresponding data.&lt;br /&gt;
&lt;br /&gt;
Basically, the &amp;lt;tt&amp;gt;mysqldump&amp;lt;/tt&amp;gt; program can be run in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] db_name [tbl_name ...]&lt;br /&gt;
| dumps database, a table or a series of tables&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --databases db_name ...&lt;br /&gt;
| dumps a series of databases&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump [options] --all-databases&lt;br /&gt;
| dumps all databases&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This program is simple to use, but it is important to be familiar with a few of its options, as using a wrong setting could lead to corrupted data.&lt;br /&gt;
&lt;br /&gt;
==== Options ====&lt;br /&gt;
&lt;br /&gt;
===== --default-character-set =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--default-character-set&amp;lt;/tt&amp;gt; option sets &#039;&#039;charset_name&#039;&#039; as the default character set. It specifies the file character encoding to be used or how the file is going to be encoded, that is, column values are converted to the character set specified by this option.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would generate a latin1 encoded dump file (see, Encoding and decoding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. If a character set is not specified, mysqldump will use utf8 by default (versions lower than 4.1.2 use latin1 by default).&lt;br /&gt;
&lt;br /&gt;
===== --set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option adds a SET NAMES default_character_set statement to the output. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
The SET NAMES statement specifies the character set used by the client to send SQL statements to the server, and the character set that the server should use for sending results back to the client (see, For data encoding).&lt;br /&gt;
&lt;br /&gt;
The SET NAMES &#039;&#039;character_set&#039;&#039; statement is equivalent to the following three statements:&lt;br /&gt;
&lt;br /&gt;
 SET character_set_client = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_results = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
 SET character_set_connection = &#039;&#039;character_set&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --default-character-set=&#039;&#039;latin1&#039;&#039; test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would add the following conditional comments at the beginning of the dump file:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;&lt;br /&gt;
 /*!40101 SET NAMES &#039;&#039;latin1&#039;&#039; */;&lt;br /&gt;
&lt;br /&gt;
and the following at the end:&lt;br /&gt;
&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;&lt;br /&gt;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;&lt;br /&gt;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;&lt;br /&gt;
&lt;br /&gt;
This would tell the mysql program that it should use, send and receive data encoded in latin1.&lt;br /&gt;
&lt;br /&gt;
===== --skip-set-charset =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt; option is used to disable the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --no-set-names (-N) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--no-set-names&amp;lt;/tt&amp;gt; is equivalent to &amp;lt;tt&amp;gt;--skip-set-charset&amp;lt;/tt&amp;gt;, and so this option disables the &amp;lt;tt&amp;gt;--set-charset&amp;lt;/tt&amp;gt; option: it doesn’t add a SET NAMES &#039;&#039;default_character_set&#039;&#039; to the output.&lt;br /&gt;
&lt;br /&gt;
===== --complete-insert (-c) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--complete-insert&amp;lt;/tt&amp;gt; option indicates to use complete INSERT statements that include column names.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump &#039;&#039;&#039;-c&#039;&#039;&#039; test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` &#039;&#039;&#039;(`id`, `string`)&#039;&#039;&#039; VALUES (1,&#039;text1&#039;),(2,&#039; text2&#039;);&lt;br /&gt;
&lt;br /&gt;
But the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement without the names of the columns:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --extended-insert (-e) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; indicates to use a multiple-row INSERT syntax that include several VALUES lists. This results in smaller dump files and faster inserts when the file is reloaded. This option is enabled by default.&lt;br /&gt;
&lt;br /&gt;
As this option is enabled by default, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would create an INSERT statement that includes all the records to be added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` VALUES (1,&#039;text1&#039;),(2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --skip-extended-insert =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-extended-insert&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--extended-insert&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
For example, the following command:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-extended-insert test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
would create multiple INSERT statements, one for each record added:&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (1,&#039;text1&#039;);&lt;br /&gt;
 INSERT INTO `t1_latin` (`id`, `string`) VALUES (2,&#039;text2&#039;);&lt;br /&gt;
&lt;br /&gt;
===== --result-file (-r) =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--result-file&amp;lt;/tt&amp;gt; option directs output to a given file.&lt;br /&gt;
&lt;br /&gt;
As this option prevents newline characters from being converted to carriage return/newline sequences, in a Windows environment it should be used:&lt;br /&gt;
&lt;br /&gt;
 mysqldump test04 &#039;&#039;&#039;-r&#039;&#039;&#039; test04.sql&lt;br /&gt;
&lt;br /&gt;
instead of using &amp;quot;&amp;gt;&amp;quot; to redirect output to file:&lt;br /&gt;
&lt;br /&gt;
 mysqldump test04 &amp;gt; test04.sql&lt;br /&gt;
&lt;br /&gt;
===== --single-transaction =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option issues a BEGIN SQL statement before dumping data from the server, and it should be used with transactional tables (like InnoDB).&lt;br /&gt;
&lt;br /&gt;
As this option and the &amp;lt;tt&amp;gt;--lock-tables&amp;lt;/tt&amp;gt; option are mutually exclusive, the &amp;lt;tt&amp;gt;--skip-lock-tables&amp;lt;/tt&amp;gt; option should also be used prior to using the &amp;lt;tt&amp;gt;--single-transaction&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqldump --skip-lock-tables --single-transaction test04 -r test04.sql&lt;br /&gt;
&lt;br /&gt;
===== --opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is shorthand for the following:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
|-&lt;br /&gt;
| --add-drop-table&lt;br /&gt;
| Add a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
|-&lt;br /&gt;
| --add-locks&lt;br /&gt;
| Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.&lt;br /&gt;
|-&lt;br /&gt;
| --create-options&lt;br /&gt;
| Include all MySQL-specific table options in CREATE TABLE statements.&lt;br /&gt;
|-&lt;br /&gt;
| --disable-keys&lt;br /&gt;
| For each table, surround the INSERT statements with statements to disable and enable keys.&lt;br /&gt;
|-&lt;br /&gt;
| --extended-insert&lt;br /&gt;
| Use multiple-row INSERT syntax that include several VALUES lists.&lt;br /&gt;
|-&lt;br /&gt;
| --lock-tables&lt;br /&gt;
| Lock all tables before dumping them.&lt;br /&gt;
|-&lt;br /&gt;
| --quick&lt;br /&gt;
| Retrieve rows for a table from the server a row at a time.&lt;br /&gt;
|-&lt;br /&gt;
| --set-charset&lt;br /&gt;
| Add SET NAMES default_character_set to the output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As all of these options are enabled by default, the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option is also enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --skip-opt =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--skip-opt&amp;lt;/tt&amp;gt; disables the &amp;lt;tt&amp;gt;--opt&amp;lt;/tt&amp;gt; option, which is enabled by default.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-database =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-database&amp;lt;/tt&amp;gt; option adds a DROP DATABASE statement before each CREATE DATABASE statement.&lt;br /&gt;
&lt;br /&gt;
===== --add-drop-table =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--add-drop-table&amp;lt;/tt&amp;gt; option adds a DROP TABLE statement before each CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
==== Internal structure of a dump file ====&lt;br /&gt;
&lt;br /&gt;
A dump file usually consists of three different elements: comments, conditional comments and SQL statements.&lt;br /&gt;
&lt;br /&gt;
===== Comments =====&lt;br /&gt;
&lt;br /&gt;
Comments are completely ignored by the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program and only serve to describe what follows. Comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 -- &#039;&#039;comment&#039;&#039; (e.g. -- MySQL dump 10.13  Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
&lt;br /&gt;
===== Conditional comments =====&lt;br /&gt;
&lt;br /&gt;
Conditional comments are used to hide SET commands or SQL statements from older versions of &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; (used to restore a dump file). Conditional comments have the following structure:&lt;br /&gt;
&lt;br /&gt;
 /*!&#039;&#039;five digit version number&#039;&#039; (e.g. /*!40101 or /*!40103)&lt;br /&gt;
 SET &#039;&#039;statement&#039;&#039; (e.g. SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT or SET NAMES utf8)&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
For example, the following conditional comment:&lt;br /&gt;
&lt;br /&gt;
 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test04` /*!40100 DEFAULT CHARACTER SET latin1 */;&lt;br /&gt;
&lt;br /&gt;
would be interpreted differently by each &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; version:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! mysql versions&lt;br /&gt;
! would read it as&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 3.23.12&lt;br /&gt;
| CREATE DATABASE `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 3.23.12 and &amp;lt; 4.1.0&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04`;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;=4.1.0 (4.01.00)&lt;br /&gt;
| CREATE DATABASE IF NOT EXISTS `test04` DEFAULT CHARACTER SET latin1;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conditional comments usually set some variables at the beginning of a block and reset them at the end.&lt;br /&gt;
&lt;br /&gt;
About the variable syntax of the SET command:&lt;br /&gt;
&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@@&#039;&#039;variable_name&#039;&#039;&amp;lt;/tt&amp;gt; can refer to a session value or a global value:&lt;br /&gt;
| * When being refered, MySQL returns the session value if it exists and the global value otherwise.&lt;br /&gt;
| * When being set (e.g. &amp;lt;tt&amp;gt;SET @@variable_name=value&amp;lt;/tt&amp;gt;), it always refers to the session value.&lt;br /&gt;
* The string &amp;lt;tt&amp;gt;@variable_name&amp;lt;/tt&amp;gt; refers to a user variable.&lt;br /&gt;
* When a variable doesn&#039;t have a modifier, it is a session variable.&lt;br /&gt;
&lt;br /&gt;
===== SQL statements =====&lt;br /&gt;
&lt;br /&gt;
The actual SQL statements, for example:&lt;br /&gt;
&lt;br /&gt;
 USE `test04`;&lt;br /&gt;
 DROP TABLE IF EXISTS `t1_latin`;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34521</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34521"/>
		<updated>2012-07-20T07:38:57Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Gathering information (1), settings and default values */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1) ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Also include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34520</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34520"/>
		<updated>2012-07-20T07:38:26Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Character sets and collations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Character set variables ===&lt;br /&gt;
&lt;br /&gt;
MySQL uses several “character set” type system variables that could be classified in three groups according to their use.&lt;br /&gt;
&lt;br /&gt;
==== For data encoding ====&lt;br /&gt;
&lt;br /&gt;
The following three determine the character encoding used to transform data as it flows from the client to the server and viceversa.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_client&amp;lt;/tt&amp;gt;. This variable defines the character set used by the client and in which it sends statements to the server.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server translates statements received from the client.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_results&amp;lt;/tt&amp;gt;. This variable defines the character set in which the server returns query results to the client.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For the &amp;lt;tt&amp;gt;character_set_connection&amp;lt;/tt&amp;gt; variable there is also a related collation type variable: &amp;lt;tt&amp;gt;collation_connection&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== As default values ====&lt;br /&gt;
&lt;br /&gt;
The following two are used to determine the character encoding to be used when a database or a table is created, respectively.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt;. This variable defines the character set of a new schema when the database charset is not specified in the CREATE DATABASE statement.&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt;. This variable defines the character set of a new table when the table charset is not specified in the CREATE TABLE statement.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. For these two variables there are also two related collation type variables: &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Other uses ====&lt;br /&gt;
&lt;br /&gt;
The following two have other uses.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_filesystem&amp;lt;/tt&amp;gt;. This variable defines the character set used by the file system (names of directories or names of files).&lt;br /&gt;
* &amp;lt;tt&amp;gt;character_set_system&amp;lt;/tt&amp;gt;. This variable defines the character set used to save metadata (data about data, for example, names of tables).&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1), settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Also include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34519</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34519"/>
		<updated>2012-07-20T00:06:55Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Default settings */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values for schema definitions when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The server character set and collation can be determined from the values of the &amp;lt;tt&amp;gt;character_set_server&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_server&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the &amp;lt;tt&amp;gt;character_set_database&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;collation_database&amp;lt;/tt&amp;gt; system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1), settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Also include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34518</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34518"/>
		<updated>2012-07-19T23:11:40Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Gathering useful information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1), settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Also include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (2) ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34517</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34517"/>
		<updated>2012-07-19T23:05:07Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Configuration files, settings and default values */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files ===&lt;br /&gt;
&lt;br /&gt;
==== MySQL settings ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering information (1), settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! OS&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| Windows&lt;br /&gt;
| &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf  C:\my.ini C:\my.cnf  &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
|-&lt;br /&gt;
| Linux&lt;br /&gt;
| /etc/my.cnf  /etc/mysql/my.cnf  SYSCONFDIR/my.cnf  $MYSQL_HOME/my.cnf&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows) and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Important note&#039;&#039;&#039;. The &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; program lists the values of the variables that the server (based on its compiled-in defaults) will use; however, some of those values might change depending on the command line parameters given. For example, if the &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; configuration file has the following lines:&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=utf8&lt;br /&gt;
&lt;br /&gt;
Then we will get a different value for variable &amp;lt;tt&amp;gt;character-set-server&amp;lt;/tt&amp;gt; if we use the &amp;lt;tt&amp;gt;no-defaults&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Action&lt;br /&gt;
! Value of &#039;&#039;character-set-server&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --no-defaults --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Ignore the settings in any option files.&lt;br /&gt;
| &amp;lt;tt&amp;gt;latin1&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;mysqld --verbose --help&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Also include the settings of any option files that it reads.&lt;br /&gt;
| &amp;lt;tt&amp;gt;utf8&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server program (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34501</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34501"/>
		<updated>2012-07-18T00:49:08Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Super Sed */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of &amp;lt;tt&amp;gt;sed&amp;lt;/tt&amp;gt; (a stream editor used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34500</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34500"/>
		<updated>2012-07-18T00:47:44Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Columns, character set and collation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, with different character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added to the SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of sed (a stream editor is used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34499</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34499"/>
		<updated>2012-07-18T00:39:46Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Columns, character set and collation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of sed (a stream editor is used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34498</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34498"/>
		<updated>2012-07-18T00:37:58Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Columns, character set and collation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german_ci  | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays all text type (e.g. varchar, text) columns in all tables of a particular database, that differ from a specific collation (e.g. &#039;&#039;latin1_swedish_ci&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;db_name&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_german1_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To display the same information, but only for a specific table, an extra AND clause can be added:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name,&lt;br /&gt;
   column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;,&lt;br /&gt;
   data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;db_name&#039;&lt;br /&gt;
 AND table_name = &#039;tbl_name&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;)&lt;br /&gt;
 AND collation_name NOT LIKE &#039;&amp;lt;em&amp;gt;latin1_swedish_ci&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of sed (a stream editor is used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34497</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34497"/>
		<updated>2012-07-18T00:27:22Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Table, how was it created */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
If a particular table was created with a specific character set and/or collation (i.e. it isn’t using the database’s default), the result will include the defined collation both in the table definition and in each of the text type column definitions, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t3_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) COLLATE latin1_spanish_ci NOT NULL,&lt;br /&gt;
   `coll_spa` text COLLATE latin1_spanish_ci,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci&lt;br /&gt;
&lt;br /&gt;
Furthermore, if a particular column was created with a specific character set and/or collation (i.e. it isn’t using the table’s default), the result will include the character set and collation definition in the respective column, for example:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t2_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_gr1` char(16) CHARACTER SET latin1 COLLATE latin1_german1_ci NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_gr1`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of sed (a stream editor is used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34496</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34496"/>
		<updated>2012-07-18T00:16:05Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* How was it created */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database was created with a specific character set and/or collation (i.e. it isn’t using the server’s default), the result will include the defined collation, for example:&lt;br /&gt;
&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                                             |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
 | temp01   | CREATE DATABASE `temp01` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */ |&lt;br /&gt;
 +----------+---------------------------------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of sed (a stream editor is used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=User:G._M.&amp;diff=34483</id>
		<title>User:G. M.</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=User:G._M.&amp;diff=34483"/>
		<updated>2012-07-15T07:11:59Z</updated>

		<summary type="html">&lt;p&gt;Gmads: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Gmads.png|Gmads]]&lt;br /&gt;
&lt;br /&gt;
Guillermo Madero&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=User:G._M.&amp;diff=34482</id>
		<title>User:G. M.</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=User:G._M.&amp;diff=34482"/>
		<updated>2012-07-15T07:11:43Z</updated>

		<summary type="html">&lt;p&gt;Gmads: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Gmads.png|Gmads]]&lt;br /&gt;
Guillermo Madero&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=User:G._M.&amp;diff=34481</id>
		<title>User:G. M.</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=User:G._M.&amp;diff=34481"/>
		<updated>2012-07-15T07:09:31Z</updated>

		<summary type="html">&lt;p&gt;Gmads: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Gmads Gmads.png]]&lt;br /&gt;
Guillermo Madero&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=File:Gmads.png&amp;diff=34480</id>
		<title>File:Gmads.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=File:Gmads.png&amp;diff=34480"/>
		<updated>2012-07-15T07:08:24Z</updated>

		<summary type="html">&lt;p&gt;Gmads: Guillermo Madero&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Guillermo Madero&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=User:G._M.&amp;diff=34479</id>
		<title>User:G. M.</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=User:G._M.&amp;diff=34479"/>
		<updated>2012-07-15T07:07:07Z</updated>

		<summary type="html">&lt;p&gt;Gmads: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Gmads Edit Gmads.png]]&lt;br /&gt;
Guillermo Madero&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34478</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34478"/>
		<updated>2012-07-15T06:52:58Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Useful tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
The tools listed here are useful when working with database dumps and character encodings.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of sed (a stream editor is used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34477</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34477"/>
		<updated>2012-07-15T06:51:42Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Columns, character set and collation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
== Useful tools ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
The following tools are useful when working with database dumps and character encodings in a Windows environment.&lt;br /&gt;
&lt;br /&gt;
==== SuperEdi ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wolosoft.com/en/superedi/ SuperEdi] is a text editor that supports Unicode UTF-8, UTF-16 and many locale-specific encodings.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.wolosoft.com/files/SuperEdi-4.3.3.exe SuperEdi].&lt;br /&gt;
&lt;br /&gt;
==== HxD hexeditor ====&lt;br /&gt;
&lt;br /&gt;
[http://mh-nexus.de/en/ HxD hexeditor] is a fast free hex editor that can open files of any size.&lt;br /&gt;
&lt;br /&gt;
Download: [http://mh-nexus.de/downloads/HxDSetupEN.zip HxD hexeditor].&lt;br /&gt;
&lt;br /&gt;
==== Super Sed ====&lt;br /&gt;
&lt;br /&gt;
[http://sed.sourceforge.net/grabbag/ssed/ Super Sed] is a heavily enhanced version of sed (a stream editor is used to perform basic text transformations on an input stream).&lt;br /&gt;
&lt;br /&gt;
Download: [http://sed.sourceforge.net/grabbag/ssed/sed-3.62.zip Super Sed].&lt;br /&gt;
&lt;br /&gt;
==== LibIconv ====&lt;br /&gt;
&lt;br /&gt;
GNU [http://gnuwin32.sourceforge.net/packages/libiconv.htm LibIconv] is an encoding conversion library.&lt;br /&gt;
&lt;br /&gt;
Download: [http://gnuwin32.sourceforge.net/downlinks/libiconv.php LibIconv complete package].&lt;br /&gt;
&lt;br /&gt;
Download zip files (only the bin folder has to be extracted from both files):&lt;br /&gt;
&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php LibIconv binaries].&lt;br /&gt;
* [http://gnuwin32.sourceforge.net/downlinks/libiconv-dep-zip.php LibIconv dependencies].&lt;br /&gt;
&lt;br /&gt;
==== Charco ====&lt;br /&gt;
&lt;br /&gt;
[http://www.marblesoftware.com/Marble_Software/Charco.html Charco] is a character set conversion tool used to recode character sets, much like iconv on Linux does, but in a more portable way and with a GUI for easy-of-use. Charco supports the most common character set encodings found on Windows, OS X and Linux, including a full complement of UTF-encodings. Charco also has a batch processing mode.&lt;br /&gt;
&lt;br /&gt;
Download: [http://www.marblesoftware.com/downloads/windows/Charco%20for%20Windows.zip Charco].&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34476</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34476"/>
		<updated>2012-07-15T06:37:21Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* MySQL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands display a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command displays a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query displays the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs something like:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34475</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34475"/>
		<updated>2012-07-15T06:33:05Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Columns, character set and collation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands can output a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command outputs a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the first AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 | test02       | t2_latin   | coll_gr1    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34474</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34474"/>
		<updated>2012-07-15T06:18:16Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* How was it created */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its character set and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands can output a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command outputs a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34473</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34473"/>
		<updated>2012-07-15T06:02:21Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Columns, character set and collation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands can output a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command outputs a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all text type (e.g. &amp;lt;tt&amp;gt;varchar&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;text&amp;lt;/tt&amp;gt;) columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34472</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34472"/>
		<updated>2012-07-15T05:39:50Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Tables and columns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands can output a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command outputs a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34471</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34471"/>
		<updated>2012-07-15T05:37:56Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Basic server status information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use db_name;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands can output a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command outputs a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34470</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34470"/>
		<updated>2012-07-15T05:37:02Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Tables and columns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use these queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use db_name;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands can output a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command outputs a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34469</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34469"/>
		<updated>2012-07-15T05:36:12Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables and columns ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the table queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use db_name;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== Table, how was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Table, describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands can output a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command outputs a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Table, index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Table, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
===== Columns, character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, character_set_name &amp;quot;column_character_set&amp;quot;, collation_name &amp;quot;column_collation&amp;quot;, data_type, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | column_character_set | column_collation  | data_type | column_type |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | latin1               | latin1_swedish_ci | char      | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+----------------------+-------------------+-----------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34468</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34468"/>
		<updated>2012-07-15T05:30:14Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Columns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the table queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use db_name;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands can output a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command outputs a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Show index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34467</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34467"/>
		<updated>2012-07-15T05:26:49Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Show index information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the table queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use db_name;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands can output a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command outputs a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Show index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes (if there are any) on a table.&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Columns ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, data_type, character_set_name, collation_name, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;dbname&#039;&lt;br /&gt;
 AND table_name = &#039;tblname&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | data_type | character_set_name | collation_name    | column_type |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | char      | latin1             | latin1_swedish_ci | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34466</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34466"/>
		<updated>2012-07-15T05:21:51Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Describe its structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the table queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use db_name;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Describe its structure =====&lt;br /&gt;
&lt;br /&gt;
Either of the two following commands can output a simple view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
 SHOW COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
The following command outputs a more complete view of the structure of table.&lt;br /&gt;
&lt;br /&gt;
 SHOW FULL COLUMNS FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | Field    | Type                 | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 | coll_swd | char(16)             | latin1_swedish_ci | NO   | PRI | NULL    |       | select,insert,update,references |         |&lt;br /&gt;
 +----------+----------------------+-------------------+------+-----+---------+-------+---------------------------------+---------+&lt;br /&gt;
&lt;br /&gt;
===== Show index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes on a table (if there are any).&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Columns ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, data_type, character_set_name, collation_name, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;dbname&#039;&lt;br /&gt;
 AND table_name = &#039;tblname&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | data_type | character_set_name | collation_name    | column_type |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | char      | latin1             | latin1_swedish_ci | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34465</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34465"/>
		<updated>2012-07-15T05:13:17Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* How was it created */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the table queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use db_name;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Describe its structure =====&lt;br /&gt;
&lt;br /&gt;
The following command describes the structure of table.&lt;br /&gt;
&lt;br /&gt;
 DESCRIBE &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | Field    | Type                 | Null | Key | Default | Extra |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
 | userid   | smallint(5) unsigned | YES  |     | NULL    |       |&lt;br /&gt;
 | coll_swd | char(16)             | NO   | PRI | NULL    |       |&lt;br /&gt;
 +----------+----------------------+------+-----+---------+-------+&lt;br /&gt;
&lt;br /&gt;
===== Show index information =====&lt;br /&gt;
&lt;br /&gt;
The following command lists the indexes on a table (if there are any).&lt;br /&gt;
&lt;br /&gt;
 SHOW INDEX FROM &#039;&#039;tbl_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
 | t1_latin |          0 | PRIMARY  |            1 | coll_swd    | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |&lt;br /&gt;
 +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Columns ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, data_type, character_set_name, collation_name, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;dbname&#039;&lt;br /&gt;
 AND table_name = &#039;tblname&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | data_type | character_set_name | collation_name    | column_type |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | char      | latin1             | latin1_swedish_ci | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34464</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34464"/>
		<updated>2012-07-15T04:41:53Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* How was it created */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the table queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use db_name;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a table was created.&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE tbl_name;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Columns ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, data_type, character_set_name, collation_name, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;dbname&#039;&lt;br /&gt;
 AND table_name = &#039;tblname&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | data_type | character_set_name | collation_name    | column_type |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | char      | latin1             | latin1_swedish_ci | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34463</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34463"/>
		<updated>2012-07-15T04:40:06Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Character set and collation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the table queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use db_name;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE tbl_name;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, one only needs to remove the last AND clause from the previous query.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Columns ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, data_type, character_set_name, collation_name, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;dbname&#039;&lt;br /&gt;
 AND table_name = &#039;tblname&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | data_type | character_set_name | collation_name    | column_type |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | char      | latin1             | latin1_swedish_ci | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34462</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34462"/>
		<updated>2012-07-15T04:31:48Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Character set and collation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the table queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use db_name;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE tbl_name;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, the last AND clause must be removed.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Columns ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, data_type, character_set_name, collation_name, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;dbname&#039;&lt;br /&gt;
 AND table_name = &#039;tblname&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | data_type | character_set_name | collation_name    | column_type |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | char      | latin1             | latin1_swedish_ci | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34461</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34461"/>
		<updated>2012-07-15T04:30:39Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables ====&lt;br /&gt;
&lt;br /&gt;
A database must first be selected before trying to use the table queries.&lt;br /&gt;
&lt;br /&gt;
* From a mysql command window:&lt;br /&gt;
 use db_name;&lt;br /&gt;
&lt;br /&gt;
* From phpMyAdmin, just select the database to be used.&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
 SHOW CREATE TABLE tbl_name;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `t1_latin` (&lt;br /&gt;
   `userid` smallint(5) unsigned DEFAULT NULL,&lt;br /&gt;
   `coll_swd` char(16) NOT NULL,&lt;br /&gt;
   PRIMARY KEY (`coll_swd`)&lt;br /&gt;
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of a table in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;&lt;br /&gt;
 AND t.table_name = &#039;&amp;lt;em&amp;gt;tbl_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
To list the same information for all the tables in a particular schema, the last AND clause must be removed.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
      information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Columns ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, data_type, character_set_name, collation_name, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;dbname&#039;&lt;br /&gt;
 AND table_name = &#039;tblname&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | data_type | character_set_name | collation_name    | column_type |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | char      | latin1             | latin1_swedish_ci | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34460</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34460"/>
		<updated>2012-07-15T02:43:12Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* How was it created */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&#039;db_name&#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all tables in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;dbname&#039;&lt;br /&gt;
 ORDER BY table_schema, table_name;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Columns ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, data_type, character_set_name, collation_name, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;dbname&#039;&lt;br /&gt;
 AND table_name = &#039;tblname&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | data_type | character_set_name | collation_name    | column_type |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | char      | latin1             | latin1_swedish_ci | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34459</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34459"/>
		<updated>2012-07-15T02:15:35Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* How was it created */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all tables in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;dbname&#039;&lt;br /&gt;
 ORDER BY table_schema, table_name;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Columns ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, data_type, character_set_name, collation_name, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;dbname&#039;&lt;br /&gt;
 AND table_name = &#039;tblname&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | data_type | character_set_name | collation_name    | column_type |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | char      | latin1             | latin1_swedish_ci | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34458</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34458"/>
		<updated>2012-07-15T02:00:14Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
===== How was it created =====&lt;br /&gt;
&lt;br /&gt;
The following command shows how a database (schema) was created (i.e., the complete CREATE DATABASE statement used to create it).&lt;br /&gt;
&lt;br /&gt;
 show create database &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and/or collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
===== Character set and collation =====&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;&amp;lt;em&amp;gt;db_name&amp;lt;/em&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all tables in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;dbname&#039;&lt;br /&gt;
 ORDER BY table_schema, table_name;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Columns ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, data_type, character_set_name, collation_name, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;dbname&#039;&lt;br /&gt;
 AND table_name = &#039;tblname&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | data_type | character_set_name | collation_name    | column_type |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | char      | latin1             | latin1_swedish_ci | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34457</id>
		<title>Reference</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Reference&amp;diff=34457"/>
		<updated>2012-07-15T01:05:25Z</updated>

		<summary type="html">&lt;p&gt;Gmads: /* Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==This is the start of a few pages of largely version independent reference==&lt;br /&gt;
&lt;br /&gt;
In the spirit of wiki and in response to the post here: http://moodle.org/mod/forum/discuss.php?d=205117&lt;br /&gt;
&lt;br /&gt;
Go for it Guillermo.&lt;br /&gt;
&lt;br /&gt;
Maybe start here, and later on add a category:Reference and see what happens.  I&#039;ve set a watch on, and I may do a page on JSON errors.&lt;br /&gt;
&lt;br /&gt;
= Database =&lt;br /&gt;
&lt;br /&gt;
I&#039;ll start writing here about database and utf8 issues, but I guess that the idea would be for this to be the main reference table of contents page so it then links to each main topic page.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Byte, character, character set, character encoding and collation ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;byte&#039;&#039; (or &#039;&#039;octet&#039;&#039;) is the smallest unit of storage that can be allocated and, in almost all modern computers, it consists of 8 bits, where a bit can only have two values: 0 or 1.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character&#039;&#039; is a symbol used in a writing system, such as a letter of the alphabet.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character set&#039;&#039;, or a &#039;&#039;coded character set&#039;&#039;, refers to the set of characters and numbers, or &#039;&#039;code points&#039;&#039;, used to represent them. A code point can be understood as the position the character occupies in the set.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;character encoding&#039;&#039;, or a &#039;&#039;character encoding form&#039;&#039;, refers to how the code points are converted (encoded) into &#039;&#039;code values&#039;&#039; to be saved or stored in a computer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Unicode&#039;&#039; is a character set developed to consistently encode, represent and handle text in most of the world&#039;s writing systems in use today. Unicode can be implemented by different character encodings, where the two most commonly used are UTF-8 and UTF-16:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;UTF-8&#039;&#039;&#039; is a variable-width character encoding that can represent every character in the Unicode character set. UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four bytes.&lt;br /&gt;
:&#039;&#039;&#039;Note&#039;&#039;&#039;. MySQL utf8 Unicode character set uses a maximum of three bytes per multi-byte character (http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8.html).&lt;br /&gt;
* &#039;&#039;&#039;UTF-16&#039;&#039;&#039; is a variable-length character encoding for Unicode that uses one or two 16-bit code units, where each unit takes two 8-bit bytes, and the order of the bytes may depend on the byte order (&#039;&#039;endianness&#039;&#039;) of the computer architecture. To assist in recognizing the byte order of code units, UTF-16 allows a &#039;&#039;Byte Order Mark&#039;&#039; (BOM), a code unit with the hexadecimal value U+FEFF, to precede the first actual coded value.&lt;br /&gt;
&lt;br /&gt;
Eventhough UTF-8 is the preferred character encoding nowadays, many others have been used, for example:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-1&#039;&#039;&#039; (or &#039;&#039;Latin-1&#039;&#039;). A character encoding for the Latin script, where each character is encoded as a single 8-bit code value. This character-encoding scheme consists of 191 characters and it is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.&lt;br /&gt;
* &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (or &#039;&#039;Latin-9&#039;&#039;). A character encoding similar to Latin-1, except that it substituted some rarely used characters with the euro sign and a few other letters.&lt;br /&gt;
* &#039;&#039;&#039;Shift JIS&#039;&#039;&#039;. A character encoding for the Japanese language.&lt;br /&gt;
&lt;br /&gt;
To illustrate the concepts given above, the € (euro) character has a code point equal to 8364 (or U+20AC, in hexadecimal notation) in the Unicode character set. This code point can be stored in different ways, depending on the character encoding used:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character encoding&lt;br /&gt;
! Code value&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ISO-8859-15&#039;&#039;&#039; (hexadecimal)&lt;br /&gt;
| A4&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-8&#039;&#039;&#039; (hex)&lt;br /&gt;
| E2 82 AC&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;UTF-16&#039;&#039;&#039; (hex)&lt;br /&gt;
| 20AC&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Finally, a &#039;&#039;Collation&#039;&#039; determines how data is sorted and how strings are compared to each other.&lt;br /&gt;
&lt;br /&gt;
=== Encoding and decoding ===&lt;br /&gt;
&lt;br /&gt;
One of the most important things one must keep in mind when working with databases (or files, for that matter) is to be aware of how characters (letters, numbers and non-alphanumeric characters) are actually being saved or encoded and how bytes (represented with hexadecimal values) are actually being interpreted or decoded.&lt;br /&gt;
&lt;br /&gt;
For example, it is not enough to say that character “é” (small letter e with acute) has been saved in a text file, one also has to be aware of how was it encoded. Why? Because if it was encoded as Latin-1, the file will have one byte of hex value E9, but if it was encoded as UTF-8, the file would then have two bytes of hex value C3 and A9:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character&lt;br /&gt;
! Latin-1 hex value&lt;br /&gt;
! UTF-8 hex values&lt;br /&gt;
|-&lt;br /&gt;
| é&lt;br /&gt;
| E9&lt;br /&gt;
| C3 A9&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the same way, it is not enough to say that an UTF-8 encoded character “é” is going to be read from a text file, because eventhough we might know that two bytes of hex value “C3 A9” will be read, if they are decoded (interpreted) as Latin-1, we will get characters Ã©, but if they are decoded as UTF-8, we would then get character “é”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Hex value&lt;br /&gt;
! Latin-1 characters&lt;br /&gt;
! UTF-8 character&lt;br /&gt;
|-&lt;br /&gt;
| C3 A9&lt;br /&gt;
| Ã©&lt;br /&gt;
| é&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Being aware of these two concepts will become relevant when trying to understand how data is encoded and decoded through the many stages (source, client, server) in order to be saved or restored.&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Character sets and collations ===&lt;br /&gt;
&lt;br /&gt;
Until version 4.1, MySQL tables used the latin1 character set by default. From version 4.1, not only the concepts of &amp;quot;character set&amp;quot; and &amp;quot;collation&amp;quot; were introduced, but the character set by default (at the configuration file) was changed to utf8.&lt;br /&gt;
&lt;br /&gt;
In MySQL, a &#039;&#039;character set&#039;&#039; is a set of symbols and encodings, and a &#039;&#039;collation&#039;&#039; is a set of rules for comparing characters in a character set.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. Eventhough in MySQL the term &amp;quot;character set&amp;quot; is used, actually it should be &amp;quot;character encoding&amp;quot; (&amp;quot;charset&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The MySQL server supports multiple character sets, like ascii, koi8r, latin1, sjis and utf8. Each character set has at least one collation, however, as it may have many more, a default one is always defined for each character set.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Character set&lt;br /&gt;
! Default collation&lt;br /&gt;
! Other collations&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ascii&#039;&#039;&#039;&lt;br /&gt;
| ascii_general_ci&lt;br /&gt;
| ascii_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;koi8r&#039;&#039;&#039;&lt;br /&gt;
| koi8r_general_ci&lt;br /&gt;
| koi8r_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;latin1&#039;&#039;&#039;&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
| latin1_bin, latin1_general_ci, latin1_spanish_ci&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;sjis&#039;&#039;&#039;&lt;br /&gt;
| sjis_japanese_ci&lt;br /&gt;
| sjis_bin&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;utf8&#039;&#039;&#039;&lt;br /&gt;
| utf8_general_ci&lt;br /&gt;
| utf8_bin, utf8_unicode_ci, utf8_turkish_ci&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Collation names follow a convention: they start with the name of the character set with which they are associated, they usually include a language name, and they end with &#039;&#039;&#039;_ci&#039;&#039;&#039; (case insensitive), &#039;&#039;&#039;_cs&#039;&#039;&#039; (case sensitive), or &#039;&#039;&#039;_bin&#039;&#039;&#039; (binary). From this, is should be evident that two different character sets cannot have the same collation.&lt;br /&gt;
&lt;br /&gt;
=== Default settings ===&lt;br /&gt;
&lt;br /&gt;
The MySQL database server uses a very flexible scheme where default settings for character sets and collations can be set at four levels: Server, Database, Table and Column.&lt;br /&gt;
&lt;br /&gt;
; Server&lt;br /&gt;
: The server charset and collation are used as default values when the database charset and collation are not specified in &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The current server character set and collation can be determined from the values of the character_set_server and collation_server system variables.&lt;br /&gt;
&lt;br /&gt;
; Database&lt;br /&gt;
: The database charset and collation are used as default values for table definitions when the table charset and collation are not specified in &amp;lt;code&amp;gt;CREATE TABLE&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
: The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.&lt;br /&gt;
&lt;br /&gt;
; Table&lt;br /&gt;
: The table charset and collation are used as default values for column definitions when the column charset and collation are not specified in individual column definitions.&lt;br /&gt;
: The table character set and collation are MySQL extensions; there do not exist in standard SQL.&lt;br /&gt;
&lt;br /&gt;
; Column&lt;br /&gt;
: A character set and a collation may be specified for every &amp;quot;character&amp;quot; column (that is, columns of type CHAR, VARCHAR, or TEXT).&lt;br /&gt;
: The column character set and collate clauses are standard SQL.&lt;br /&gt;
&lt;br /&gt;
=== Configuration files, settings and default values ===&lt;br /&gt;
&lt;br /&gt;
To run the commands given in this section, one has to have direct access to the MySQL server.&lt;br /&gt;
&lt;br /&gt;
From here on it will be assumed that the server is already running. Also, for Windows users, commands must be entered from a Windows command (system) window.&lt;br /&gt;
&lt;br /&gt;
==== Server and client ====&lt;br /&gt;
&lt;br /&gt;
All MySQL settings, both for the server and the client components, are defined under one configuration or option file: &amp;lt;tt&amp;gt;my.ini&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;my.cnf&amp;lt;/tt&amp;gt; (Linux), although many copies of this file might be read at startup.&lt;br /&gt;
&lt;br /&gt;
Settings in the configuration file are divided in option groups, where each one contains the settings for: the server, all clients and each particular client:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Settings for&lt;br /&gt;
! Option group&lt;br /&gt;
|-&lt;br /&gt;
| The server&lt;br /&gt;
| [mysqld], [server], etc.&lt;br /&gt;
|-&lt;br /&gt;
| All clients&lt;br /&gt;
| [client]&lt;br /&gt;
|-&lt;br /&gt;
| Each particular client&lt;br /&gt;
| [mysql], [mysqldump], [myisamchk], [mysqlhotcopy], etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Running a particular program with the parameters &amp;lt;tt&amp;gt;--verbose --help&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 mysqld --verbose --help&lt;br /&gt;
 mysql --verbose --help&lt;br /&gt;
 mysqldump --verbose --help&lt;br /&gt;
&lt;br /&gt;
will list four pieces of information:&lt;br /&gt;
&lt;br /&gt;
# The location of the configuration files.&lt;br /&gt;
# The option groups read by the program.&lt;br /&gt;
# The allowed options or variables (parameters) with their abreviations and descriptions.&lt;br /&gt;
# The default values of variables that can be set from the command line.&lt;br /&gt;
&lt;br /&gt;
===== Location of the configuration files =====&lt;br /&gt;
&lt;br /&gt;
Default options are read from the following files in the given order:&lt;br /&gt;
&lt;br /&gt;
; Windows&lt;br /&gt;
: &#039;&#039;WINDIR&#039;&#039;\my.ini &#039;&#039;WINDIR&#039;&#039;\my.cnf C:\my.ini C:\my.cnf &#039;&#039;INSTALLDIR&#039;&#039;\my.ini &#039;&#039;INSTALLDIR&#039;&#039;\my.cnf&lt;br /&gt;
: Where &#039;&#039;WINDIR&#039;&#039; is the Windows directory (e.g. C:\Windows), and &#039;&#039;INSTALLDIR&#039;&#039; is the MySQL installation directory (e.g. C:\MySqlServer5.5).&lt;br /&gt;
&lt;br /&gt;
; Linux&lt;br /&gt;
: /etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR/my.cnf $MYSQL_HOME/my.cnf&lt;br /&gt;
&lt;br /&gt;
===== The option groups read =====&lt;br /&gt;
&lt;br /&gt;
The option groups (in the configuration file) read by each program; for example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Program&lt;br /&gt;
! The following groups are read&lt;br /&gt;
|-&lt;br /&gt;
| mysqld&lt;br /&gt;
| mysqld server mysqld-5.5&lt;br /&gt;
|-&lt;br /&gt;
| mysql&lt;br /&gt;
| mysql client&lt;br /&gt;
|-&lt;br /&gt;
| mysqldump&lt;br /&gt;
| mysqldump client&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Allowed options (variables) =====&lt;br /&gt;
&lt;br /&gt;
The variables accepted (in the command line) by the program, with their abreviations and descriptions; for example, the following are some of those listed for the &amp;lt;tt&amp;gt;mysql&amp;lt;/tt&amp;gt; client program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable (option)&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| -D, --database=name&lt;br /&gt;
| Database to use.&lt;br /&gt;
|-&lt;br /&gt;
| --default-character-set=name&lt;br /&gt;
| Set the default character set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== Variables and their values =====&lt;br /&gt;
&lt;br /&gt;
The default values of variables that can be set from the command line for each program; for example, the following are some of those listed by the &amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt; server program:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Default value&lt;br /&gt;
|-&lt;br /&gt;
| basedir&lt;br /&gt;
| C:/MySqlServer5.5/&lt;br /&gt;
|-&lt;br /&gt;
| character-set-server&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| datadir&lt;br /&gt;
| C:\ MySqlServer5.5\Data\&lt;br /&gt;
|-&lt;br /&gt;
| date-format&lt;br /&gt;
| %Y-%m-%d&lt;br /&gt;
|-&lt;br /&gt;
| innodb&lt;br /&gt;
| ON&lt;br /&gt;
|-&lt;br /&gt;
| tmpdir&lt;br /&gt;
| C:\Tmp&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== System values used by a running server ====&lt;br /&gt;
&lt;br /&gt;
While the &amp;lt;tt&amp;gt;--help --verbose&amp;lt;/tt&amp;gt; options of the MySQL server (&amp;lt;tt&amp;gt;mysqld&amp;lt;/tt&amp;gt;) show command line options and their default values, there are also other variables that can only be seen after the server has been started and that provide information about its operation.&lt;br /&gt;
&lt;br /&gt;
To see what system values is using a running server, the &amp;lt;tt&amp;gt;mysqladmin&amp;lt;/tt&amp;gt; program can be used with the &amp;lt;tt&amp;gt;variables&amp;lt;/tt&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] variables&lt;br /&gt;
&lt;br /&gt;
The following are some of the variables and values listed:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
! Variable_name&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| character_set_client&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| character_set_connection&lt;br /&gt;
| latin1&lt;br /&gt;
|-&lt;br /&gt;
| collation_connection&lt;br /&gt;
| latin1_swedish_ci&lt;br /&gt;
|-&lt;br /&gt;
| connect_timeout&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The server status information provided by the mysqladmin &amp;lt;tt&amp;gt;extended-status&amp;lt;/tt&amp;gt; option is rather technical and so it will only be useful for DBA’s, however it is worth knowing how to display it:&lt;br /&gt;
&lt;br /&gt;
 mysqladmin [-u root -p&#039;&#039;your_password&#039;&#039;] extended-status&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
For each database created, its character set and collation values are saved in a text file named &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt;, located in the corresponding database folder (&#039;&#039;dbname&#039;&#039;) under the &#039;&#039;datadir&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
 more C:\MySqlServer5.5\data\&#039;&#039;dbname&#039;&#039;\db.opt&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
When a database is first created, if the character set and collation options are not defined in the &amp;lt;code&amp;gt;CREATE DATABASE&amp;lt;/code&amp;gt; statement, then they are taken from the server charset and collation values. These two values can be modified via the &amp;lt;code&amp;gt;ALTER DATABASE&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
=== Gathering useful information ===&lt;br /&gt;
&lt;br /&gt;
The first step before trying to fix a character set or a collation problem in a database, table or column is to determine how are they actually defined. The aim of this section then, is to show how to get specific pieces of information about these components.&lt;br /&gt;
&lt;br /&gt;
To run all the SQL queries shown in this section, one can work from:&lt;br /&gt;
&lt;br /&gt;
* A mysql command window, in which case the mysql client program must be running:&lt;br /&gt;
&lt;br /&gt;
 mysql -u root -p&#039;&#039;your_password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Starts a mysql session:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The phpMyAdmin tool, through the “Run SQL query/queries on database dbname” window.&lt;br /&gt;
&lt;br /&gt;
==== Saving the output of a query into a file ====&lt;br /&gt;
&lt;br /&gt;
As results from many commands might be a bit long to be analyzed from a window, it is useful to know how to send them into a file.&lt;br /&gt;
&lt;br /&gt;
The following commands can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
===== Windows =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;notee&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee e:/tmp/vars.out;&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; notee;&lt;br /&gt;
 Outfile disabled.&lt;br /&gt;
&lt;br /&gt;
To determine into which file output is being written, just type &amp;lt;tt&amp;gt;tee&amp;lt;/tt&amp;gt; by itself:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; tee;&lt;br /&gt;
 Currently logging to file &#039;e:/tmp/vars.out&#039;&lt;br /&gt;
&lt;br /&gt;
===== Unix =====&lt;br /&gt;
&lt;br /&gt;
Use command &amp;lt;tt&amp;gt;pager&amp;lt;/tt&amp;gt; to save the output of a query into a file, and command &amp;lt;tt&amp;gt;nopager&amp;lt;/tt&amp;gt; to stop writing into a file. For example:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; pager cat &amp;gt; /tmp/vars.out&lt;br /&gt;
 mysql&amp;gt; show variables;&lt;br /&gt;
 mysql&amp;gt; nopager;&lt;br /&gt;
&lt;br /&gt;
===== phpMyAdmin =====&lt;br /&gt;
&lt;br /&gt;
Once a query is run and the results are displayed, the &amp;lt;tt&amp;gt;Print view&amp;lt;/tt&amp;gt; or the &amp;lt;tt&amp;gt;Print view (with full texts)&amp;lt;/tt&amp;gt; links from the &amp;lt;tt&amp;gt;Query results operations&amp;lt;/tt&amp;gt; section can be used to save them.&lt;br /&gt;
&lt;br /&gt;
==== Basic server status information ====&lt;br /&gt;
&lt;br /&gt;
The STATUS command will get basic status information from the server, like the current database in use, the server version, the TCP port or the characterset defined for the server, the database, the client and the connection. This command can only be run from a mysql command window.&lt;br /&gt;
&lt;br /&gt;
 STATUS;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 Current database:&lt;br /&gt;
 mysql  Ver 14.14 Distrib 5.5.8, for Win32 (x86)&lt;br /&gt;
 Connection id:          232&lt;br /&gt;
 Current database:&lt;br /&gt;
 Current user:           root@localhost&lt;br /&gt;
 SSL:                    Not in use&lt;br /&gt;
 Using delimiter:        ;&lt;br /&gt;
 Server version:         5.5.8 MySQL Community Server (GPL)&lt;br /&gt;
 Protocol version:       10&lt;br /&gt;
 Connection:             localhost via TCP/IP&lt;br /&gt;
 Server characterset:    latin1&lt;br /&gt;
 Db     characterset:    latin1&lt;br /&gt;
 Client characterset:    latin1&lt;br /&gt;
 Conn.  characterset:    latin1&lt;br /&gt;
 TCP port:               3306&lt;br /&gt;
 Uptime:                 18 hours 25 min 38 sec&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the Db characterset variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
==== Server status information ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same variables as the &amp;lt;tt&amp;gt;mysqladmin extended-status&amp;lt;/tt&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
==== System variables with their values ====&lt;br /&gt;
&lt;br /&gt;
The following will list the same system variables as the &amp;lt;tt&amp;gt;mysqladmin variables&amp;lt;/tt&amp;gt; command, plus a few more:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
&lt;br /&gt;
As the list of variables is quite long, the LIKE clause can be used to list only those that match.&lt;br /&gt;
&lt;br /&gt;
To list all the character_set variables:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;character_set\_%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | Variable_name            | Value                             |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
 | character_set_client     | latin1                            |&lt;br /&gt;
 | character_set_connection | latin1                            |&lt;br /&gt;
 | character_set_database   | latin1                            |&lt;br /&gt;
 | character_set_filesystem | binary                            |&lt;br /&gt;
 | character_set_results    | latin1                            |&lt;br /&gt;
 | character_set_server     | latin1                            |&lt;br /&gt;
 | character_set_system     | utf8                              |&lt;br /&gt;
 +--------------------------+-----------------------------------+&lt;br /&gt;
&lt;br /&gt;
If a database hasn’t been set active, the character_set_database variable will contain the global default, otherwise its value will reflect that of the selected database.&lt;br /&gt;
&lt;br /&gt;
To list all the collations defined:&lt;br /&gt;
&lt;br /&gt;
 SHOW VARIABLES LIKE &#039;coll%&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | Variable_name        | Value             |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
 | collation_connection | latin1_swedish_ci |&lt;br /&gt;
 | collation_database   | latin1_swedish_ci |&lt;br /&gt;
 | collation_server     | latin1_swedish_ci |&lt;br /&gt;
 +----------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Database ====&lt;br /&gt;
&lt;br /&gt;
The following command outputs the defined database (schema) character set.&lt;br /&gt;
&lt;br /&gt;
 show create database dbname;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | Database | Create Database                                                   |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
 | test02   | CREATE DATABASE `test02` /*!40100 DEFAULT CHARACTER SET latin1 */ |&lt;br /&gt;
 +----------+-------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
As mentioned before, when a database is created or when its characterset and collation are modified, these two values are saved in the corresponding &amp;lt;tt&amp;gt;db.opt&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
The following SQL statement gives both, the character set and collation of a schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT schema_name, default_character_set_name &amp;quot;character_set&amp;quot;, default_collation_name &amp;quot;collation&amp;quot;&lt;br /&gt;
 FROM information_schema.schemata&lt;br /&gt;
 WHERE schema_name = &#039;dbname&#039;;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | schema_name | character_set | collation         |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
 | test02      | latin1        | latin1_swedish_ci |&lt;br /&gt;
 +-------------+---------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
It is important to remember that these values only act as defaults to define the character set and the collation of newly created tables.&lt;br /&gt;
&lt;br /&gt;
==== Tables ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all tables in a particular schema.&lt;br /&gt;
&lt;br /&gt;
 SELECT t.table_schema, t.table_name, ccsa.character_set_name &amp;quot;table_character_set&amp;quot;, t.table_collation&lt;br /&gt;
 FROM information_schema.`tables` t,&lt;br /&gt;
 information_schema.`collation_character_set_applicability` ccsa&lt;br /&gt;
 WHERE ccsa.collation_name = t.table_collation&lt;br /&gt;
 AND t.table_schema = &#039;dbname&#039;&lt;br /&gt;
 ORDER BY table_schema, table_name;&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | table_schema | table_name | table_character_set | table_collation   |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
 | test02       | t1_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 | test02       | t2_latin   | latin1              | latin1_swedish_ci |&lt;br /&gt;
 +--------------+------------+---------------------+-------------------+&lt;br /&gt;
&lt;br /&gt;
==== Columns ====&lt;br /&gt;
&lt;br /&gt;
The following SQL query outputs the character set and collation of all columns in a particular table.&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema, table_name, column_name, data_type, character_set_name, collation_name, column_type&lt;br /&gt;
 FROM information_schema.columns&lt;br /&gt;
 WHERE table_schema = &#039;dbname&#039;&lt;br /&gt;
 AND table_name = &#039;tblname&#039;&lt;br /&gt;
 AND data_type IN (&#039;char&#039;, &#039;varchar&#039;, &#039;tinytext&#039;, &#039;text&#039;, &#039;mediumtext&#039;, &#039;longtext&#039;, &#039;enum&#039;, &#039;set&#039;);&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | table_schema | table_name | column_name | data_type | character_set_name | collation_name    | column_type |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;br /&gt;
 | test02       | t1_latin   | coll_swd    | char      | latin1             | latin1_swedish_ci | char(16)    |&lt;br /&gt;
 +--------------+------------+-------------+-----------+--------------------+-------------------+-------------+&lt;/div&gt;</summary>
		<author><name>Gmads</name></author>
	</entry>
</feed>