MySQL命令学习

上面两篇博客讲了MySQL的安装、登录,密码重置,为接下来的MySQL命令学习做好了准备,现在开启MySQL命令学习之旅吧。

首先打开CMD,输入命令:mysql -u root -p  登录MySQL。

注意:MySQL命令终止符为分号 (;) 

1.show databases;显示当前用户的数据库

2.use 数据库名;   选择数据库

3.create database 数据库名; 创建数据库

4. drop database  数据库名 ;删除数据库 

5.create table if not exists `表名`()engine= InnoDB default charset=utf8;创建数据表 

例:

create table if not exists `test_user`(
`test_id` int unsigned auto_increment,
`test_title` varchar(100) not null,
 `test_name` varchar(100) not null,
`test_createDate` date, primary key (`test_id`)
)engine= InnoDB default charset=utf8;

6. drop  table 表名; 删除数据表 

7.show tables; 显示当前数据库的表

8.insert  into table_name ( 字段1,字段2,...字段) values   ( value1, value2,...valueN );为表插入数据

9. where是查询条件语句与select,update,delete一起用的

10.select 查询命令,select 读取一条或者多条记录

  10.1  select * from 表名  查看表里的所有数据 ,显示所有字段  

  10.2  select column_name,column_name from 表名 where 条件 limit n offset m ;查询满足条件的数据,只显示字段column_name,column_name

  • 查询语句中可以使用一个或者多个表,表之间使用逗号(,)分割
  • 用星号(*)来代替其他字段,select语句会返回表的所有字段数据
  • 使用 where语句写查询条件。
  • 使用limit 属性来设定返回的记录数。
  • offset指定select语句查询数据的偏移量。默认偏移量为0。
例1:
select test_title from test_user where test_id>2 limit 3 offset 3;
查询结果只显示了字段:test_title
test_id>2的记录有3,4,5,6,7,8,9,10,11,然后offset为3,所以查询结果偏移3后,最后的数据为:6,7,8
例2:
select test_title from test_user where test_id>7 limit 3 offset 3;
查询结果只显示了字段:test_title
test_id>7的记录有8,9,10,11,然后offset为3,所以查询结果偏移3后,最后的数据为:11

11.update 表名 set field1=new-value1, field2=new-value2 where 条件; 更新满足条件的记录

    例:update test_user set test_createDate="2018-11-02" where test_id<5;

12.delete from 表名 where 条件; 删除表里满足条件的记录 
 
    delete from test_user where id>6 && id<8; 删除第7条数据

13.like,like与where联合使用,表示包含的情况,其中like语句的%表示任意字符,如果like语句中没有用%,那么它就与等号没有差别

like "%my":表示以my结尾
like "%my%":表示中间或开始有my
like "my%":表示以my开始
like "my" :表示等于my

14.order by 字段  ASC |DESC ;这个命令一般跟select联合使用, 根据什么字段排序,默认情况下是升序

        asc:升序

        desc:降序    

        按拼音来排序:

      14.1 如果字符集采用的是 gbk(汉字编码字符集),直接在查询语句后边添加 order by:

             select * from 表名 order by 字段  ASC ;

      14.2 如果字符集采用的是 utf8(万国码),需要先对字段进行转码然后排序:

      select * from 表名 order by convert(runoob_title using gbk)

15. show columns from 表名查看表的字段定义格式

 例:show columns from test_user;

