Why learn database?

1. There is demand

① Many programs run data need to be pre-saved, and the results of the program run often need to be saved.

② Sometimes, we need to query the stored data, this time, the database is very useful.

2. Advantages of database

① Data can be stored for a long time.

② Can realize structured query, convenient management.

2. Database related concepts

 1, data: data, data is the basic object stored in the database2DB: database, a container that holds a group of organized data3DBMS: Database management system, also known as database software (product), used to manage the data in DB4, DBS: database system, DBS = DBMS + DB5SQL: Structured query language, used to communicate with DBMS. Data Query Language (DQL): Data Query Language (DML): Data Define Languge (DDL): Data Definition Language TCL (Transaction Control Language) : Transaction Control LanguageCopy the code

Three, the characteristics of database storage data

        1, put the data into the table, and the table into the library2A database can have multiple tables, and each table has a name that identifies it. Table names are unique.3Tables have properties that define how data is stored in a table, similar to the design of classes in Java.4A table consists of columns, also known as fields. All tables are composed of one or more columns, each of which is similar to the "properties" in Java5Data in a table is stored in rows, each row similar to an object in Java.Copy the code

MySQL database basic operations

1. Start and stop MySQL services

Method 1: Computer – right click Manage – Services

Method 2: Run CMD as the administrator

Net Start Service name (starting a service) Net Stop Service name (stopping a service)Copy the code

2. Log in and log out of the MySQL service

Method 1: Use the mysql client

Only root userCopy the code

Method 2: Use the Windows client (Environment variables need to be configured, and environment variable configuration is attached)

Mysql [-h host name -p port number] -u user name -p password Exit: exit or CTRL +CCopy the code

MySQL > select * from ‘MySQL’

1. View all the current databases

show databases;
Copy the code

2. Open the specified library

Use the library.Copy the code

3. View all tables in the current library

show tables;
Copy the code

4. View all tables in other libraries

Show tables from database name;Copy the code

5. Create the tables

Create table name (column name column type, column name column type,...) ; Create table Student(Sno char(8) primary key, Sname char(20), Sage int(4));Copy the code

6. View the table structure

Desc table name;Copy the code

7. Check the server version

Method 1: Log in to the mysql server

select version();
Copy the code

Method 2: Do not log in to the mysql server (CMD)

Mysql --version or mysql --VCopy the code

8. Display all data in the table

select * fromThe name of the table. select Snofrom Student;
Copy the code

Insert data into table

Insert into values(attributes1Attributes,2...). ; Insert into Student values('20200001'.'Joe'.23);
Copy the code

MySQL > configure MySQL environment variables

1, find the MySQL directory, find the path of the bin folder, copy it

2, right click “My computer”, click “Advanced System Settings”, click “Environment Variables” button.

3, click “New” button, enter variable name: MYSQL_HOME, variable value: enter mysql path, and click “OK”.

4. Click OK to go to CMD test

Login:

Mysql [-h host name -p port number] -u user name -p passwordCopy the code

5. If the following interface is displayed, environment variables are configured successfully