MySQL database foundation (1): database installation and DataGrip installation

learning catalog

  • Database introduction

  • MySQL database installation and use

  • SQL statement

  • DDL database operation

  • DDL table operation

  • DML database operation language

  • SQL constraints

  • DQL operation

  • multi-table operation

learning target

  • Master DDL operations

  • Understand the constraints of mysql

  • Master DML operations

  • Master DQL operations

  • Master multi-table joint query

1. Database overview

1. Database introduction

A database is a warehouse for storing data. It is essentially a file system that stores data in a specific format. Users can add, modify, delete and query data in the database. With the rapid development of the Internet, a large amount of data is constantly being generated, accompanied by how to store and process data efficiently and safely, and this problem has become a very big problem in the information age, and the use of databases can efficiently organized data storage.

  • A large amount of data can be stored in a structured manner;

  • Can effectively maintain data consistency and integrity;

  • The reading and writing efficiency is extremely high.

2. Database classification

Databases are divided into relational databases and non-relational databases

☆ relational database

Relational database: refers to a database that uses a relational model to organize data.

The relational model refers to the two-dimensional table model, and a relational database is a data organization composed of two-dimensional tables and the connections between them. At the beginning stage, we can simply understand the relational database as an Excel table:

☆ Non-relational database NoSQL

Non-relational database: also known as NoSQL (Not Only SQL), meaning not just SQL, the most common definition of NoSQL is "non-associated", emphasizing the Key-Value way of storing data.

Key-value structure storage: Key-value database is a database that stores data in key-value pairs, similar to the map in Java. The entire database can be understood as a large map, and each key corresponds to a unique value.

What is the difference between relational and non-relational databases? Relational database (RDBMS):

1. Data is stored in the form of tables, each table contains multiple rows and columns, each row represents a record, and each column represents an attribute.

2. The data can be queried and manipulated through the SQL language to establish an association relationship through the primary key and the foreign key.

3. The data structure is strict, and the structure and relationship of the table need to be defined in advance, with high data consistency and integrity.

4. Suitable for applications that require complex queries and transaction processing, such as financial systems and enterprise management systems.

Non-relational databases (NoSQL):

1. Data is stored in non-tabular forms such as key-value pairs, documents, and column families. There is no fixed structure, and fields can be added dynamically.

2. There is no strict relationship between data, and the query method is usually a fast search through keys or indexes.

3. The data structure is flexible, can store semi-structured and unstructured data, and is suitable for large-scale data storage and processing.

4. Suitable for applications requiring high scalability and high performance, such as big data analysis and real-time data processing.

3. Common database introduction

☆ relational database

database

introduce

MySQL

Open source free database, medium-sized database. It has been acquired by Oracle. MySQL6.x version also starts to charge.

Oracle

Charged large database, Oracle's products. Oracle acquired SUN and acquired MYSQL.

DB2

IBM's database products are charged. Often used in banking systems.

SQLserver

A medium-sized database charged by Microsoft Corporation. C#, .net and other languages ​​are often used.

SQLite

Embedded small database, applied on the mobile phone.

☆ Non-relational database

database

introduce

Redis

It is a small and beautiful database, mainly used in key-value memory cache, with excellent read and write performance

HBase

HBase is a columnar database, the goal is to efficiently store large amounts of data

MongoDB

MongoDB is a document database, very close to a relational database.

4. Summary

① The database is the warehouse for storing data. Users can add, delete, modify and query the data in the database

② Databases are divided into relational databases and non-relational databases.

③ Commonly used relational databases are: MySQL, Oracle, DB2, SQLserver, sqlite

④ Commonly used non-relational databases are: Redis, Hbase, MongoDB

2. MySQL database

1. Introduction to MySQL

MySQL is a relational database management system. In terms of WEB applications, MySQL is the best RDBMS (Relational Database Management System, relational database management system) application software. It is developed by the Swedish MySQL AB company and is currently a product of Oracle. MySQL It is one of the most popular relational database management systems.

2. Features of MySQL

