MySQL-basic operation of the database

Create and view databases

To create a database is to divide a storage space in the database system. The syntax format is as follows:

CREATE DATABASE 数据库名称;

It should be noted that the database name is unique and cannot be repeated.

Create a database named text, the syntax format is as follows:

CREATE DATABASE text;

Execution result: To
Insert picture description here
verify whether the database named text is successfully created, you need to check the database. The syntax format is as follows:

SHOW DATABASES;

Viewed all existing databases, the execution result:
Insert picture description here
the text database just created already exists, and the user can also view the database information that has been created, the syntax format is as follows:

SHOW CREATE DATABASE 数据库名称;

Query the database information of text, the execution result: The
Insert picture description here
execution result shows the creation information of the database text, such as the name of the database-text and the code of the database-utf8. If you want other codes, you can specify the code of the database when you create the database. The syntax format is as follows:

 CREATE DATABASE 数据库名称 CHARACTER SET 编码方式(如:utf8);

Use database

After the database is created, if you want to operate in this database, you need to switch to this database. Use SELECT database();to check which database is currently in use.
Insert picture description here
NULL shows that I am not currently using the database, switch to the database syntax format is as follows:

USE 数据库名称;

Use the text database, and check whether the currently used database is text, the execution result:
Insert picture description here
you can see that the database used at this time is text.

Modify the database

After the database is created, it is found that the encoding type is not utf8. If you want to modify the encoding of the database, you can use a ALTER DATABASEstatement to achieve it. The specific syntax format is as follows:

ALTER DATABASE 数据库名称 DEFAULT CHARACTER SET 编码方式 COLLATE 编码方式_bin;

Delete database

Deleting a database is to delete an existing database in the system. After deletion, all data in the database will be cleared, and the allocated space will be recovered. The syntax format is as follows:

DROP DATABASE 数据库名称;

Delete the text database and check whether it is successful. Execution result: The
Insert picture description here
database named text no longer exists in the database system.

Guess you like

Origin blog.csdn.net/javanofa/article/details/107181331