Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add a database using mysql database basic commands

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

How to use mysql database basic commands to add a database, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Add database

[root@localhost ~] # mysql-uroot-p # enter mysql data table`Enter password: Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 8. # omit part of the content Type 'help;' or'\ h' for help. Type'\ c' to clear the current input statement.mysql > show databases;+-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | sys | +-+ 4 rows in set (0.00 sec)

Mysql > create database school; # create a new library 'school

Query OK, 1 row affected (0.00 sec)

Mysql > show databases; # View all libraries

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | performance_schema |

| | school |

| | sys |

+-+

5 rows in set (0.00 sec)

Add data tabl

Mysql > use school;mysql > create table info (id int not null,name char (6), score decimal (5), age int (4)) Query OK, 0 rows affected (0.04 sec) mysql > desc info # View the table structure +-+-+ | Field | Type | Null | Key | Default | Extra | +- -+-+ | id | int (11) | NO | | NULL | | name | char (6) | YES | | NULL | | score | decimal (5L2) | YES | NULL | | age | int (4) | YES | NULL | | +-+- -+ add data table content mysql > insert into info (id Name,score,age) values (1Jing 'Zhang San', 88. 33) Query OK, 1 row affected (0.01sec) mysql > insert into info (id,name,score,age) values; Query OK, 1 row affected (0.01sec) mysql > insert into info (id,name,score,age) values; Query OK, 1 row affected (0.00 sec) mysql > select * from info # View the contents of the table +-+ | id | name | score | age | +-- + | 1 | Zhang San | 88.00 | 33 | 2 | Li Si | 48.00 | 31 | 3 | Wang Wu | 68.00 | 27 | +-- + | -+ add the table column mysql > alter table info add column score decimal (5penny 2) Query OK, 0 rows affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0mysql > select * from info # View the contents of the table +-+ | id | name | hobbly | score | +-- + | 1 | zl | NULL | | 2 | Li Si | surfing the Internet | NULL | | 5 | kl | Swimming | NULL | +- -- + change data mysql > update info set score=82 where id=1 # change the id=1 student's score to 82 Query OK, 1 row affected (0.01sec) Rows matched: 1 Changed: 1 Warnings: 0mysql > select * from info # View change effect +-+ | id | name | score | age | +-- + | 1 | Zhang San | 82.00 | 33 | | 2 | Li Si | 48.00 | 31 | 3 | Wang Wu | 68.00 | 27 | +-+ | -+ Delete data table mysql > drop table info Query OK, 0 rows affected (0.02 sec) mysql > show tables; # check whether to delete Empty set (0.00 sec) # deleted (empty table) delete library mysql > drop database school;Query OK, 0 rows affected (0.01 sec) mysql > show databases # check whether the school database deletes +-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | sys | +-+ delete table columns (number of records) mysql > delete from info where hobbly=1 Query OK, 1 row affected (0.01sec) mysql > select * from info +-+ | id | name | score | age | hobbly | +-- + | 1 | Zhang San | 82.00 | 33 | 3 | 2 | Li Si | 48.00 | 31 | | | 5 | | 3 | Wang Wu | 68.00 | 27 | 4 | | 2 | ff | 55 | 44 | 2 | 3 | ww | 33 | 3 1 | 3 | + + delete table column (field) mysql > select * from info | # View data table +-+ | id | name | score | hobbly | +-+ | 1 | zl | 88 | Reading | | 2 | Lisi | 68 | surfing the Internet | | 5 | kl | 88 | | | Swimming | +-+ mysql > alter table info drop column score | # use alter to delete the table column mysql > select * from info # check the data table again +-+ | id | name | hobbly | +-- + | 1 | zl | read books | | 2 | Lisi | surf the Internet | | 5 | kl | Swimming | +-+ finish reading the above Have you learned how to add a database using the basic mysql database commands? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report