Home > Database > Mysql Tutorial > A brief discussion on MySQL drifting (4)

A brief discussion on MySQL drifting (4)

黄舟
Release: 2017-03-08 13:27:31
Original
1204 people have browsed it

Before reading Code_Xiaosheng’s MySQL Drifting Notes IV, I hope that if you have time, you can briefly read MySQL Drifting Notes (1), MySQL Drifting Notes (2) and MySQL Drifting Notes (3)!

PS: The fourth section should be regarded as a small supplement to the database-related operations and the previously created database!

1) Create a database:
Use if exists to determine whether it already exists. If it does not exist, it will be created. If it already exists, it will not be created and no error will be reported. If it is not used, create it again. Databases with the same name will report an error!

Case: create database if not exists new08;
Copy after login
Copy after login

A brief discussion on MySQL drifting (4)

2) Display database:
show command, display the built database

Case: show databases;
Copy after login
Copy after login


You can see all the built databases;
If I want to fuzzy query the database starting with "new..", I can use the like keyword:

Case: show databases like ‘new%’
Copy after login
Copy after login

Notes:
01–% is a wildcard character, representing one or more characters;
02–_underscore is a wildcard character, representing one character;
03–When using the show command, remember that the following databases are in plural form. I saw a post on the Internet last time. A friend struggled with writing "s" for a long time. Ahem...

3) Select database
Syntax:

use +database 
Case: use new01;
Copy after login
Copy after login

A line 'Database changed' will appear ' Friendly reminder;
A brief discussion on MySQL drifting (4)

4) Delete the database
Use the drop command
Syntax:

drop  database +数据库名字; 
Case: drop database new01;
Copy after login
Copy after login

Pay attention to the if exists command;

Case:drop database  if exists new04;
Copy after login
Copy after login

The advantage of adding if exists is to avoid the new04 database not existing and then reporting an error message.
A brief discussion on MySQL drifting (4)

Before reading Code_Xiaosheng's MySQL Drifting Notes IV, I hope that if you have time, you can briefly take a look at MySQL Drifting Notes (1), MySQL Drifting Notes (2) and MySQL Drifting Notes (3)!

PS: The fourth section should be regarded as a small supplement to the related operations of the database and the previously created database!

1) Create a database:
Use if exists to determine whether it already exists. If it does not exist, it will be created. If it already exists, it will not be created and no error will be reported. If it is not used, create it again. Databases with the same name will report an error!

Case: create database if not exists new08;
Copy after login
Copy after login

A brief discussion on MySQL drifting (4)

2) Display database:
show command, display the built database

Case: show databases;
Copy after login
Copy after login

Yes See all the built databases;
If I want to fuzzy query the database starting with "new..", I can use the like keyword:

Case: show databases like ‘new%’
Copy after login
Copy after login

Notes:
01 –% is a wildcard character, representing one or more characters;
02–_Underscore is a wildcard character, representing one character;
03–When using the show command, remember that the following databases are in plural form. Last time I saw it online When I came to a post, a friend was struggling for a long time to write "s", cough...

3) Select database
syntax:

use +database 
Case: use new01;
Copy after login
Copy after login

will appear a line of 'Database changed' Tips;
A brief discussion on MySQL drifting (4)

4) Delete the database
Use the drop command
Syntax:

drop  database +数据库名字; 
Case: drop database new01;
Copy after login
Copy after login

Pay attention to the if exists command;

Case:drop database  if exists new04;
Copy after login
Copy after login

The advantage of adding if exists is to avoid the new04 database not existing and then reporting an error message,
A brief discussion on MySQL drifting (4)


The above is the detailed content of A brief discussion on MySQL drifting (4). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template