zoukankan      html  css  js  c++  java
  • mysql

    MAC下安装mysql
     安装mysql:brew install mysql 
    查看mysql运行状态:ps -ef | grep mysql 
    启动mysql:sudo systemctl start mariadb.service
    启动mysql:mysql.server start
    导入数据:进入 .sql的文件目录下,见一个数据库yongda
    create database yongda;
    mysql -uroot -p yongda < yongda.sql 
    进入mysql查看爬去的数据是否存储
    启动数据库:sudo systemctl start mariadb
    在projects/cr_clawer/.git下输入  mysql -uroot -p 输入密码进入mysql
    查看所有数据库:show databases;
    查看所有表:show tables;
    查找所需要的组:show tables like “cl%”;
    select * from smart_proxy_proxyip;
    select count(*) from smart_proxy_proxyip;
    select count(distinct(company_key))* from smart_proxy_proxyip;
    select * from smart_proxy_proxyip limit 10;
    select count(*) from smart_proxy_proxyip [where is_valid=1];
    增加一行
    INSERT INTO customers(cut_name,cust_address,causticity,cust
    _state,cust_zip,cust_country,just_contact,cust_email) VALUES('Pep E.LaPew’,’100 Main Street’,'Los Angeles’,’CA’,’90046’,’USA’,’NULL’,’NUll’);
    更新一行,SET命令用来将新值赋给被更新的例
    UPDATE customers SET cust_email=‘elmer@fudd.com’ where cust_id=10005;
    更新多行,where用来告诉MySQL更新哪一行
    UPDATE customers SET cust_email=‘elmer@fudd.com’ ,cust_name=’The Fudds’ where cust_id=10005;
    删除数据
    删除一行:DELETE FROM customers WHERE cust_id =10006;
    删除表:drop database basic;
    删除多行:truncate table
    创建表:create table basic;
                  create table basic(cust_id    int    not NULL AUTO_INCREMENT
                                                   cust _name     char(50)    NOT NULL…..);
    查询字段中最小值: select min(potential) from boss_customerpersonalinformation;
    最大值:max;
    平均值:avg;
    查看两个表的数据:select * from 20160819_ind_comm_pub_reg_modify as a,20160819_basic as b where a.`company_key`=b.`company_key`  and b.`enter_name` like '%江苏%'
    SET  @row_number = 0;
      select a.`potential`,(@row_number:=@row_number + 1)  as ROWNUM from boss_customerpersonalinformation as a   where  a.`shop_id`="BU0000462" and a.`brand_id`="BR000005" order by potential
     
    同时添加多个表的数据
    #!/bin/bash
    folder='data_0908/'
    for file in `ls $folder`
    do
        mysql -uroot -p yongda -f < $folder$file
    done
     
    DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据
    DATE_FORMAT(date,format)  date 参数是合法的日期。format 规定日期/时间的输出格式。
    DATE_FORMAT(NOW(),'%b %d %Y %h:%i %p')
    DATE_FORMAT(NOW(),'%m-%d-%Y')
    DATE_FORMAT(NOW(),'%d %b %y')
    DATE_FORMAT(NOW(),'%d %b %Y %T:%f’)
    
    Dec 29 2008 11:45 PM
    12-29-2008
    29 Dec 08
    29 Dec 2008 16:25:46.635

    CONCAT():用来链接两个或者多个字符串

    CONCAT_WS():与CONCAT()类似,但是CONCAT_WS()的第一个参数为分隔符,且CONCAT()有NULL会直接输出

    NULLCONCAT_WS() 代表 CONCAT With Separator ,是CONCAT()的特殊形式。 第一个参数是其它参数的分隔符。分隔符的位置放在要连接的两个字符串之间。分隔符可以是一个字符串,也可以是其它参数。如果分隔符为 NULL,则结果为 NULL。函数会忽略任何分隔符参数后的 NULL 值。

    将2016-08-10减一年,赋值给:so.orderTime:DATE_FORMAT(so.orderTime, '%Y%m') = DATE_FORMAT(
    DATE_ADD('2016-08-10',INTERVAL - 1 YEAR)

     
  • 相关阅读:
    BUGFREE安装等
    常用网站
    Mongodb
    python资源
    HTTP协议详解(经典)
    Jmeter工具
    一.移动app测试与质量保证
    我发现涯哥特有才。各种跳,组合式
    原来如此
    我真庆幸我看过那本书。
  • 原文地址:https://www.cnblogs.com/liuqingqing/p/6750072.html
Copyright © 2011-2022 走看看