【MySQL】Basic use of database

1. Database Introduction

MySQL is essentially a network service based on the C(mysql)S(mysqld) model.
It is a set of network programs that provide data access services.

  • mysqld: the server side of the database (d means daemon process)

  • mysql: the client side of the database

Databases are structured data files stored on disk or in memory.

  • Why not use general file storage?

Files can indeed be stored, but it does not provide better data management capabilities from the user's perspective. (For example, find the ip address starting with 120 in the file)
And if it is a database, it has a set of solutions for data content storage, we submit fields or requests, and the database returns the results.

insert image description here

2. Database usage

2.1 Login to MySQL

mysql -h 127.0.0.1 -P 3306 -u root -p

-h: Specify the host name or IP address where MySQL is deployed . Here, 127.0.0.1 means that the host to be connected is the local host, that is, to connect to the MySQL database on the local machine. If -h is not specified, it will connect to the MySQL built on the local server by default. : Specify the port number
-P of the MySQL database to be connected . Here, 3306 represents the default port number of MySQL database. If -P is not specified, the port number specified in the configuration file is used to connect to MySQL by default. : Specify the user name to connect to the MySQL database . Here, root means to use the root user name to connect to the MySQL database. : Indicates that a password is required when connecting to the MySQL database . Here, no password is specified after -p, so a password is prompted.
-u
-p

2.2 Basic use

2.2.1 Display a list of all databases in the current MySQL instance

show databases;

insert image description here

2.2.2 Create a database

create database test;

insert image description here

The database is stored /var/lib/mysqlin the directory. Check:

insert image description here
Creating a database is essentially creating a directory under Linux.

2.2.3 Create database tables

You can see that there are many databases, so choose one of them first:

use test;

insert image description here
Then you can create the database table:

mysql> create table person(
    -> name varchar(32),
    -> age int,
    -> gender varchar(2)
    -> );

insert image description here
Creating a table in the database is essentially creating a corresponding file in Linux.
insert image description here

2.2.4 Insert data into the table

insert into person (name, age, gender) values ('张三', '20', '男');

insert image description here

2.2.5 Query data in the table

select* from person;

insert image description here
The essence of the database is actually a file, but these files are not directly operated by the programmer, but are operated by the database service for us

3. The relationship between server, database and table

In fact, installing the database server (mysqld) is to install a database management application program on Linux and run it as a daemon process in the background. This program can manage multiple databases (tables) at once:

insert image description here

Four, SQL statement classification

There are three types of SQL statements:

DDL data definition language is naturally used to maintain the structure of stored data , representing instructions: create, drop, alter, operation table
DML data manipulation language, used to operate data , representing instructions: insert, delete, , and a separate one in updatathe operation data DML
DQL, data query language, representing instructions: select
DCL data control language, mainly responsible for authority management and transactions , representing instructions: grant, revoke,commit

5. Storage engine

Storage engine: the implementation method
of how the database management system stores data, how to index the stored data, and how to update and query data . That is, the program that really deals with the operating system.

Search engine:

show engines;

insert image description here
The core of MySQL is the plug-in storage engine, which supports multiple storage engines. The
most commonly used storage engine is InnoDB, and
the default storage engine of MyISAM is InnoDB.

Guess you like

Origin blog.csdn.net/qq_66314292/article/details/132028668