MySQL is open source, so you don't need to pay extra.

MySQL supports large databases. Can handle large databases with tens of millions of records.

MySQL uses standard SQL data language forms.

MySQL can be installed on different operating systems and provides operation interfaces in multiple programming languages. These programming languages ​​include C, C++, Python, Java, Ruby, and more.

3. MySQL version

MySQL Community Server: Community version, open source and free, but does not provide official technical support.

MySQL Enterprise Edition: The enterprise version requires payment and can be tried for 30 days.

MySQL Cluster: cluster version, open source and free. Several MySQL Servers can be packaged into one Server.

MySQL Cluster CGE: Advanced Cluster Edition, paid.

MySQL Workbench (GUITOOL): An ER/database modeling tool designed for MySQL. It is the successor of the famous database design tool DBDesigner4. MySQL Workbench is divided into two versions, namely the community version (MySQL Workbench OSS) and the commercial version (MySQL WorkbenchSE).

In this course, we use MySQL8.0 version, MySQL Community Server for learning.

4. MySQL database download and installation

☆ download

MySQL is open source and free. You can go directly to the official website to download the latest version of MySQL. The download address is as follows:

Download address: https://dev.mysql.com/downloads/mysql/, scroll down and select Windows system.

It is recommended to select the installation version to install, and click Go to Download Page to install.

After clicking Download, it will jump to the following page, click No thanks, just start my download. in the lower left corner to start downloading.

☆ install

After the download is complete, open the installation package, wait for a while, select the developer's default installation method, and click Next.

After that, you can install it according to the process. When you encounter Next (next step), click Execute (execute) directly. After clicking Execute, you need to wait for a few minutes.

Enter the database password until Account and Roles appears. Be sure to remember the password entered here for later login to the database.

Continue to click Next, and click Finish when it appears to complete the installation.

Note: MySQL software has a default administrator called root

5. Add environment variables (Windows)

cmd (DOS window) => enter commands such as mysql => find in the environment variables of the current Windows

The purpose of adding environment variables: When entering a terminal command, you can search for the corresponding executable file.

First find the mysql installation directory, locate the mysql file, and copy the contents of the address bar.

Default installation path: C:\Program Files\MySQL\MySQL Server 8.0\bin

Find this computer, right-click and select Properties, the following interface pops up, select Advanced System Settings, the location of the system may be different in different versions, please search patiently.

After entering the advanced system settings, click the environment variable button to enter the environment variable configuration interface.

Find the path variable in the system variables, click Edit to enter the editing interface.

Select New, paste the address of the assigned mysql file into the text box, and click OK to complete the environment variable configuration.

6. Check whether the environment variable is configured successfully

Type cmd in the search bar at the bottom and press Enter to bring up the terminal window.

Enter mysql -V (V should be capitalized), and the configuration is successful if the output is as follows.

3. MySQL installation and use under Linux system

1. MySQL installation and use

Mysql has been installed in the Linux system provided by the course, you can use it directly without installation

Please check the installation documentation: MySQL8.0 Installation.docx

2. Log in to the MySQL database

MySQL is a database that requires an account name and password to log in. It is used after login. It provides a default root account, which can be logged in with the password set during installation. There are currently two login scenarios:

☆ Local (for local MySQL)

 
 
 
 

# mysql -uroot –p Enter
password: Enter password 1

Case presentation:

Note: -u is followed by the login user name -p is followed by the login password, if you do not fill in, you will be prompted to enter the password after pressing Enter

☆ Remote (for remote MySQL, the MySQL server is no longer local)

 
 
 
 

# mysql -h remote server IP address -P port number -u username -p Enter
password: enter password


Case:
# mysql -h 192.168.88.100 -P 3306 -uroot -p
Enter password:123456

☆ exit

 
 
 
 

① mysql> exit
② mysql> quit
③ shortcut key Ctrl + d

3. Summary

① MySQL features: free, support large databases, standard SQL language form, cross-platform.

② The version used in the course is MySQL8.0.

③ Two ways to log in to MySQL:

