The Road to Learning Linux (Basics (23)) MySQL Service (Part 2)

Table of contents

SQL statement of MySQL service

1. SQL statement types

1. DDL statement

2. DML statement

3. DCL statement

4. DQL statement

2. Database operations

1. View

2. Create

3. Enter

 4. Delete the database

5. Change the database name

6. Change character set

3. Data table management

1. Data type

1. Numeric type

TINYINT

SMALLINT

INT

BIGINT

FLOAT(M,D)

2. Time/date type

DATE

TIME

DATETIME

TIMESTAMP

3. String type

CHAR

VARCHAR

TEXT

4. Binary type

BINARY

VARBINARY

BLOB

2. View

View datasheet  

View datasheet contents

View data table properties

3. Create

4. Delete

5. Changes

Table name

table properties

Column name

Column properties

Column character set

4. Data operations

Add data

delete data

Change data

Find data

1. Conditional query

operator

sort query


SQL statement of MySQL service

        MQL (MetaQuotes Language) is a programming language specifically used for the MetaTrader trading platform. MetaTrader is a popular foreign exchange trading platform widely used in stocks, futures, and other financial markets. MQL statements are codes used to write automated trading strategies.

        MQL statements allow traders to write custom indicators and scripts to perform various operations such as market analysis, trading signal generation, order execution, and risk management. By using MQL statements, traders can automate their trading activities and execute trades automatically based on a predetermined set of rules.

        MQL statements are similar to other programming languages, with basic elements such as variables, functions, conditional statements, and loops. It also provides many trading-specific functions and instructions, such as getting market quotes, sending trading orders, and accessing historical data.

1. SQL statement types

1. DDL statement

        DDL (Data Definition Language): used to define various objects in the database, including databases, tables, views, triggers, etc.

        DDL instructions CREATE, ALTER, DROP

2. DML statement

        DML (Data Manipulation Language): used to operate data in tables to perform operations such as adding, querying, updating, and deleting.

        DML instructions SELECT, INSERT, UPDATE, DELETE

3. DCL statement

        DCL (Data Control Language): used to manage database permissions and security, including operations such as authorization and permission recovery.

         DCL commands GRANT, REVOKE

4. DQL statement

        DQL (Data Query Language) is a subset of SQL and is mainly used to query data in databases.

        DQL command SELECT

2. Database operations

1. View

        show databases;

2. Create

        create database database_name

3. Enter

        use   database_name

 4. Delete the database

        drop database database_name 

5. Change the database name

        cd /var/lib/mysql     

6. Change character set

 ALTER DATABASE <database_name>CHARACTERSETutf8mb4COLLATEutf8mb4_unicode_ci;

3. Data table management

1. Data type

1. Numeric type

TINYINT

        1 byte in the range -128 to 127 (signed) or 0 to 255 (unsigned)

        You can use TINYINT UNSIGNED to store decimal values ​​such as age (unsigned) or temperature (signed)

SMALLINT

        2 bytes in the range -32,768 to 32,767 (signed) or 0 to 65,535 (unsigned)

 You can use SMALLINT to store the product quantity, or use SMALLINT UNSIGNED to store the area number (unsigned)

INT

         4 bytes, ranging from -2,147,483,648 to 2,147,483,647 (signed) or 0 to 4,294,967,295 (unsigned)

        This is the most commonly used integer type. It can be used in many ways, such as storing order numbers or the number of users.

BIGINT

        8 bytes

        Store large values, such as funds, population, etc.

FLOAT(M,D)

        Single precision floating point number, M is the total number of digits, D is the number of decimal places

        You can use FLOAT(8,2) to store the price of the product

2. Time/date type

DATE

        Used to store dates in the format 'YYYY-MM-DD'

        You can use DATE to store birth date or expiration date, etc.

TIME

        Used to store time in the format 'HH:MM:SS'

        You can use TIME to store the number of hours, minutes or seconds spent in the past period, etc.

DATETIME

        Used to store date and time in the format 'YYYY-MM-DD HH:MM:SS'

        You can use DATETIME to store order time or statistical report generation time, etc.

TIMESTAMP

        Used to store date and time, usually used to record the timestamp of a specific event. Using UNIX date and time format, calculated from midnight on January 1, 1970

        You can use TIMESTAMP to store the timestamp of the user's last login

3. String type

CHAR

        Used to store fixed-length strings, with a maximum length of 255 characters

        You can use CHAR(10) to store the user's gender, marital status and other data

VARCHAR

        Used to store variable-length strings, with a maximum length of 65535 characters

        You can use VARCHAR(255) to store user-entered text content, addresses and other data

TEXT

        Used to store large character data, the maximum length is 2^16-1 characters

        You can use TEXT to store large text data such as articles and comments

4. Binary type

BINARY

        Used to store fixed-length binary data, with a maximum length of 255 bytes

        You can use BINARY(16) to store UUID

VARBINARY

        Used to store variable-length binary data, with a maximum length of 65535 bytes

        You can use VARBINARY(256) to store binary data of variable length, such as pictures and audio files.

BLOB

        Used to store large binary object data, with a maximum length of 2^16-1 bytes

        BLOB can be used to store media files such as audio and video

2. View

View datasheet  

        show tables;

View datasheet contents

        select * from tables_name;

View data table properties

        describe  table_ name;

        desc table _name;

3. Create

        create table tables_name (
            first column type attribute,
            second column type attribute,
            ...
        ) character set utf8mb4 collate utf8mb4_unicode_ci; (indicates that the entire data table is utf8 character set)

        create table tables_name(
            first column type attribute,
            second column type attribute character set utf8mb4 collate utf8mb4_unicode_ci,
        );

4. Delete

        drop table table_name

5. Changes

Table name

        alter table old_table_name rename to new_table_name;

table properties

        alter table table_name convert to character set utf8mb4 collate utf8mb4_unicode_ci;

Column name

        alter table table_name change old_name new_name 属性;

Column properties

        alter table my_table modify modified column modified attribute;

Column character set

        alter table  users modify name varchar(50) character set utf8mb4;

4. Data operations

Add data

        insert into table_name (column1, column2, ...) values (value1, value2, ...);

delete data

        delete from table_name where 条件;

Change data

        update table_name set column1 = value1, column2 = value2, ... where 条件;

Find data

        select * from tables_name;

        select column1,column2 from tables_name where 条件;

1. Conditional query

operator

        Equal =
        Not equal!= or <>
        Greater than >
        Greater than or equal >=
        Less than <
        Less than or equal to <=
        between BETWEEN operator is used to represent values ​​within a range, AND
        in IN operator is used to compare whether an expression is consistent with a group matches any one of the expressions

sort query

        Ascending (default) ASC
        Descending DESC        

        select * from test order by colume1;

         select * from test order by colume1 DESC, colume2 ASC;

Guess you like

Origin blog.csdn.net/a872182042/article/details/131924739
Recommended