A, SQL character set
It is a collection of all the abstract characters supported by the system. Character is the general term for a variety of text and symbols, including text countries, punctuation marks, graphic symbols, numbers, etc.
Commonly used character set: utf8, utf8mb4, utf8mb3 (8.0), is now recommended utf8mb4 character set support richer. It is an internal database storage format
Note: To ensure that all the characters are the same, otherwise they will be garbled
1.1 CentOS7 operating system language
-- 查看现在使用的语言 # echo $LANG en_US.UTF-8 # locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= -- 临时修改 LANG="zh_CN.UTF-8" #修改为中文 LANG="en_US.UTF-8 "# amended as English - to permanently modify the CAT / etc / locale.conf LANG = " en_US.UTF - 8 "
1.2 MySQL instance level
A. plus specified at compile time parameters
cmake . -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \
B. Non compile and install (previous version 5.6) to modify my.cnf configuration file, the default is Latin character set
[mysqld] character-set-server=utf8
1.3 database level
The CREATE DATABASE `wp` the DEFAULT CHARACTER the SET utf8 the DEFAULT COLLATE = utf8_general_ci; - the CREATE DATABASE` wp`: representatives is to create a database WP - the DEFAULT CHARACTER the SET utf8: represents the default encoding format is set to utf8 database format - - the COLLATE utf8_general_ci: represents the database collation, the utf8_bin each character string with binary data, case sensitive. utf8_genera_ci case insensitive, CI is an abbreviation for case insensitive, i.e., case-insensitive. utf8_general_cs case-sensitive, the abbreviation CS is case sensitive, i.e. case sensitive
1.4 MySQL client level
- provided at the connection mysql mysql > SET names UTF8; - modify my.cnf achieve [ Client ] default - Character - SET = UTF8
1.5 Table Level
CREATE TABLE test ( id int(4) NOT NULL auto_increment, name char(20) NOT NULL, PRIMARY KEY id, )ENGINE=INNODB auto_increment=13 DEFAULT CHARSET(=utf8);
1.6 production environment and change the database character set table method
Note: When you change the character set, be sure to protect from small to big change, which must be a strict superset of the former. Do not modify the production.
ALTER DATABASE wp CHARACTER set utf8 COLLATE utf8_general_ci; alter table t1 CHARACTER SET utf8;
Two, information_schema obtain metadata
Information_schema query the database table that contains all the relevant data objects managed by the MySQL database server.
MySQL > use information_schema; - see Table Structure MySQL > DESC TABLES; - some common columns TABLE_SCHEMA: library table where TABLE_NAME: name of the table ENGINE: Table engines Table_rous: tables of data rows Data_length + Index_length: space usage statistics Happening
Through the information schema commonly used queries
- The number count table of statistics for all library () the SELECT table_schema, count (table_name) the FROM TABLES the GROUP BY table_schema; - show the information in all the libraries of all tables: the SELECT table_schema, table_name from the Tables; - View webdb BANK view information SELECT TABLE_SCHEMA, table_name, TABLE_TYPE from tables WHERE TABLE_SCHEMA = ' WebDB ' and TABLE_TYPE = ' view ' ; - statistical database tables for all engines innodb the SELECT the TABLE_SCHEMA, tABLE_NAME, eNGINEThe FROM TABLES the WHERE Engine = ' InnoDB ' ; - number of rows in the core business of database statistics for all tables, statistical information should be carried out every day. The SELECT the TABLE_SCHEMA, TABLE_NAME, TABLE_ROWS the FROM `TABLES` the WHERE the TABLE_SCHEMA the IN ( ' MySQL ' , ' WebDB ' ) the ORDER BY TABLE_ROWS DESC ; - the amount of statistical data for each database, MB units of the SELECT the TABLE_SCHEMA, SUM ( ' DATA_LENGTH ' + ' Index_length ' )/ 1024 / 1024 the FROM TABLES the GROUP BY TABLE_SCHEMA; - total accounts for spatial statistical database of the SELECT SUM (data_length + Index_length) / 1024 / 1024 the FROM the Tables; - add a line in the configuration file /etc/my.cnf, a secure export route vim # / etc / my.cnf Secure - File - PRIV = / Backup # / etc / init.d / mysqld restart # mkdir / Backup Chown mysql.mysql # / Backup - Use concat command to bulk raw ingredients library sub-table command to back up the SELECT CONCAT ( "mysqldump - -uroot - p123456", TABLE_SCHEMA, "", TABLE_NAME, " > / Backup / ", TABLE_SCHEMA, " . _ ", TABLE_NAME," SQL ") the FROM tABLES the INTO the OUTFILE ' /backup/bak.sh ' - Specifies webdb sub-library library sub-table command splicing the SELECT CONCAT (" the mysqldump - -uroot - p123456 ", the TABLE_SCHEMA," " , TABLE_NAME, " > / Backup / ", TABLE_SCHEMA, "_", TABLE_NAME,. "sql") FROM TABLES WHERETABLE_SCHEMA = ' WebDB ' INTO OUTFILE ' /backup/bak.sh ' - direct sh to run after the export file.