16.alter 

    16.1 alter table 表名 add 新字段 数据类型;为数据表添加新的字段(为已经建好的表增加一列)

         例:

              alter table test_user add score int; 为表test_user,添加类型为int的新字段score;

              alter table test_user add score int first;为表test_user,添加类型为int的新字段score,并且放在第一位

             alter table test_user add score int  after  name;      添加类型为int的新字段score,并且放在字段name的后面

 

   16.2 alter table 表名 drop 字段;删除数据表的字段(为已经建好的表删除一列)

   例:alter table test_user drop score;

  16.3 alter table 表名 modify 字段  新类型;修改已有字段的类型

     例:alter table test_user modify test_title  varchar(200) not null default  "hello";

            修改表test_user的字段test_title 的类型为varchar(200) ,并且不能为null,默认值为hello

  16.4 alter table 表名 change 字段  新字段 新字段数据类型;更改旧字段的名称及类型

 例:alter table test_user change score middle_score int;

  16.5 alter table 表名 engine=myisam;修改存储引擎为myisam

  16.6 alter table 表名 drop foreign key 键名;删除外键约束

  16.7 alter table 表名 modify 字段1  数据 first|after 字段2;

     修改字段的相对位置,字段1为想要修改的字段,类型为该字段原来类型,first和after二选一,first放在第一位,after放在字段2后面

  16.8 alter table 表名 alter 字段 set default ;为数据表字段设置默认值;

 例:alter table test_user alter score set default 0;表test_user的score字段 设置默认值0;

  16.9 alter table 表名 rename to 新的表名;更改数据表的名字

 

  1. show databases; 显示当前用户的数据库

2.  use 数据库名;   选择数据库

3. create database 数据库名; 创建数据库

 

4. drop database 数据库名 ;删除数据库

 5.create table if not exists `test_user`()engine= InnoDB default charset=utf8;创建数据表

create table if not exists `test_user`(
`test_id` int unsigned auto_increment,
`test_title` varchar(100) not null,
 `test_name` varchar(100) not null,
`test_createDate` date, primary key (`test_id`)
)engine= InnoDB default charset=utf8;

6. drop  table 表名; 删除数据表

7.show tables; 显示当前数据库的表

8.insert  into table_name ( field1, field2,...fieldN ) values   ( value1, value2,...valueN );为表插入数据

 

9. where是查询条件语句与select,update,delete一起用的

10.select 查询命令,select 读取一条或者多条记录

   select * from 表名;   查看表里的所有数据 ,显示所有字段  

 select column_name,column_name from 表名 where 条件 limit n offset m ;查询满足条件的数据,只显示字段column_name,column_name

  • 查询语句中可以使用一个或者多个表,表之间使用逗号(,)分割
  • 用星号(*)来代替其他字段,select语句会返回表的所有字段数据
  • 使用 where语句写查询条件。
  • 使用limit 属性来设定返回的记录数。
  • offset指定select语句查询数据的偏移量。默认偏移量为0。
select test_title from test_user where test_id>2 limit 3 offset 3;
查询结果只显示了字段:
test_title
test_id>2的记录有3,4,5,6,7,8,9,10,11,然后offset为3,所以查询结果偏移3后,最后的数据为:6,7,8

select test_title from test_user where test_id>7 limit 3 offset 3;
查询结果只显示了字段:test_title
test_id>7的记录有8,9,10,11,然后offset为3,所以查询结果偏移3后,最后的数据为:11


11.update
表名 set field1=new-value1, field2=new-value2 where 条件; 更新满足条件的记录

 update test_user set test_createDate="2018-11-02" where test_id<5;



12.delete from 表名 where 条件; 删除表里满足条件的记录 

 
delete from test_user where id>6 && id<8; 删除第7条数据

 

13.like,like与where联合使用,表示包含的情况,其中like语句的%表示任意字符,如果like语句中没有用%,那么它就与等号没有差别

like "%my":表示以my结尾
like "%my%":表示中间或开始有my
like "my%":表示以my开始
like "my" :表示等于my
查询结果如下:

 14.order by 字段  ASC |DESC ;这个命令一般跟select联合使用, 根据什么字段排序,默认情况下是升序

        asc:升序

        desc:降序    

        按拼音来排序:

      14.1 如果字符集采用的是 gbk(汉字编码字符集),直接在查询语句后边添加 order by:

             select * from 表名 order by 字段  ASC ;

      14.2 如果字符集采用的是 utf8(万国码),需要先对字段进行转码然后排序:

      select * from 表名 order by convert(runoob_title using gbk); 

           

 

15. alter table 表名 add 新字段 数据类型;为数据表添加新的字段(为已经建好的表增加一列)

         alter table test_user add score int;

 

