zoukankan      html  css  js  c++  java
  • MySQL相关小技巧

    分享几个很实用的MySQL相关技巧:

     

    1. MySQL中有许多很实用的函数,好好利用它们可以省去很多时间:

    group_concat() 将取到的值用逗号连接,可以这么用:

    select group_concat(distinct id) from table;

    得到的结果类似为: 1,2,3,4,5

    unix_timestamp(), to_days(), now() 这三个函数都是与日期相关的函数,主要用于处理mysql中timestamp类似的数据,可以用于与unix时间戳转换以及比较

    select now(), unix_timestamp(now()), to_days(now());

     

    inet_aton(), inet_ntoa() 这个就不多说了,ip网络字节序列转换函数

    select inet_aton('127.0.0.1'), inet_ntoa(2130706433);

    2. 在操作数据库中很多时候可能会出现字符乱码的情况,这种情况主要是因为数据表使用的编码和数据库默认的编码不一致所造成的,可以利用以下语句改变编码:

    set names utf8

    利用以下语句查看数据表相关信息:

    show create table your_table;

    3. 许多时候在启动MySQL时候会出现

    Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'

    当出现错误的时候去看下错误日志吧,很快就可以解决的。

     

  • 相关阅读:
    Codeforces 777B Game of Credit Cards
    Codeforces 777A Shell Game
    零基础学贪心算法
    1283 最小周长
    容斥原理
    Humble Numbers(丑数) 超详解!
    1284 2 3 5 7的倍数
    1305 Pairwise Sum and Divide
    1347 旋转字符串
    HDU 2549 壮志难酬
  • 原文地址:https://www.cnblogs.com/aLittleBitCool/p/2603727.html
Copyright © 2011-2022 走看看