Article Directory
MySQL database
MySQL is a relational database management system developed by MySQL AB in Sweden and currently belongs to Oracle Corporation. MySQL is a relational database management system. A relational database keeps data in different tables instead of putting all the data in one big warehouse, which increases speed and improves flexibility.
- MySQL is open source and is currently part of Oracle's products
- MySQL supports large databases. Can handle large databases with tens of millions of records
- MySQL uses the standard SQL data language form.
- MySQL can run on multiple systems and supports multiple languages. these programming languages
1. Create a database
1. Link to the MySQL database
1.mysql -u root -p
2.mysql -h hsot -u root -p
-u is the user user, -p is the password password
-h is the host host address, -u is the user user, -p is the password password (applicable to remote link login database)
Enter the link command and press Enter, then enter the MySQL password (don’t forget the password), and then press Enter to connect to MySQL
2. View the current database
1.show databases;
See which databases are in the currently installed MySQL.
3. Create a library
1.create database tutou;
2.show databases;
Use create database database name; create a library named tutou
show databases; view all current libraries and verify whether the creation is successful
Real column
2. Create a data table
1. Enter the library
1.use tutou;
The use command allows us to use the database.
Use command format: use library name;
2. Create a data table
Create a data table (creating a MySQL data table requires the following information: table name, table field name, and definition of each table field)
2.1. Create a data table name
create table 学院图书管理系统();
2.2. Create table fields, data types, and constraints
Example:
create table 学院图书管理系统(
入馆时间 datetime not null
);
Entry time = table field
date (indicating the date and type of time value) = data type
not null (indicating that the attribute cannot be empty) = constraint
2.3. Constraints - primary key
Example:
orimary key (field)
create table 学院图书管理系统(
入馆时间 datetime not null
学号 int not null,
orimary key (学号)
);
The relationship between the primary key and the record is like the relationship between the ID card and the person, they are one-to-one correspondence.
(1) The primary key constraint requires that the data in the primary key column be unique and not allowed to be empty.
(2) The primary key can uniquely identify a record in the table, and can be combined with foreign keys to define the relationship between different data tables, and the query speed of overtime database (2) is generally divided into single sub-segment primary key and multi-field primary
key
2.3. Complete data table fields, data types, constraints
Example:
show tables;
Query all the tables in the library to verify whether the table is successfully
created
3. Insert data
3.1, enter the library
1.use tutou;
example
3.2. Insert statement
The INSERT INTO statement is used to insert new data into the table.
列:
insert into 表明(字段1,字段2)
values
("对应字段1数据","对应字段2数据")
;
Example:
3.3. Query the data in the table
1.select * from 表名
select: the statement is used to select data from the table
(*): is a shortcut to select all fields
from: specify the data table name
Example:
select * from College library management system;