当前位置:网站首页>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的基本命令: 登录,查看库,选择库,查看表, 创建库,创建表,添加数据,查询数据。
边栏推荐
- [semantic segmentation] 2021-pvt2 cvmj
- [unity, C #] character keyboard input steering and rotation
- Spark高效数据分析02、基础知识13篇
- 为什么要使用markdown进行写作?
- 架构实战营模块八作业
- Use R-Pack skimr to collect the beautiful display of President measurement
- HMS Core Discovery第16期回顾|与虎墩一起,玩转AI新“声”态
- Explore SQL Server metadata (I)
- 敏捷开发如何消减协作中的认知偏差?| 敏捷之道
- R 语言 用黎曼和求近似 积分
猜你喜欢

站点数据收集-Scrapy使用笔记

Understanding of Arduino circuit

Analysis of QT basic engineering

阿里架构师耗时一年整理的《Lucene高级文档》,吃透你也是大厂员工!

敏捷开发如何消减协作中的认知偏差?| 敏捷之道

What is "enterprise level" low code? Five abilities that must be possessed to become enterprise level low code

Review of the 16th issue of HMS core discovery | play with the new "sound" state of AI with tiger pier

数据可视化设计指南(信息图表篇)

QT工程基本构建

Leetcode bit operation
随机推荐
Survival analysis using rtcga clinical data
The 2022 open atom global open source summit opened in Beijing
LeetCode二叉树系列——144.二叉树的前序遍历
2022cuda summer training camp Day1 practice
Regular expression matching URL
Learning R language these ebooks are enough!
开源峰会抢先看 | 7 月 29 日分论坛 & 活动议程速览
matplotlib中文问题
DW: optimize the training process of target detection and more comprehensive calculation of positive and negative weights | CVPR 2022
架构实战营模块八作业
What is the difference between a global index and a local index?
使用R包PreMSIm根据基因表达量来预测微卫星不稳定
Adcode city code in Gaode map API
Start from scratch blazor server (3) -- add cookie authorization
使用 RTCGA 临床数据进行生存分析
Oracle advanced (XIV) explanation of escape characters
LeetCode_416_分割等和子集
若依如何实现添加水印功能
GPO: using PowerShell scripts in start/logon
Matplotlib Chinese question