The basic operation of the database-add, delete, modify and check

First log in to the database: enter in the terminal

/usr/local/mysql/bin/mysql -u root -p

 

How to query all the databases in the database server?

 

 

How to select a database to operate?

use database name

 

 

Only after the use operation can you select * from admin; query all records in the database

Query specific information: select * from admin where Admin_ID = 1; the name needs to be consistent with the database information queried

 

How to exit the database server?

Just type exit

 

How to create our database in the database server?

Both upper and lower case can be used

 

 

 

 

View all the data tables in this database?

 

 

How to create a data table?

pet is the table name of the data table.

create TABLE pet(
                   name VARCHAR(20),
                   owner VARCHAR(20),
                   specise VARCHAR(20),
                   sex CHAR(1),
                   birth DATE,
                   death DATE );

 

 

 

Then go to check the data table in the test database, there is: (that is, check whether the data table is successfully created)

 

 

View the structure of the created data table:

Field field, whether NULL is allowed to be empty, Key constraint related things, Default default value

 

View the records in the data sheet:

 

 

How to add data records to the data table?

Both upper and lower case

 

 

Once again, you will find the corresponding data:

 

 

 

 Enter Chinese characters, if the characters are garbled, add the utf-8 attribute when creating the database.

 

Common data types of mysql:

 Numeric value, date / time, character string (character)

 

Then insert multiple

INSERT INTO pet VALUES('kk1','cc1','dog1','1','1998-1-2',null);
INSERT INTO pet VALUES('kk2','cc2','dog2','2','1998-2-2',null);
INSERT INTO pet VALUES('kk3','cc3','dog3','1','1998-3-2','1998-12-2');
INSERT INTO pet VALUES('kk4','cc4','dog4','2','1998-4-2',null);

 

 

View:

 

  

Delete the first piece of data:

delete from pet where name='puffball';

 

View:

 

 

How to modify the data?

To change kk4 to kk44, you need to write the table name pet and owner.

update pet set name='kk44' where owner='cc4';

 

 

Summarize the common operations of data recording:

Add INSERT, delete DELETE, modify UPDATE, query SELECT.

 

Guess you like

Origin www.cnblogs.com/OFSHK/p/12711827.html