16.alter table 表名 drop 字段;删除数据表的字段(为已经建好的表删除一列)

 alter table test_user drop score;

 

 

17. alter table 表名 modify 字段  新类型;修改已有字段的类型

 alter table test_user modify test_title  varchar(200);

 

18. show columns from 表名; 查看表的字段定义格式

 show columns from test_user;

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389130.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

实验心得_大肠杆菌原核表达实验心得(上篇)

大肠杆菌原核表达实验心得&#xff08;上篇&#xff09;对于大肠杆菌蛋白表达&#xff0c;大部分小伙伴都觉得 so easy! 做大肠杆菌蛋白表达十几年经历的老司机还经常阴沟翻船&#xff0c;被大肠杆菌表达蛋白虐千百遍的惨痛经历&#xff0c;很多小伙伴都有切肤之痛。福因德接下…

scrapy从安装到爬取煎蛋网图片

下载地址&#xff1a;https://www.lfd.uci.edu/~gohlke/pythonlibs/pip install wheelpip install lxmlpip install pyopensslpip install Twistedpip install pywin32pip install scrapy scrapy startproject jandan 创建项目cd jandancd jandan items.py 存放数据pipelines.p…

高斯金字塔 拉普拉斯金字塔_金字塔学入门指南

高斯金字塔 拉普拉斯金字塔The topic for today is on data validation and settings management using Python type hinting. We are going to use a Python package called pydantic which enforces type hints at runtime. It provides user-friendly errors, allowing you …

基本排序算法

插入排序 基本思想&#xff1a;把待排序列表分为已排和未排序两部分&#xff0c;从未排序左边取值&#xff0c;按顺序从已排序的右端开始对比插入到相应的位置。 java代码实现 private void insertSort(int[] arr){int i, j;int temp;for(i 0; i < arr.length; i){temp …

自定义版本更新弹窗

目录介绍 1.Animation和Animator区别 2.Animation运行原理和源码分析 2.1 基本属性介绍2.2 如何计算动画数据2.3 什么是动画更新函数2.4 动画数据如何存储2.5 Animation的调用 3.Animator运行原理和源码分析 3.1 属性动画的基本属性3.2 属性动画新的概念3.3 PropertyValuesHold…

《SQL Server 2008从入门到精通》--20180716

1.锁 当多个用户同时对同一个数据进行修改时会产生并发问题&#xff0c;使用事务就可以解决这个问题。但是为了防止其他用户修改另一个还没完成的事务中的数据&#xff0c;就需要在事务中用到锁。 SQL Server 2008提供了多种锁模式&#xff1a;排他锁&#xff0c;共享锁&#x…

googleearthpro打开没有地球_嫦娥五号成功着陆地球!为何嫦娥五号返回时会燃烧,升空却不会?...

目前&#xff0c;嫦娥五号已经带着月壤成功降落到地球上&#xff0c;创造了中国航天的又一里程碑。嫦娥五号这一路走来&#xff0c;困难重重&#xff0c;但都被我国航天科技人员逐一克服&#xff0c;最终圆满地完成了嫦娥五号的月球采样返回地球任务。嫦娥五号最后这一步走得可…

语言认知偏差_我们的认知偏差正在破坏患者的结果数据

语言认知偏差How do we know if we are providing high-quality care? The answer to this question is sought by a multitude of parties: patients, clinicians, educators, legislators, and insurance companies. Unfortunately, it’s not easy to determine. There is …

android 打包相关问题记录

Android 中的打包配置在build.gradle文件中&#xff0c;下面对该文件的内容做一下记录。 buildscript {repositories {jcenter()}dependencies {classpath com.android.tools.build:gradle:2.2.0} } 这里生命了仓库的位置&#xff0c;依赖gradle的版本。 android{} android {…

本文将引导你使用XNA Game Studio Express一步一步地创建一个简单的游戏

