This article mainly introduces the summary of common commands for MySQL database operations, such as creating a database, using a database, viewing a database, and operating database encoding. For more information, see create a database.
The simplest method:
The code is as follows:
Create database my_db;
Or:
The code is as follows:
Create database if not exists my_db;
Create a utf8-encoded database:
The code is as follows:
Create database if not exists my_db default character set utf8 COLLATE utf8_general_ci;
The default character set of all data tables created in this database will be utf8. pay attention to the following sentence: "COLLATE utf8_general_ci", which roughly means sorting based on utf8 variable code format during sorting.
View the database list:
The code is as follows:
Show databases;
Database usage:
The code is as follows:
Use my_db;
View the default database encoding:
The code is as follows:
Show variables like 'character _ set _ %'
+ -------------------------- + ------------------------------------------------------- +
| Variable_name | Value |
+ -------------------------- + ------------------------------------------------------- +
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | latin1 |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | latin1 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/local/mysql-5.5.28-linux2.6-i686/share/charsets/|
+ -------------------------- + ------------------------------------------------------- +
The character_set_database is lantin1.
Modify the database code:
The code is as follows:
Alter database my_db character set latin1;
Delete database:
The code is as follows:
Drop database my_db;
Or:
The code is as follows:
Drop database if exists my_db;