Update from the basic part ~ ~ ~ ~ _
MySQL Database Basics
content
1. Introduction to mysql database related knowledge
2.1 Display the current database
4.1 View the structure of the table
1. Introduction to mysql database related knowledge
①What is a database? ? ?
A database is a type of software. The software for managing data often stores data on the hard disk (persistent storage), and it is very convenient to add, delete, check and modify; the typical representatives are: MySQL, Oracle, SQL Server; MySQL is a software with a client-server structure
②What do server, client, request, and response refer to? ? ?
Any command entered on the console essentially interacts with the server through the network;
server: the party that passively accepts the request
Client: the end that actively initiates the request Request: the data response
sent by the client to the server
: The data returned by the server to the client③How MySQL database manages data
a. There can be many data tables in a database;
b. Each data table has many rows, each row is called a "record", and each row has many columns, and each column is called a "field".
c. Databases such as MySQL require that each row and column be consistent; eg. the first row and the first column are an integer. The first column of the second row is then also an integer
d. Not all data is organized in a tabular manner
④The actual storage form of MySQL
2. Operation of the database
The operations mentioned in this section are introductory operations that belong to the database, and the subsequent complex operations will be described in the following sections.
Notice:
① Operations in the database need to end with;.
②The words are separated by spaces. The number of spaces may not be fixed, but there must be at least one
③ Both upper and lower case can be used, and bloggers are accustomed to lowercase, so subsequent codes will be presented in lowercase
④When there is a mistake when typing, press the up key in the direction key of the keyboard to restore
2.1 Display the current database
①Format:
show+space+databases semicolon
②Demo:
2.2 Create a database
①Format:
create+space+database+database name; (the name of the database can be arbitrarily chosen, but note that it cannot be a keyword)
②Demo:
2.3 Using the database
①Format:
use+space+database name;
②Demo:
2.4 Delete the database
①Format:
drop+database+database name;
②Demo:
③Note:
Deleting a database is a very dangerous operation, and it must be meticulous, meticulous and meticulous! ! !
3. Common data types
Since MySQL was born earlier than languages like Java, the data type keywords are slightly different
3.1 Numeric Types
①Detailed table
type of data size illustrate Corresponding java type BIT[ (M) ] M specifies the number of digits, the defaultis 1 binary number, M ranges from 1 to 64 ,Stores values ranging from 0 to 2^M-1 Commonly used Boolean corresponds to BIT . At this time, the default is 1 bit, that is, only 0 and 1 can be stored. TINYINT1 byte Byte SMALLINT2 bytes Short INT4 bytes Integer BIGINT8 bytes Long FLOAT(M, D)4 bytes Single precision, M specifies the length, and D specifies the number of decimal places. Loss of precision (significant digits) occursFloat DOUBLE(M,D) 8 bytes Double DECIMAL(M,D) M/D max +2 Double precision, M specifies the length, and D represents the number of decimal places. Exact value (significant digits) BigDecimal NUMERIC (M,D) M/D max +2 same as DECIMAL BigDecimal②Note:
a. The value type can be specified as unsigned ( unsigned), which means no negative number.Try not to use unsigned . For the data that may not be stored in int type, int unsigned may not be able to store it. Instead, it is better to upgrade int type to bigint type when designing. \b. 1 byte ( bytes ) = 8bit
3.2 String type
①Detailed table:
type of data size illustrate Corresponding java type VARCHAR (SIZE) 0-65,535 bytes variable length string String TEXT 0-65,535 bytes long text data String MEDIUMTEXT0-16 777 215 bytes medium length text data String BLOB 0-65,535 bytes long text data in binary form String
3.3 Date Types
①Detailed table:
type of data size illustrate Corresponding Java type DATETIME8 bytes The range is from 1000 to 9999 , and no time zone retrieval and conversion will be performed. java.util.Date 、java.sql.Timestamp TIMESTAMP4 bytes The range is from 1970 to 2038 , the current timezone is automatically retrieved and converted. java.util.Date 、java.sql.Timestamp②Note:
Time said it is best not to use varchar
4. Operation of the table
When you need to operate the tables in the database, you need to use the database first;
(i.e. refer to show databases first)
4.1 View the structure of the table
①Format: (This operation needs to select the database in advance)
show + tables;
②Demo:
③View the structure of the table: (View the type, name, etc. of each column)
desc + table name;
4.2 Create a table
①Format: (note that the column name is in the front, and the type is in the back!!!)
create table table name (column name type, column name, type.....)
②Demo:
4.3 Delete Table
①Format:
drop+table+table name;
②Demo:
③Note:
Deleting a table is also a very dangerous operation and needs to be thought twice
Suggestion: When there is a lot of code, you can type on text documents or other compilers, which is easier to check~~~
thanks for watching