MySql database basic operations

1.1 Basic operations of MySql database

First of all, the operation of MySql can be realized either through a graphical interface (such as Mysql workbench), or through the command line terminal input command line. When designing the data table structure, it is very convenient and fast to use the graphical interface, but when operating the database in the application program, it must be realized through the MySql statement. The command line operation of the database is to operate the database through MySql, so when developing the application program of the database, this is the must master.

Taking windows as an example, first log in to the MySql database.

1.1.1 Create a database

The syntax is as follows:

CREATE DATABASE database name;

The general specification of MySql statements is that commands are in uppercase letters (of course, lowercase can also be recognized), and variable names are represented in lowercase. The final statement ends with a semicolon.

Example: Create a database named db_admin

CREATE  DATABASE db_admin;

After the creation is successful, the output is as shown in the following figure.

1.1.2 View database list

The syntax is as follows:

SHOW  DATABASES ;


or SHOW SCHEMAS;


1.1.3 Select database

The syntax is as follows:

USE database name ;

Even though the previous statement created the database db_admin , it does not mean that the current operating database is db_admin . Use the USE statement to select a database to be the current default database.

Example: select db_admin


1.1.4 Delete the database

The syntax is as follows: DROP DATABASE database name;

Use this operation with caution. Once this operation is performed, all structures and data of the database will be deleted, and there is no possibility of recovery. Unless the database is backed up.

Example: Delete the db_admin database


1.1.5 Summary

 The commonly used statements for database operations are the above. Let’s learn how to operate data tables in the next blog.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325432675&siteId=291194637