Get the App
SLTechnology News&Howtos  ›  Servers  › 

Basic operation of database

Shulou Source: shulou.com Published: 2022-06-02 12:56:50 09月25日 Update

1. Create an empty database create database the name of the database to be created; Note: create database aa;2, switch to the name of the database use to switch to; Note: use aa Create a data table in the database 3, create a data table in the database the name of the data table to be created by create table ("name" CHAR (character) NOT NULL, "age" INT (character) NOT NULL, "birth date" DATE NOT NULL, "class" CHAR (character) DEFAULT'do not write default content',) Note: create table C02 ("name" CHAR (24) NOT NULL, "age" INT (8) NOT NULL, "date of birth" DATE NOT NULL, "class" CHAR (10) DEFAULT 'C02,); 4. Insert multiple rows of data in the table: INSERT INTO table name (field name list) VALUES (values list), (values list)... ; example: insert into aa VALUES ('zhang','1','20'), (' li','2','30'); 5. Modify the contents in the table alter table table name change "date of birth" × × number "INT (field) NOT NULL Alter table C02 rename C02bot 6, delete database: DROP DATABASE database name; Note: drop database aa;7, commonly used field attribute constraints: non-empty constraint NOT NULL if a field is not allowed to be empty, you need to set a NOT NULL constraint. The default constraint DEFAULT assigns a field a default value. If the field is not assigned a value, the value is the default value. For example, if there are most boys in the student table, the gender default value can be set to "male" unique constraint UNIQUE KEY setting field is unique. Null is allowed, but only one null primary key constraint PRIMARY KEY sets this field as the primary key of the table, and it can be used as the only tag of the table record foreign key constraint FOREIGN KEY is used to establish a relationship between the two tables. You need to specify which field references the primary table to grow automatically AUTO_INCREMENT sets this field to self-increment field, default to increase 17 per entry, view data table list: SHOW table name; note: SHOW tables 8, view the definition fields in the table: DESCRIBE table name or DESC table name; Note: describe aa;desc aa;9, add new fields to existing fields: ALTER TABLE table name ADD field name data type attribute; 10, delete a field in the table: ALTER TABLE table name DROP field name; 11, insert data record in the data table, customize insert into 'library name. The table name in the library is'("name", "age", "date of birth") values ("Zhang San", "20 years"); note: insert into 'aa.c02' ("name", "age", "date of birth") values ("Zhang San", "20 years") 12. Types of backup: full backup, differential backup, incremental backup 13, backup mysql database mysqldump-uroot-pabc123 mysql > / opt/mysql.sql14, backup user, aa, bb these three databases mysqldump-uroot-pabc123-- databases user aa bb > / opt/uab.sql15, backup user in mysql database, information two data tables mysqldump-uroot-pabc123 mysql user information > / opt/mysqlum.sql16, the method of restoring the database. Method 1: enter the database and switch to the empty database source backup file name (absolute path) method 2: mysql-uroot-pabc123 < backup file name (absolute path) method 3: tar decompress backup software package method 4: mysqlbinlog-- no-defaults binary log files | mysql-uroot-pabc123mysqlbinlog-- no-defaults-- start-datetime='2019-01-15 1300 pabc123 -01-15 13 pabc123 30 pabc123 binary log file | mysql-log-log file

Tags: Data field database backup data table method date name age file character switch binary content attribute file name log class path Zhang San Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Technology Linux Apple Huawei