This is the 13th day of my participation in the August More text Challenge. For details, see: August More Text Challenge

In case you’re wondering how to talk about a database, we’ll talk about node linking to a database and operating a database

The MySQL database

1.1 What is a Database

A warehouse where data is stored.

Common databases: MySQL, Oracle, Sqlserver, and DB2.

MySQL 1.2 introduction

MySQL is a relational database management system developed by MySQL AB in Sweden and is currently a product of Oracle

MySQL structure:

The structure of the data sheet is exactly the same as excel:

Table structure:

It’s the same structure as an Excel sheet.

Each column is a type of data – a field

Each row represents a piece of data — a record

1.3 Installing the Client

MySQL is a C/S structure software.

MySQL itself is server-side.

Common clients: CMD, Navicat, Sqlyog, phpMyadmin and so on, you can choose according to your own hobby. Note: Do not use Chinese in the installation path

1.4 Using a Client to Connect to the MySQL Server

  1. Click the link button – select the type of database you want to link to

  1. Configuring Link Information

User name: root The user is the highest user of the MySQL server system and has all permissions of the system.

Password: default password of user root in root phpStudy.

3. Click “localhost”The contents under localhost on the left are all database names.

Information_schema, mysql, performance_SCHEMA are the system databases (don’t move). The rest are self-built databases

If you see the figure above, you have connected to the MySQL server using the Navicat client.

1.5 Creating a database using Navicat

  1. Right click on ‘localhost’ and select ‘New database’
  2. Enter the database name and character set (recommended or not).
  3. The list will appear in the database that you built.

1.6 Creating data tables using Navicat

  1. Double-click ‘study’ –> ‘Table’ (right click) –> ‘New Table’
  2. Set the field name and data type of the data table

  1. After saving, use F5 to refresh, and you can see the new table

Data query

2.1 Basic Query

Syntax format: select field name 1, field name 2,…. From the name of the table

Case 1: Query the student number and name table for all students: student

Fields: SNO, sNAME

select sno,sname from student
Copy the code

Case 2: Query all student information (All field information)

select * from student
Copy the code

* is a wildcard, representing all fields.

2.2 Query with A WHERE clause

select field1, field2… From Table name Queries all data in the table

Where can be used to filter the results of the query

Query conditions The predicate
To compare >, >=, <, <=,! =, <>,! >,! <, not, + comparison operators
Determine the scope of between… and… And not between… and …
A collection of In, not in
Character match Like, not like
Multiple conditions And, or

Case 3: Query all information about student number 2

Table: student

Fields: *

Filter criteria: SNO =2

select * from student where sno=2
Copy the code

2.3 Fuzzy Query

Wild card:

%: any character of any length (including 0)

_: any character of 1 character length

A % B: ab abb A to Sada Ba_b: acb  atb 
a_b%:  acb  a&baaad
Copy the code

Like: When executing a fuzzy query, you must use like as a matching condition

Case 1: Query information about a student whose nickname contains X

Table: student

Fields: *

Snickname like ‘%x%’

select * from student
where snickname like '%x%'
Copy the code

2.4 Sorting query Results

Order BY can sort the query results by the rise or fall of a certain field

Ascending asC (default), descending DESC

Sorted fields are usually integers, English string, date (Chinese string is ok, but generally not)

Case 1: Query information about all students in ascending order of age

Table: student

Fields: *

Filter condition: None

Order by Sage ASC

select * from student
order by sage ase
Copy the code

2.5 Limiting query Results

The limit is used to limit the start point and length of the query result

Format: LIMIT VAR1, VAR2

Var1: indicates the starting point. Index of the query result, starting from 0. 0 represents the first data

The length of the var2:

select * from student
limit 2.4
Copy the code

The next part mainly talks about multi – table query and relational database

Praise support, hand stay fragrance, and have glory yan, move your small hand to make a fortune yo, thank you for leaving your footprints.

Past excellent recommendation

Front-end performance optimization combat

Talk about regular expressions

Obtain the file BLOB stream address to download the function

Git

An easy-to-read introduction to Git

Git implements automatic push

How do I use Git at work

Interview recommendations

Front ten thousand literal classics – basic

Front swastika area – advanced chapter

More wonderful details: personal home page