In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you an example of the basic operation in the Mysql database, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
one。 Operation of the library
1. Create a database
Create the database:
Create database library name charset utf8; charset uft8 is optional
1.2 Database naming convention:
Can be composed of letters, numbers, underscores, @, #, $
Case sensitive
Uniqueness
Cannot use keywords such as create select
You cannot use numbers alone.
Up to 128 bits
two。 Basic database operations:
1 View the database show databases;show create database db1;select database (); 2 Select the database USE database name 3 delete the database DROP DATABASE database name; 4 modify the database alter database db1 charset utf8
two。 Operation of the table:
A table is equivalent to a file, and a record in the table is equivalent to a line of contents of the file, and a record in the table has a corresponding title, called
The cid cname teacher_id in the first row is a field, and each other line is a record.
Create a table:
# syntax: create table table name (field name 1 type [(width) constraint], field name 2 type [(width) constraint], field name 3 type [(width) constraint]); # Note: 1. In the same table, the field name cannot be the same 2. Width and constraints are optional and optional. Width refers to field length constraints, such as 103 in char (10). Field names and types are required # case mysql > create database db1 charset utf8;mysql > use db1;mysql > create table T1 (- > id int,-> name varchar (50),-> sex enum ('male','female'),-> age int (3)->); mysql > show tables; # View all table names mysql > desc T1 under the db1 library +-+-- + | Field | Type | Null | Key | Default | Extra | + -- + | id | int (11) | YES | | NULL | | name | varchar (50) | YES | | NULL | | sex | enum ('male' 'female') | YES | | NULL | age | int (3) | YES | | NULL | | +-+ mysql > select id,name,sex,age from T1 Empty set (0.00 sec) mysql > select * from T1 politics empty set (0.00 sec) mysql > select id,name from T1 politics empty set (0.00 sec)
View the table structure:
Mysql > describe T1 # View table structure It can be abbreviated as: desc table name +-+-+ | Field | Type | Null | Key | Default | Extra | +-+- -+ | id | int (11) | YES | | NULL | | name | varchar (50) | YES | | NULL | | sex | enum ('male' 'female') | YES | | NULL | age | int (3) | YES | | NULL | | +-+ mysql > show create table T1\ G # to view the detailed structure of the table, you can add\ G
Insert data
Mysql > insert into T1 values-> (1) select * from T1),-> (2) select * from T1)-> (2) > (2) +-+ | id | name | age | sex | +-+ | 1 | chao | 18 | male | | 2 | sb | 81 | female | +- -+ mysql > insert into T1 (id) values-> (3) -> (4) Mysql > select * from T1 +-+ | id | name | age | sex | +-+ | 1 | chao | 18 | male | 2 | sb | 81 | female | 3 | NULL | 4 | NULL | +-- -+
Modify the table: alter table is a fixed syntax format
Grammar: 1. Modify ALTER TABLE table name RENAME new table name; 2. Add field ALTER TABLE table name ADD field name data type [integrity constraints.] , # Note that it can be divided by commas, adding multiple constraints ADD field name data type [integrity constraints.] ; ALTER TABLE table name ADD field name data type [integrity constraints …] FIRST; # when you add this field, put it in the first field location. ALTER TABLE table name ADD field name data type [integrity constraints …] The name of the AFTER field; # after is placed after the latter field, and we can put the newly added field in any field location in the table with a first and an after. 3. Delete field ALTER TABLE table name DROP field name; 4. Modify field ALTER TABLE table name MODIFY field name data type [integrity constraints …] ; ALTER TABLE table name CHANGE old field name new field name old data type [integrity constraints.] # change has one more function to change the name than modify. This sentence only changes one field name, ALTER TABLE table name, CHANGE old field name, new field name, new data type [integrity constraints.] ; # this sentence not only changed the field name, but also changed the data type, integrity constraints and so on. These are all the contents of the article "examples of basic Operations in Mysql Database". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.