当前位置:网站首页>3.认识和操作一下mysql的基本命令
3.认识和操作一下mysql的基本命令
2022-07-29 10:48:00 【不吃西红柿】
3.认识和操作一下mysql的基本命令
登录mysql,在终端输入以下命令,进行登录
mysql -u root -p
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>查看当前mysql中所有的库
库==>数据库==>就像文件夹一样,库里面可以存储很多个表)
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
选择需要操作的库,打开库
use mysql; 查看当前库中的所有数据表
show tables;
+---------------------------+
| Tables_in_mysql |
查看表中的数据
# 查看user表中的所有数据的所有字段 select * from user;
# 查看 user表中的所有数据的 host和user字段列 select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
库和表的概念与关系
库就像是文件夹,库中可以有很多个表 表就像是我们的excel表格文件一样 每一个表中都可以存储很多数据
mysql中可以有很多不同的库,库中可以有很多不同的表 表中可以定义不同的列(字段), 表中可以根据结构去存储很多的数据
如何创建自己的库?
create database 库名 default charset=utf8; 创建库
+---------------------------+
| columns_priv |
| db |
| engine_cost |
....
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec)
create database tlxy default charset=utf8;
-- Query OK, 1 row affected (0.01 sec)
查看所有库
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| tlxy |
+--------------------+
5 rows in set (0.00 sec)
-- 进入库 use tlxy;
创建表的语法
create table 表名( 字段名 类型 字段约束, 字段名 类型 字段约束, 字段名 类型 字段约束, )engine=innodb default
charset=utf8;
-- 创建用户表 create table user(
name varchar(20),
age int,
sex char(1)
)engine=innodb default charset=utf8;
-- Query OK, 0 rows affected (0.16 sec)
添加数据
-- 向 user 表中 添加 name,age,sex 数据
insert into user(name,age,sex) values('admin',26,'男'); -- Query OK, 1 row affected (0.00 sec)
insert into user(name,age,sex) values('张三',22,'女');
查看表中的数据
select * from user; +--------+------+------+ |name |age |sex | +--------+------+------+ |admin| 26|男 | |张三 | 22|女 | +--------+------+------+ 2 rows in set (0.00 sec)
总结
认识库,表的概念和关系 mysql的基本命令: 登录,查看库,选择库,查看表, 创建库,创建表,添加数据,查询数据。
边栏推荐
- VMware: use commands to update or upgrade VMware esxi hosts
- 重磅 | 开放原子校源行活动正式启动
- WPF 截图控件之绘制方框与椭圆(四) 「仿微信」
- R 语言 BRCA.mRNA数据集 分析
- [untitled]
- 「PHP基础知识」使用数组保存数据
- Ggdag draw DAG and cause and effect diagram
- 会议OA项目----我的审批
- Alibaba P8 broke out this interview guide for big factories. After reading it, the salary soared by 30K!
- 聊聊性能测试环境搭建
猜你喜欢

浅谈安科瑞灭弧式智慧用电在养老机构的应用

How can agile development reduce cognitive bias in collaboration| Agile way

AI模型风险评估 第2部分:核心内容

Meeting OA project (V) -- meeting notice and feedback details

为什么要使用markdown进行写作?

VMware: use commands to update or upgrade VMware esxi hosts

factoextra:多元统计方法的可视化PCA

A tour of grp:04 - GRP unary call unary call

Alibaba P8 broke out this interview guide for big factories. After reading it, the salary soared by 30K!

WPF 截图控件之绘制方框与椭圆(四) 「仿微信」
随机推荐
2022cuda summer training camp Day1 practice
LeetCode_ 1049_ Weight of the last stone II
Research on Android multithreading (4) -- from an interview question
Pytorch 入门
How can agile development reduce cognitive bias in collaboration| Agile way
How to synchronize when the primary and sub warehouses are modified?
Oncopy and onpaste
js两个数组对象进行合并去重
Why use markdown to write?
matplotlib中文问题
The 2022 open atom global open source summit opened in Beijing
Evolution of xxl-job architecture for distributed scheduling
Discussion on the application of arcing smart electricity in elderly care institutions
WPF 截图控件之绘制方框与椭圆(四) 「仿微信」
R包pedquant实现股票下载和金融量化分析
QT基本工程的解析
若依集成minio实现分布式文件存储
What is "enterprise level" low code? Five abilities that must be possessed to become enterprise level low code
What are the compensation standards for hospital misdiagnosis? How much can the hospital pay?
[unity, C #] character keyboard input steering and rotation