MySQL数据库管理

一、查看数据库结构

1.查看数据库信息

在这里插入图片描述

2.查看数据库中的表信息

在这里插入图片描述

3显示数据表的结构

在这里插入图片描述

二、SQL语句概述

1SQL语言简介
●Structured Query Language的缩写,即结构化查询语言
●关系型数据库的标准语言
●用于维护管理数据库
包括数据查询、数据更新、访问控制、对象管理等功能
2SQL分类
●DDL:数据定义语言
●DML:数据操纵语言
●DQL:数据查询语言
●DCL:数据控制语言

三、MySQL基础命令

mysql> select * from user;    查看表的数据信息
mysql> create database school;     创建数据库
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| school             |
| sys                |
+--------------------+
5 rows in set (0.00 sec)
mysql> create table student (id int(9) primary key not null,name char(10) not null,socre decimal(5,2) default '0');创建表
Query OK, 0 rows affected (0.01 sec)
mysql> desc student;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id    | int(9)       | NO   | PRI | NULL    |       |
| name  | char(10)     | NO   |     | NULL    |       |
| socre | decimal(5,2) | YES  |     | 0.00    |       |
+-------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> drop table comany.boss;    删除表
Query OK, 0 rows affected (0.01 sec)
mysql> drop database comany;     删除库
Query OK, 0 rows affected (0.00 sec)
mysql> insert into student(id,name,socre)values(170420101,'zhangqing',91);往表中插入数据
mysql> select * from student;  查看添加信息
+-----------+-----------+-------+
| id        | name      | socre |
+-----------+-----------+-------+
| 170420101 | zhangqing | 91.00 |
| 170420102 | yangwu    | 88.00 |
+-----------+-----------+-------+
2 rows in set (0.00 sec)
mysql> create table teacher as select * from student where name='zhangqing';提取数据库信息到另一个数据库
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| student          |
| teacher          |
+------------------+
2 rows in set (0.00 sec)

mysql> select * from teacher;
+-----------+-----------+-------+
| id        | name      | socre |
+-----------+-----------+-------+
| 170420101 | zhangqing | 91.00 |
+-----------+-----------+-------+
1 row in set (0.00 sec)
mysql> update teacher set socre=100 where id=110;修改更新数据库表中的数据
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from teacher;
+-----------+-----------+--------+
| id        | name      | socre  |
+-----------+-----------+--------+
| 110 | zhangqing | 100.00 |
+-----------+-----------+--------+
1 row in set (0.00 sec)
mysql> create temporary table tmp(id int (5) not null primary key auto_increment,创建临时表
    -> name char(10) not null,
    -> socre double(5) default '0'
    -> )engine=innodb default charset=utf8;
mysql> desc tmp;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(5)       | NO   | PRI | NULL    | auto_increment |
| name  | char(10)     | NO   |     | NULL    |                |
| socre | decimal(5,2) | YES  |     | 0.00    |                |
+-------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> create table test1 as select * from teacher; 克隆
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| student          |
| teacher          |
| test             |
| test1            |
+------------------+
4 rows in set (0.00 sec)

mysql> desc test1;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id    | int(9)       | NO   |     | NULL    |       |
| name  | char(10)     | NO   |     | NULL    |       |
| socre | decimal(5,2) | YES  |     | 0.00    |       |
+-------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> select * from test1;
Empty set (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值