The third day of MySQL database learning from entry to mastery (view, select, modify, delete database)

View, select, modify, delete databases

view database

After creating the database, you can SHOWview all database information through commands, syntax:

SHOW DATABASES [LIKE %模式% WHERE 条件];>>>>>>> []is optional.

LIKE: For the specified matching mode, the format uses two %databases representing a format like this for matching.
WHERE: The condition used to specify the query scope of the database name.

For example, enter the following statement on the command line:

SHOW DATABASES;

The following 6 pieces of data can be queried, referring to the six databases.

insert image description here

Enter the following data to filter the database:

SHOW DATABASES LIKE "%db_%";

The returned result is a database, and db_the database name starting with is satisfied.

insert image description here

select database

After a database is created, it does not automatically become the current database. That is, the location is the scope of storing the entire database, and there is no scope under the database. If you need to switch to the specified database, you need to use USEa statement to make it the current library that needs to be operated. Only then can we perform operations on the database and the data objects it stores. grammar:

USE 数据库名;

For example, enter the following statement:

USE DB_STDUY;

At this time, the display Database changedindicates that you have switched to the specified database, that is, you can perform related operations on the current database.

insert image description here

modify database

We used to USEselect the database earlier, and here we can modify the database.

Note: The modification here refers to modifying the parameters of the data, and the database name cannot be modified.

grammar:

ALTER DATABASE [数据库名] DEFAULT CHARACTER SET {UTF-8 | GBK} DEFAULT COLLATE 校对规则名称;>>>>>>> []is optional, {}and is required.

[数据库名]: If the database to be modified is not specified, the current database will be modified by default.
DEFAULT: Specifies the default value for the parameter in the database.
CHARACTER: Specifies the character set of the database.
COLLATE: Collation rules for the specified character set.

For example, enter the following statement:

alter database db_stduy default character set gbk default collate gbk_chinese_ci;

Among them gbkis the default encoding format, gbk_chinese_ciwhich means that the collation rules of the character set are set to Simplified Chinese, that is, Simplified Chinese is used for input.

insert image description here

delete database

Use DROPthe statement to delete the database. When using this command to delete the database, all the data in the data will be permanently deleted, so special attention should be paid when using it to avoid accidental deletion.

grammar:

DROP DATABASE [IF EXISTS] 数据库名;

[IF EXISTS]: It is used to determine whether the database exists before deleting the database. Only if it exists, the deletion operation will be performed, which can avoid exceptions when deleting non-existing databases.

Note: When using DROP, the user must have the permission to delete the database, and when the database is deleted, the user permissions on the database will not be automatically deleted.

For example, enter the following statement:

DROP DATABASE IF EXISTS DB_STUDY;

The deletion can be done because the database named database exists DB_STDUY.

insert image description here

Guess you like

Origin blog.csdn.net/m0_67021058/article/details/130672092