Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code DEF204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.

Rechercher dans le manuel MySQL

10.8.7 Using Collation in INFORMATION_SCHEMA Searches

String columns in INFORMATION_SCHEMA tables have a collation of utf8_general_ci, which is case insensitive. However, for values that correspond to objects that are represented in the file system, such as databases and tables, searches in INFORMATION_SCHEMA string columns can be case-sensitive or insensitive, depending on the characteristics of the underlying file system and the lower_case_table_names system variable setting. For example, searches may be case-sensitive if the file system is case-sensitive. This section describes this behavior and how to modify it if necessary.

Suppose that a query searches the SCHEMATA.SCHEMA_NAME column for the test database. On Linux, file systems are case-sensitive, so comparisons of SCHEMATA.SCHEMA_NAME with 'test' match, but comparisons with 'TEST' do not:

  1. mysql> SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
  2.        WHERE SCHEMA_NAME = 'test';
  3. +-------------+
  4. | SCHEMA_NAME |
  5. +-------------+
  6. | test        |
  7. +-------------+
  8.  
  9. mysql> SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
  10.        WHERE SCHEMA_NAME = 'TEST';
  11. Empty set (0.00 sec)

These results occur with the lower_case_table_names system variable set to 0. A lower_case_table_names setting of 1 or 2 causes the second query to return the same (nonempty) result as the first query.

Note

It is prohibited to start the server with a lower_case_table_names setting that is different from the setting used when the server was initialized.

On Windows or macOS, file systems are not case-sensitive, so comparisons match both 'test' and 'TEST':

  1. mysql> SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
  2.        WHERE SCHEMA_NAME = 'test';
  3. +-------------+
  4. | SCHEMA_NAME |
  5. +-------------+
  6. | test        |
  7. +-------------+
  8.  
  9. mysql> SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
  10.        WHERE SCHEMA_NAME = 'TEST';
  11. +-------------+
  12. | SCHEMA_NAME |
  13. +-------------+
  14. | TEST        |
  15. +-------------+

The value of lower_case_table_names makes no difference in this context.

The preceding behavior occurs because the utf8_general_ci collation is not used for INFORMATION_SCHEMA queries when searching for values that correspond to objects represented in the file system.

If the result of a string operation on an INFORMATION_SCHEMA column differs from expectations, a workaround is to use an explicit COLLATE clause to force a suitable collation (see Section 10.8.1, “Using COLLATE in SQL Statements”). For example, to perform a case-insensitive search, use COLLATE with the INFORMATION_SCHEMA column name:

  1. mysql> SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
  2.        WHERE SCHEMA_NAME COLLATE utf8_general_ci = 'test';
  3. +-------------+
  4. | SCHEMA_NAME |
  5. +-------------+
  6. | test        |
  7. +-------------+
  8.  
  9. mysql> SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
  10.        WHERE SCHEMA_NAME COLLATE utf8_general_ci = 'TEST';
  11. +-------------+
  12. | SCHEMA_NAME |
  13. +-------------+
  14. | test        |
  15. +-------------+

You can also use the UPPER() or LOWER() function:

  1. WHERE UPPER(SCHEMA_NAME) = 'TEST'
  2. WHERE LOWER(SCHEMA_NAME) = 'test'

Although a case-insensitive comparison can be performed even on platforms with case-sensitive file systems, as just shown, it is not necessarily always the right thing to do. On such platforms, it is possible to have multiple objects with names that differ only in lettercase. For example, tables named city, CITY, and City can all exist simultaneously. Consider whether a search should match all such names or just one and write queries accordingly. The first of the following comparisons (with utf8_bin) is case sensitive; the others are not:

  1. WHERE TABLE_NAME COLLATE utf8_bin = 'City'
  2. WHERE TABLE_NAME COLLATE utf8_general_ci = 'city'
  3. WHERE UPPER(TABLE_NAME) = 'CITY'
  4. WHERE LOWER(TABLE_NAME) = 'city'

Searches in INFORMATION_SCHEMA string columns for values that refer to INFORMATION_SCHEMA itself do use the utf8_general_ci collation because INFORMATION_SCHEMA is a virtual database not represented in the file system. For example, comparisons with SCHEMATA.SCHEMA_NAME match 'information_schema' or 'INFORMATION_SCHEMA' regardless of platform:

  1. mysql> SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
  2.        WHERE SCHEMA_NAME = 'information_schema';
  3. +--------------------+
  4. | SCHEMA_NAME        |
  5. +--------------------+
  6. | information_schema |
  7. +--------------------+
  8.  
  9. mysql> SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
  10.        WHERE SCHEMA_NAME = 'INFORMATION_SCHEMA';
  11. +--------------------+
  12. | SCHEMA_NAME        |
  13. +--------------------+
  14. | information_schema |
  15. +--------------------+

Suchen Sie im MySQL-Handbuch

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 26/06/2006, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/mysql-rf-charset-collation-information-schema.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.

Referenzen

  1. Zeigen Sie - html-Dokument Sprache des Dokuments:en Manuel MySQL : https://dev.mysql.com/

Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.

Inhaltsverzeichnis Haut