Method 1: Local mysql -uroot -p123456

Method 2: remote mysql -h 192.168.88.100 -P 3306 -uroot -p123456

④ There are 3 ways to exit from the MySQL software

Method 1: exit

Method 2: quit

Method 3: Ctrl + d

4. MySQL graphical development tool DataGrip

1. Introduction to DataGrip

DataGrip is a database management product launched by JetBrains. It is very powerful and compatible with various databases. In addition, JetBrains also has a well-known IDE development tool IDEA, which has a very good user experience.

Download address: https://www.jetbrains.com/datagrip/download/#section=windows

2. DataGrip installation

After the download is complete, open the installer, select the installation path, and click Next to install. Click until Finish to complete the installation and open the application. Choose Evaluate for free for a 30-day free trial.

3. Create a project

Click File->New->Project to create a new DataGrip project, enter the project name, and click OK. Choose how to open the new project: This Windows (open in this window), New Windows (open in a new window), Attach (additional mode)

4. Connect to the database

Select ➕ under Database, and click MySQL under the DataSource menu. Fill in the corresponding parameters to connect to the database: connection name, IP, user name, password, etc., and click OK to complete the connection. Note: If you use it for the first time, you need to download the mysql driver file.

Set the database time zone:

  1. Click the Advanced button;

  2. Write -Duser.timezone=Asia/Shanghai after VM options, and it will be fine;

After the setting is complete, click Apply, click OK, and the database is successfully connected!

5. Select the database to use

Click the button after the connection name to select the database to use:

6. DataGrip software settings

☆ Set font size

Set text size: File--->settings--->Editor---->Font

☆ set keyword capitalization

Set keyword capitalization: File--->settings--->Editor---->Code Style--->SQL--->MySql (database that needs to be set)--->Case

☆ Automatic typesetting

Automatic typesetting layout: File--->settings--->Editor---->Code Style--->SQL--->MySql (database that needs to be set)--->Queries

Auto typesetting shortcut key: Ctrl+ Alt + L

Five, SQL statement

1. Connect to the database

Structured Query Language (Structured Query Language), referred to as SQL, is a specification that all relational database management systems need to follow, and it is a statement recognized by the database. Different database manufacturers support SQL statements, but all have unique content.

Example:

Mandarin: The ISO standard that all database vendors follow.

Dialect: A database-specific keyword.

2. Classification of SQL statements

☆ DDL

Data Definition Language: DDL (Data Definition Language) for short is used to define database objects: databases, tables, columns, etc. Keywords: create, alter, drop, etc.

☆ DML

Data Manipulation Language: DML (Data Manipulation Language) for short is used to update the records in the table in the database. Keywords: insert, delete, update, etc.

☆ DQL

Data Query Language: DQL (Data Query Language) for short is used to query the records in the tables in the database. Keywords: select, from, where, etc.

☆ DCL

Data Control Language: DCL (Data Control Language) for short is used to define the access authority and security level of the database, and to create users.

3. Basic syntax of SQL

① SQL statements can be written in one line or multiple lines, ending with a semicolon.

 
 
 
 

select * from students;

② Spaces and indentation can be used to enhance the readability of the statement

 
 
 
 

select
*
from students;

③ The SQL statement of the MySQL database is not case-sensitive, and it is recommended to use capital letters for keywords

 
 
 
 

SELECT * FROM user;
is equivalent to
select * from user;

④ You can use single-line and multi-line comments

 
 
 
 

# Single-line comment
-- single-line comment, note: -- there is a space after
--/*
...
multi-line comment
...
*/

4. Summary

Structured Query Language (SQL) is a specification that all relational database management systems need to follow. Different database manufacturers support SQL statements, but all have unique content.

SQL statements are divided into: Data Definition Language (DDL), Data Manipulation Language (DML), Data Query Language (DQL), and Data Control Language (DCL).

SQL general syntax: flexible structure, ending with a semicolon; case-insensitive; /**/, #, -- can be used for comments.

 

Guess you like

Origin blog.csdn.net/Blue92120/article/details/131452367