###一键偷懒YUM安装MySQbL###

1.安装mysql数据库

#yum install -y mariadb-server  mariadb

2.登录mysql数据库常用选项

  -h:指定服务端主机地址
  -u: 指定登入的用户名
  -p:指明密码
  -D:指明登入的数据库
  -e:连接之后直接运行SQL语句,不进入交互式模式(可以在脚本中使用)

3.mysql语言分为3大类

  DDL:数据库定义语言  create , alter , drop

  DML:数据库操作语言  insert , delete , update , select

  DCL:数据库控制语言  grant , revoke

4.数据库DDL语言

  创建库  create database zxxsql;

  删除库  drop database zxxsql;
  修改库   alter database zxxsql character set = utf8

  创建表    create table home (id int not null primary key auto_increment, name varchar(250) not null, class varchar(250) not null);
  
查看表结构    desc home;
  
修改表
      
添加字段:alter table home add gender enum('f','m');
      
删除字段:alter table home drop gender;
      
修改字段
           alter table home change name username varchar(100) after id;
           alter table home modify username varchar(100) first;
  
删除表:drop table home;
5.数据库DML语言

  <1>insert     在home表中插入3组class和username数据。

    insert into home (class,username) values ('ops', '运维开发'), ('opsdev', '运维开发'), ('开发', 'java开发');

  <2>update     修改home表数据

    update home set class = '开发部门' where id = 1;

  <3>delete  删除表数据

    delete from home where class = '开发';

  <4>select

    查询表上的所有的数据   select * from home;
    查询部分数据  select id,class from home;
    # 还可以取个别名    select id as num,class from home;

    使用where子句过滤
      # 可以使用的算数运算符:>, < , >=, <=, ==, !=
      # 可以使用连接词:and , or
      select * from home where id >= 2;
      select * from home where id <= 2 and id >1;
      select * from home where id between 1 and 2;

    # 可以使用like做模糊匹配(%:表示任意长度的字符,_:表示任意单个字符)
    select * from home where class like 'ops%';

    # 可以使用null对值进行判断
    select * from home where id is not null;
    select * from home where id is null;

    使用order指定排序(默认是asc,升序排列)
    select * from home order by id desc;

6.DCL数据库语言

  <1>grant

    #先创建用户,再授权

    create user zxx@'172.16.19.%' identified by '123456';

    grant all on *.* to zxx@'172.16.19.%';
    flush privileges;
    #
创建用户的同时给用户授权
    grant all on *.* to zxx@'172.16.19.%' identified by '123456';
    flush privileges;
    #给用户授予某些权限
    show grants for zxx@'172.16.19.%';

  <2>查看用户权限

    show grants for zxx@'172.16.19.%';

  <3>删除用户

    delete from mysql.user where user = "zxx";
    flush privileges;

7.select 查询语句详解

  -1:where子句:指明过滤条件
    可以使用的算数运算符:+, -, * ,/ ,= ,!= ,<=, >=
    between 较小的数 and 较大的数
    in (较小的数,较大的数)
    is null 或 is not null
    like模糊匹配
    例如:
    select * from home where id >= 2;
    select * from home where id <= 2 and id >1;
    select * from home where id between 1 and 2;
    select * from home where id in (1,2); # 从1和2中取值
    select * from home where class like 'ops%';
    select * from home where id is not null;
    select * from home where id is null;

  -2:group by 子句:根据指定的查询条件将查询结构进行分组,用于做聚合运算
    使用聚合函数:avg( ) , max( ) , min( ) , count( ), sum( )
    select age,gender from students group by gender;
    select avg(age),gender from students group by gender;
    select min(age), gender from students group by gender;
    select max(age), gender from students group by gender;
    select count(id), gender from students group by gender;

  -3:having子句:将分组之后的结果再次过滤
    select avg(age) as 'average_age', gender from students group by gender having average_age > 50;

  -4:order by子句 :根据指定的字段对查询结果进行排序,默认为升序,降序使用关键字desc
    select name,age from students order by age desc;

  -5:limit 子句:对查询的结果进行输出行数的限制
    select name,age from students order by age desc limit 8; # 选前8行
    select name,age from students order by age limit 4, 2; # 前4个不选,从第五行开始选2行

###总结单表查询次序##########################################################################################################################

子句的书写顺序:
where -> group by -> having -> order by -> limit

例如:                                                              
select *,avg(score) as '各班平均成绩' from students where id > 1 group by class having avg(score) > 55 order by score desc limit 3 ;  #

