MYSQL的基础知识

本文介绍了MySQL数据库的作用,如数据持久化、快速查询等,并详细讲解了如何登录MySQL,展示了一些基础的数据库操作,包括查看数据库、数据表,选择库,查看表数据,创建表以及插入数据。通过实例演示了MySQL中的库和表的概念,帮助初学者理解数据库管理和操作。
摘要由CSDN通过智能技术生成

一、MySQL是什么?

MySQL数据库(Database)就是按照数据结构来组织,存储和管理数据的仓库 专业的数据库是专门对数据进行创建,访问,管理,搜索等操作的软件,比起我们自己用文件读写的方 式对象数据进行管理更加的方便,快速,安全.

(一)作用

对数据进行持久化的保存 方便数据的存储和查询,速度快,安全,方便 可以处理并发访问 更加安全的权限管理访问机制

二、mySQL的基本命令(重点!)

1.登录mysql,在终端输入以下命令,进行登录

(win10版)

C:\Users\Administrator>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

(mac版)

MacBook-Pro:~ yc$ mysql -u root -p 
Enter password:
 Welcome to the MySQL monitor. Commands end with ; or \g.
  Your MySQL connection id is 4
   Server version: 5.7.28 Homebrew 
   Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. 
   Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. 
   Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
   mysql>

2.mysql的基础使用

1.查看当前mysql中所有的库。
库==>数据库==>就像文件夹一样,库里面可以存储很多个表

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

2.查看当前库中的所有数据表

mysql> show tables;
+--------------------+
| Tables_in_jianming |
+--------------------+
| users              |
+--------------------+
1 row in set (0.00 sec)

mysql> select * from users;
Empty set (0.01 sec)

3.选择需要操作的库,打开库

mysql> use jianming
Database changed
mysql> show tables
    -> show tables;

4.查看表中的数据.

mysql> select * from users;
+----+--------+------+
| id | name   | age  |
+----+--------+------+
| 10 | 张三   |   25 |
+----+--------+------+
1 row in set (0.00 sec)

5.创建表

mysql> create table if not exists myusers(
    -> id int not null primary key auto_increment,
    -> name varchar(4) not null,
    -> age tinyint,
    -> sex enum('男','女')
    -> )engine=innodb default charset=utf8mb4;

6.往表中添加数据

 insert into users(id,name,age) values(12,'涨势',23),(15,'物理',18);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from users;
+----+--------+------+
| id | name   | age  |
+----+--------+------+
| 10 | 张三   |   25 |
| 12 | 涨势   |   23 |
| 15 | 物理   |   18 |
+----+--------+------+
3 rows in set (0.00 sec)

总结

1.库和表的概念与关系
库就像是文件夹,库中可以有很多个表 表就像是我们的excel表格文件一样 每一个表中都可以存储很多数据 mysql中可以有很多不同的库,库中可以有很多不同的表 表中可以定义不同的列(字段), 表中可以根据结构去存储很多的数据

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值