1. View the database encoding format
0./**-All rights-**/
GRANT all on Epet to ' epetadmin ' @localhost identified by ' 1234 ';
Mysql> Show variables like ' character_set_database ';
2. View the encoding format of the data table
Mysql> Show CREATE table < table name >;
3. Specify the character set of the database when creating the database
Mysql>create databases < database name > character set UTF8;
4. Specify the encoding format of the data table when creating the data table
CREATE TABLE Tb_books (
Name varchar () is not NULL,
Price double is not NULL,
Bookcount int NOT NULL,
Author varchar () NOT NULL) default CharSet = UTF8;
5. Modify the encoding format of the database
Mysql>alter databases < database name > character set UTF8;
6. Modify the data table encoding format
Mysql>alter Table < name > character set UTF8;
7. Modify the field encoding format
Mysql>alter Table < name > Change < Field name > < Field name > < type > Character set UTF8;
Mysql>alter Table User change username username varchar character set UTF8 NOT null;
8. Add a FOREIGN key
Mysql>alter table tb_product Add constraint fk_1 foreign key (Factoryid) references tb_factory (Factoryid);
Mysql>alter table < table name > Add constraint < foreign key name > Foreign key< Field name > REFERENCES < outer table name >< field name >;
9. Delete foreign keys
Mysql>alter table tb_people drop foreign key fk_1;
Mysql>alter table < table name > drop FOREIGN Key < foreign key name >;
10. Query the new self-increment subscript
SELECT @ @IDENTITY
MySQL database basic use