Author's Foreword
Welcome little cuties to come and learn from my gtiee Qin Boss (qin-laoda) - Gitee.com
————————————————————————————
Table of contents
A brief introduction to the database
1. Data Storage
2. Database type
(1). Relational database
(2). Non-relational database
3. Data type
4. Constraints
5.SQL
————————————————————————————
author small nonsense
In the blog in the previous chapters, I briefly introduced the simple commands of linux. These commands allow us to perform simple operations in the terminal, such as modifying files, creating folders, files, copying files or folders. Moving files or folders, searching for file names, searching for file contents, packing and compressing files (including decompression), granting permissions, obtaining administrator permissions, viewing users, and some commands to download mysql, etc. Below we operate in the environment that will step into the database
Interstitial knowledge
1. Do not design mysql password-free login when entering /etc/my.cnf, which may prevent us from connecting to the graphical interface
A brief introduction to the database
data storage
The database itself is just a kind of file
We can see what mysql looks like
You can see the layout in the mysql file
When we enter the mysql environment to view the library inside (which can be understood as a database), what is displayed is the name of the library
3. View the contents of the table
database type
1. Relational database:
RDBMS (Relational Database Management System)
Relational Database Management System : A relational database management system that expresses relational data through tables.
RDBMS-server can be understood as a server, RDBMS-ckient can be understood as a client
Operating principle:
The user has used RDBMS-ckient to send sql statements to RDBMS-server, and then RDBMS-server returns the data that meets the requirements to RDBMS-ckient
Through SQL statements, the data can be organized in a relational and structured manner, and then displayed on the user's client.
type of data
The data types of Python language include int, str, list..., etc., and the data types of C language include int, char float double, etc.
Of course mysql also has its own data type
data type
Among them, we commonly use tinyint, int (integer), double, and other smallint, mediumint, blgint, float, and decimal are used later to search
date, time, year, datetime, timestamp (timestamp) we can simply remember date and datetime, the precision of data is up to days, and the precision of datetime is up to seconds (commonly used in transaction time)
character type
In char, varchar, tinyblob, tinytext, blob, text, medlumblob, medlumtext, longblob, longtext, we first simply remember varchar, text (long text)
Notice
SQL
database operation
enter the database
mysql -u root -p
view all libraries
database: database
Add s databases: all databases
show databases;
select database
use 数据库的名称;
create database
create database 库名;或者CREATE DATABASE 库名;
create database 库名 charset=utf8;
Generally, the default is utf-8 encoding format
delete library
drop database 库名;或者DROP DATABASE 库名;
View the location of the current library
select database();或者SELECT DATABASE();
If we forget this command, we can select the library again (USE library name)
USE 库名
Data Table Operations
select library
use 库名 或者USE 库名
View all tables in the current Curry
show tables;或者SHOW TABLES;
View the structure of the current table
desc 表名;或者 DESC 表名;
The content under the field is the header name. It can be seen that there are three headers in this table: id name pid
The data type in the id is int and cannot be left blank. The default value of the primary key is empty.
view table contents
select * from 表名;
select * from 表名 limit 20; //查看表内容的前20行
Summarize:
Here is a brief introduction to some values and names of the database, as well as some simple commands, and more commands will be introduced later