2024 MySQL Study Guide (1), explore the MySQL database and grasp future data management trends

Preface

这是一篇 MySQL 通关一篇过硬核The original intention of organizing experience learning routes,包括数据库相关知识,SQL语句的使用,数据库约束,设计等。 is to record one's own growth and at the same time help friends who need to learn and review.

1. Database related concepts

1.1 Data

数据It refers to the basic objects stored in the database and is a symbolic record that describes things.

1.2 Database

数据库It refers to a warehouse for storing data, an organized and shareable collection of data stored in a computer for a long time.

Insert image description here

Database technology solves the problem of persistent storage of data, and at the same time uses database management systems to solve the problem of tedious operations on large amounts of data.

1.3 Database management system

数据库管理系统It refers to a layer of data management software located between the user and the operating system, scientific organization and storage, and efficient acquisition and maintenance.

Insert image description here

What we call MySQL database refers to the MySQL database management system, which is called MySQL database in everyone's daily usage habits. After installing the database management system software on our computer, we can create a database to manage data. At the same time, we can also add, delete, modify, and check the data in the database.

1.4 Database system

Databases, database management systems, applications and database administrators collectively make up the database 数据库系统.

1.5 SQL

SQL in English is Structured Query Language, or SQL for short. It is a structured query language for operating relational databases. The operations we often use when operating databases are query operations.

SQL定义了操作所有关系型数据库的统一标准, you can use SQL to operate all relational database management systems. When using other database management systems, you can also use SQL to operate.

2. MySQL database

2.1 MySQL installation

There are many installation methods for MySQL. You can use the green version here to avoid some tedious operations of the installation version. Directly download the compressed file of the version corresponding to your computer from the official website , and then decompress the compressed file into a non-Chinese directory. .

Insert image description here
The product version chosen to download here is 5.7.24because each library has the most complete support and is more stable than the latest version.

2.2 MySQL configuration

2.2.1 Add environment variables

Insert image description here

Right-click this computer/Properties/Advanced System Settings/Environment Variables, create a new variable in System Variables, name it MYSQL_HOME, and the variable value is the storage path of MySQL just now.

Double-click Path in the system variable, the value is %MySQL_HOME%\bin. The method of adding environment variables is roughly the same as learning to configure Java environment variables previously.

So, why do we need to configure environment variables first?

Usually, when we enter a command for an executable program in the command line window, Windows will first Pathsearch in the path pointed to in the environment variable. If it is found, it will be executed directly. If it is not found, it will be searched in the current working directory. If it is not found, it will be searched in the current working directory. If it is not found, an error will be reported.

The purpose of adding environment variables is to be able to run programs configured with environment variables in any path without always modifying the working directory, which greatly simplifies the operation.

How do we verify that adding environment variables is successful?

At this point, we only need to run the command prompt tool as an administrator and execute mysql. If prompted Can't connect to MySQL server on 'localhost', the environment variable is added successfully.

Note: You must run the command prompt tool as an administrator at this time, otherwise an error will be reported.

2.2.2 Create a new configuration file

Create a configuration file in the root directory of MySQl my.iniwith the following content:

[mysql]
default-character-set=utf8

[mysqld]
character-set-server=utf8
default-storage-engine=INNODB
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

The main purpose is to configure the default encoding set of the database utf-8and the default storage engine INNODB.

2.2.3 Initialize MySQL

Run in the command prompt window mysqld --initialize-insecure. If no error occurs, it proves that the data directory is initialized successfully.

mysqld --initialize-insecure

At this time, when we open and view the MySQL directory, dataa directory has been generated.

2.2.4 Register MySQL service

Run it in the command prompt window mysqld -install. At this time, your computer has successfully registered the MySQL service. At this time, your computer can be called a MySQL server.

mysqld -install

2.2.5 Start the MySQL service

Run in the command prompt window net start mysql. At this time, we have successfully started the MySQL service.

net start mysql

Run net stop mysqlto stop the MySQL service.

net stop mysql

You can modify the default account password by running mysqladmin -u root password 1234, which 1234refers to the password of the default administrator (i.e. root account).

mysqladmin -u root password 1234

2.3 MySQL login and logout

Run in the command line mysql -uroot -p, enter the password as prompted, and the login is successful.

mysql -uroot -p密码

Parameters in the login command:

mysql -u用户名 -p密码 -h要连接的mysql服务器的ip地址(默认127.0.0.1) -P端口号(默认3306)

When exiting MySQL:

exit
quit

2.4 MySQL uninstallation

We only need three simple steps to complete the uninstallation of MySQL:

Step 1: Runnet stop mysql

net stop mysql

Step 2: Runmysqld -remove mysql

mysqld -remove mysql

Step 3: Delete the MySQL directory and related environment variables.

2.5 MySQL data model

MySQl 是一个关系型数据库. A relational database is a database based on a relational model. Simply put, a relational database is a database composed of multiple two-dimensional tables that can be connected to each other.

Corresponding to relational databases are non-relational databases. Relational databases have many advantages. For example, they all use table structures, have consistent formats, and are easy to maintain. Use the common SQL language to operate, which is convenient and fast, and can be used for complex queries, etc.

image-20230118150205180

Through the client, we can use the database management system to create a database, create a table in the database, and add data to the table. Each database created corresponds to a folder on the disk, and multiple tables can be created under one database. The .frm in the folder is the table file, and .MYD is the data file. You can query it through these two files. The effect of displaying data into a two-dimensional table.

3.SQL statement

3.1 Introduction to SQL

SQL is called a structured query language and can be used to operate all relational databases. That is, we can add, delete, modify, and query databases, tables, and data through SQL statements.

SQL defines a unified standard for operating relational databases. However, for the same requirement, each database operation method may have some differences.

3.2 General grammar

Insert image description here

The SQL statements of the MySQL database are not case-sensitive, and it is recommended to use uppercase letters for keywords.

SQL statements can be written on a single line or on multiple lines, ending with a semicolon.

Note:

  1. Single line comment: – comment content or #comment content (MySQL specific)

  2. Multi-line comments: /* comments*/

3.3 SQL classification

Insert image description here

DDL: Data Definition Language , used to define database objects: databases, tables, columns, etc.

DML: Data manipulation language , used to add, delete, and modify data in tables in the database

DQL: Data query language , used to query records (data) in tables in the database

DCL: Data Control Language , used to define database access permissions and security levels, and create users

Data is a very important part of the database, so in future operations we most often perform some operations on the data, that is, how to delete, modify and check the data, so the most commonly used operations are DMLand DQL.

In general, DML is used to add, delete, and modify data, DQL is used to query data, DDL is used to operate the database, and DCL is used to control permissions. The basic operations of SQL generally refer to the addition, deletion, modification and query of databases, data tables, and data.

Guess you like

Origin blog.csdn.net/zhangxia_/article/details/135276181