Linux下Mysql的查询用法
Posted jks212454
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下Mysql的查询用法相关的知识,希望对你有一定的参考价值。
Linux下mysql的查询用法
一、Mysql的delete删除语法
1.删除数据库
①使用drop删除
mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| huawei |
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+--------------------+
6 rows in set (0.00 sec)
mysql> drop database huawei;
Query OK, 1 row affected (0.10 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+--------------------+
5 rows in set (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
2.删除数据库的表
①使用drop语法
mysql> show tables;
+------------------+
| Tables_in_zabbix |
+------------------+
| student |
+------------------+
1 row in set (0.00 sec)
mysql> drop table student;
Query OK, 0 rows affected (0.05 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
Empty set (0.00 sec)
二、查询数据
语法:select _column,_column from _table [where Clause] [limit N][offset M]
1.基本查询
select * from 表名
mysql> select * from fruits;
+------+------+------------+---------+
| f_id | s_id | f_name | f_price |
+------+------+------------+---------+
| a1 | 101 | apple | 5.20 |
| b1 | 101 | blackberry | 10.20 |
| bs1 | 102 | orange | 11.20 |
| bs2 | 105 | melon | 7.20 |
| t1 | 102 | banana | 10.30 |
+------+------+------------+---------+
5 rows in set (0.00 sec)
mysql> select s_id from fruits;
+------+
| s_id |
+------+
| 101 |
| 101 |
| 102 |
| 105 |
| 102 |
+------+
5 rows in set (0.00 sec)
2.条件查询
mysql> select s_id,f_name,f_price from fruits where f_price <=7;
+------+--------+---------+
| s_id | f_name | f_price |
+------+--------+---------+
| 101 | apple | 5.20 |
+------+--------+---------+
1 row in set (0.00 sec)
三、数据库插入数据
1.创建新表
create table fruits ( f_id char(10) not null, s_id int not null, f_name char(255) not null, f_price decimal(8,2) not null, primary key(f_id) );
2.插入数据
mysql> insert into fruits(f_id,s_id,f_name,f_price) values ('bs2',105,'melon','7.2') ;
Query OK, 1 row affected (0.00 sec)
mysql> insert into fruits(f_id,s_id,f_name,f_price) values ('t1',102,'banana','10.3') ;
Query OK, 1 row affected (0.05 sec)
mysql> select * from fruits;
+------+------+------------+---------+
| f_id | s_id | f_name | f_price |
+------+------+------------+---------+
| a1 | 101 | apple | 5.20 |
| b1 | 101 | blackberry | 10.20 |
| bs1 | 102 | orange | 11.20 |
| bs2 | 105 | melon | 7.20 |
| t1 | 102 | banana | 10.30 |
+------+------+------------+---------+
5 rows in set (0.00 sec)
四、修改数据库表内容
mysql> select * from fruits;
+------+------+------------+---------+
| f_id | s_id | f_name | f_price |
+------+------+------------+---------+
| a1 | 101 | apple | 5.20 |
| b1 | 101 | blackberry | 10.20 |
| bs1 | 102 | orange | 11.20 |
| bs2 | 105 | melon | 7.20 |
| t1 | 102 | banana | 10.30 |
+------+------+------------+---------+
5 rows in set (0.00 sec)
mysql> UPDATE fruits SET f_price='8.5' WHERE f_id='a1';
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from fruits;
+------+------+------------+---------+
| f_id | s_id | f_name | f_price |
+------+------+------------+---------+
| a1 | 101 | apple | 8.50 |
| b1 | 101 | blackberry | 10.20 |
| bs1 | 102 | orange | 11.20 |
| bs2 | 105 | melon | 7.20 |
| t1 | 102 | banana | 10.30 |
+------+------+------------+---------+
5 rows in set (0.00 sec)
以上是关于Linux下Mysql的查询用法的主要内容,如果未能解决你的问题,请参考以下文章