#############################################################################################################

my_mysql的更多相关文章

  1. mysqli_set_charset和SET NAMES优劣分析

    bool mysqli_set_charset ( mysqli $link , string $charset ) 这应该是首选的用于改变字符编码的方法,不建议使用 mysqli_query()执行 ...

  2. linux一些工具的安装(三)

    linux(vmware15   centos7)中Docker安装 一.Docker卸载 1.查看已安装的docker安装包 $yum list installed|grep docker 执行后的 ...

  3. Docker: 创建带数据的MySql container

    如果需要想要在一个装有docker的机器上启动一个MySql的container,并且整个MySql container有我想要的数据: 1. 先在已有的MySql instance上准备好数据 2. ...

  4. Docker容器学习梳理 - 应用程序容器环境部署

    关于国内Docker镜像,可以参考:Docker容器学习梳理--基础知识(2) 的Docker镜像使用. 如果我们需要在Docker环境下部署tomcat.redis.mysql.nginx.php等 ...

  5. cenos7.0 安装docker

    使用yum命令在线安装  yum install docker 安装后查看Docker版本 docker -v启动docker:systemctl start docker停止docker:syste ...

  6. PHP API中,MYSQL与MYSQLI的持久连接区别

    转载自:http://www.cnxct.com/some-differences-between-mysql-and-mysqli-of-persistent-connection/ 很久很久以前, ...

  7. Python爬虫(八)

    源码: import requests import re from my_mysql import MysqlConnect import time,random # 获取招聘详情链接 def ge ...

  8. Python爬虫(七)

    源码: import requests import re from my_mysql import MysqlConnect # 获取详情页链接和电影名称 def get_urls(page): u ...

  9. Python爬虫(六)

    源码: import requests import re from my_mysql import MysqlConnect # 获取问答信息 def get_contents(page,heade ...

随机推荐

  1. Top 10 open source projects of 2015

    Top 10 open source projects of 2015 Posted 15 Dec 2015Jen Wike Huger (Red Hat)Feed 188 up 31 comment ...

  2. 通过Ajax提交form表单来提交上传文件

    Ajax 提交form方式可以将form表单序列化 然后将数据通过data提交至后台,例如: $.ajax({      url : "http://localhost:8080/" ...

  3. PHP内置服务器

    PHP在安装的时候会内置了服务器的功能,我们在使用的过程中如果只是调试,可以选择启动PHP内置的服务器,下面是windows下PHP内置服务器的启动步骤: 1.将php的D:\phpStudy\php ...

  4. 分布式TensorFlow集群local server使用详解

    通过local server理解分布式TensorFlow集群的应用与实现. ​​简介 TensorFlow从0.8版本开始,支持分布式集群,并且自带了local server方便测试. Local ...

  5. 基于thinkphp实现根据用户ip判断地理位置并提供对应天气信息的应用

    https://blog.csdn.net/MyCodeDream/article/details/46706469 我们都知道,在很多的网站都提供了给用户提供天气预报的功能,有时会发现,用户即使不输 ...

  6. python深浅copy和赋值

    Python直接赋值,浅copy和深copy的比较 基于引用和对象(python引用和对象分离) 总结: 直接赋值:a = b -->a,b两个引用指向相同的对象 浅copy:a为b的copy ...

  7. Yarn install 报错 Resolving packages... [2/4] Fetching packages... info There appears to be trouble with your network connection. Retrying

    1.设置淘宝代理 yarn config set registry 'https://registry.npm.taobao.org' 2.如果网址本地可以打开,说明你本地有代理设置 所以需要按本地的 ...

  8. win10 uwp 在 Canvas 放一个超过大小的元素会不会被裁剪

    我尝试在一个宽度200高度200的 Canvas 放了一个宽度 300 高度 300 的元素,这个元素会不会被 Canvas 裁剪了? 经过我的测试,发现默认是不会被裁剪 火火问了我一个问题,如果有一 ...

  9. UVA 11922 Permutation Transformer —— splay伸展树

    题意:根据m条指令改变排列1 2 3 4 … n ,每条指令(a, b)表示取出第a~b个元素,反转后添加到排列尾部 分析:用一个可分裂合并的序列来表示整个序列,截取一段可以用两次分裂一次合并实现,粘 ...

  10. UVa 1627 - Team them up!——[0-1背包]

    Your task is to divide a number of persons into two teams, in such a way, that: everyone belongs to ...