Summary of operations related to tables and columns in mysql database:

Keywords: Database encoding MySQL SQL

1. Display table structure: desc or describe

describe test_collate;

2. Creation statement of display table: you can see the storage engine, encoding format and other information of table.

show create table test_collate;

3. Show the details of the data sheet as follows:

select * from information_schema.columns 
where table_schema = 'mydatabase' and table_name = 'test_collate';

You can also display the desired columns as follows:

select column_name, column_comment, data_type 
from information_schema.columns 
where table_schema ='mydatabase' and table_name = 'test_collate' ;

4. Display the storage engine and encoding format of the current table

show engines; -- View the provided storage engine
 Show variables like'% storage_engine%'; -- View mysql's current default storage engine

5. View the current version of the database:

select version();

6. View the relevant information of the tables in the database:

-- Specified table:
select * from information_schema.tables where table_schema = 'mydatabase' and table_name = 'test_collate';
-- Specify the database:
select * from information_schema.tables where table_schema = 'mydatabase';

For example:

-- View the self-increment of the specified table:
select auto_increment from information_schema.tables 
where table_schema = 'mydatabase' and table_name = 'test_collate';

-- View the character set of the specified table:
select auto_increment from information_schema.tables 
where table_schema = 'mydatabase' and table_name = 'test_collate';

7. In addition to setting the field name, type, default value and annotation in the table, the following parameters can be set when creating the table:
ENGINE Storage Engine
CHARSET Character Set
COLLATE Proofreading Set (Character Order)
COMMENT Notes

8. In addition to the annotations, the above parameters can adopt default values, in which the proofreading set refers to the sorting of characters. First of all, the characters are of no size, so the operation of >, =, <character needs a rule of character sorting. This is what collate does. You can set the character order of a table, or you can set the character order of a field separately.
The proofreading set has three formats
Binary: binary, take out binary bits, compare bit by bit, distinguish case from case
_ ca: case sensitive, case sensitive, case sensitive
_ ci: case insensitive, case insensitive, case insensitive
Such as:

CREATE TABLE `test_collate` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
  `name` varchar(100) COLLATE utf8mb4_0900_ai_ci COMMENT 'Name',
  PRIMARY KEY (`id`)
)COMMENT='Test Character Sequence Table';

Then the following query statement produces the same result:

select * from test_collate where name like '%yes%';

select * from test_collate where name like '%YEs%';

If we change the character order to utf8mb4_bin

alter table test_collate change name name varchar(100) COMMENT 'Full name' COLLATE utf8mb4_bin;

Continue with the above statement and you will find that the results are different:


9. View the encoding of the current database:

show variables like '%character%';


10. View the character order corresponding to the current database coding:

show variables like '%collation%';

11. View all coding sets supported by the database:

show character set;


12. View the proofreading set corresponding to the specified encoding set:

show collation where charset = 'utf8mb4';

13. Modify the default character set of the table:

alter table_name default character set character_name;
-- Such as:
alter test_collate default character set utf8mb4;

14. Modify the default character set of the table field:

alter table table_name change field field field_type character set character_name [other_attribute];
-- Such as:
alter table test_collate change name name varchar(100) character set utf8mb4;

15. Modify the default character set of the table and the character set of all columns:

alter table table_name convert to character set character_name;
-- Such as:
alter table test_collate convert to character set utf8mb4;

Unimplemented sql, please verify by yourselves, here are no longer listed one by one.


 

Posted by RonDahl on Sun, 20 Jan 2019 12:12:12 -0800