当前位置:网站首页>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的基本命令: 登录,查看库,选择库,查看表, 创建库,创建表,添加数据,查询数据。
边栏推荐
- 使用R包PreMSIm根据基因表达量来预测微卫星不稳定
- R language Monte Carlo method and average method are used to calculate the definite integral. Considering the random point casting method, the confidence is 0.05, and the requirement is ϵ= 0.01, numbe
- 判断两个对象的值是否都相等
- matplotlib中文问题
- Understanding of Arduino circuit
- 开源峰会抢先看 | 7 月 29 日分论坛 & 活动议程速览
- JVM知识点详细整理(长文警告)
- 通过tidymodels使用XGBOOST
- Luogu p1816 loyalty solution
- What is "enterprise level" low code? Five abilities that must be possessed to become enterprise level low code
猜你喜欢

Kunlunbase instruction manual (III) data import & synchronization

重磅 | 基金会为白金、黄金、白银捐赠人授牌

How to realize the function of adding watermark

1. (map tools) detailed tutorial of acrgis desktop10.5 software installation

Pytorch 入门

Leetcode bit operation

98. (cesium chapter) cesium point heat

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

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

JVM知识点详细整理(长文警告)
随机推荐
Summer 2022 software innovation laboratory training JDBC
Mongodb aggregation statistics
一键搭建博客:如何使用WordPress插件搭建专属博客
Survival analysis using rtcga clinical data
Regular expression matching URL
R language brca MRNA data set analysis
Evolution of xxl-job architecture for distributed scheduling
R 语言 Monte Carlo方法 和平均值法 计算定积分, 考虑随机投点法,计算在置信度0.05, 要求为ϵ=0.01 , 所需要的试验次数
How can agile development reduce cognitive bias in collaboration| Agile way
Open source, compliance escort! 2022 open atom global open source summit open source compliance sub forum is about to open
LeetCode二叉树系列——144.二叉树的前序遍历
How to synchronize when the primary and sub warehouses are modified?
Steps of project explanation in interview
Explore SQL Server metadata (I)
Drunken driving alarm system based on stm32
LeetCode_ 1049_ Weight of the last stone II
1. (map tools) detailed tutorial of acrgis desktop10.5 software installation
一文搞懂什么是二叉树(二叉树的种类、遍历方式、定义)
Luogu p1816 loyalty solution
GPO: using PowerShell scripts in start/logon