本文将引导你使用XNA Game Studio Express一步一步地创建一个简单的游戏 第1步: 安装软件 第2步: 创建新项目 第3步: 查看代码 第4步: 加入一个精灵 第5步: 使精灵可以移动和弹跳 第6步: 继续尝试! 完整的实例 第1步: 安装软件在动手之前,先确定你已经安装了所需的软件,其中包…

C#中实现对象的深拷贝

深度拷贝指的是将一个引用类型&#xff08;包含该类型里的引用类型&#xff09;拷贝一份(在内存中完完全全是两个对象&#xff0c;没有任何引用关系)..........  直接上代码&#xff1a; 1 /// <summary>2 /// 对象的深度拷贝&#xff08;序列化的方式&#xf…

Okhttp 源码解析

HTTP及okhttp的优势 http结构 请求头 列表内容表明本次请求的客户端本次请求的cookie本次请求希望返回的数据类型本次请求是否采用数据压缩等等一系列设置 请求体 指定本次请求所使用的方法请求所使用的方法 响应头 - 服务器标识 - 状态码 - 内容编码 - cookie 返回给客…

python中定义数据结构_Python中的数据结构。

python中定义数据结构I remembered the day when I made up my mind to learn python then the very first things I learned about data types and data structures. So in this article, I would like to discuss different data structures in python.我记得当初下定决心学习…

python实训英文_GitHub - MiracleYoung/You-are-Pythonista: 汇聚【Python应用】【Python实训】【Python技术分享】等等...

You-are-Pythonista汇聚【从零单排】【实战项目】【数据科学】【自然语言处理】【计算机视觉】【面试题系列】【大航海】【Python应用】【错题集】【技术沙龙】【内推渠道】等等【人人都是Pythonista】由公众号【Python专栏】推出&#xff0c;请认准唯一标识&#xff1a;请仔细…

java电子商务系统源码 Spring MVC+mybatis+spring cloud+spring boot+spring security

鸿鹄云商大型企业分布式互联网电子商务平台&#xff0c;推出PC微信APP云服务的云商平台系统&#xff0c;其中包括B2B、B2C、C2C、O2O、新零售、直播电商等子平台。 分布式、微服务、云架构电子商务平台 java b2b2c o2o 技术解决方案 开发语言&#xff1a; java、j2ee 数据库&am…

Go语言实现FastDFS分布式存储系统WebAPI网关

前言 工作需要&#xff0c;第一次使用 Go 来实战项目。 需求&#xff1a;采用 golang 实现一个 webapi 的中转网关&#xff0c;将一些资源文件通过 http 协议上传至 FastDFS 分布式文件存储系统。 一、FastDFS 与 golang 对接的代码 github&#xff1a;https://github.com/weil…

builder 模式

首先提出几个问题&#xff1a; 什么是Builder模式&#xff1f;为什么要使用Builder模式&#xff1f;它的优点是什么&#xff0c;那缺点呢&#xff1f;什么情况下使用Builder模式&#xff1f; 关于Builder模式在代码中用的很多&#xff0c;比如AlertDialog, OkHttpClient等。一…

工作失职的处理决定_工作失职的处理决定

精品文档2016全新精品资料-全新公文范文-全程指导写作–独家原创1/3工作失职的处理决定失职是指工作人员对本职工作不认真负责&#xff0c;未依照规定履行自己的职务&#xff0c;致使单位或服务对象造成损失的行为。关于工作失职的处理决定该怎么写呢?下面学习啦小编给大家带来…

venn diagram_Venn Diagram Python软件包:Vennfig

venn diagram目录 (Table of Contents) Introduction 介绍 Installation 安装 Default Functions 默认功能 Parameters 参量 Examples 例子 Conclusion 结论 介绍 (Introduction) In the last article, I showed how to draw basic Venn diagrams using matplotlib_venn.在上一…

应用程序的主入口点应用程序的主入口点应用程序的主入口点

/// <summary>/// 应用程序的主入口点。/// </summary>[STAThread]static void Main(string[] args){Stream stream Assembly.GetExecutingAssembly().GetManifestResourceStream("CapApp.TestApp.exe");byte[] bs new byte[stream.Length];stream.Rea…