zoukankan      html  css  js  c++  java
  • mysql常用命令整理

    目录

    1.数据类型

    2.运算符

    数学运算符

    加减乘除,模除

    select 10+3, 10-3, 10*3, 10/3, mod(10,3);

     

    逻辑运算符

    与,或,非

    select 1|0, 1&0, !1;

    异或

    3.函数

    数学函数

    select abs(-1), pi(), sqrt(4), ceil(9.9), floor(9.9), round(9.9), round(9.1), sign(-3), pow(2,3), log(2,4);

     字符串函数

    select char_length('abc'), concat('abc', '--', 'abc');

    日期函数

    select curdate(), now(), current_timestamp(), year(now()), month(now()), day(now());

    其他

    select user(), version();

    4.sql语句

    库相关

    create database  db1;

    drop  database  db1;

    create database if not exists sbtest;

    drop database if exists sbtest;

    表相关

    创建

    create table t1 (id int);

    rename table t1 to t2;

    create table lr_db.t1(id int primary key, id2 int);

    创建表,自增

    create table t1(id int auto

    创建表,主键

    create table t0(id int primary key, id2 int);

    查看表

    show tables;

    show tables from liurong_database;

    show columns from lr_db.t1;   #等价于desc lr_db.t1;

    desc t2;

    desc lr_db.t1;

    修改表结构

    增加列

    alter table t1 add id3 int;

    删除列

    alter table t1 drop id3;

    show table statusG

    删除表

    drop table t3;

    update

    replace

    查看sql语句执行计划

    只需要在sql语句前加上关键词‘explain’

    explain insert into t1 values (1, 5);

    关于explain返回的各字段含义可以自行搜索。

    主键

    增加主键

    create table t4( id int, id2 int, primary key(id));

    create table t3( id int primary key, id2 int);

    删除主键

    alter table t3 drop primary key;

    视图

    创建视图

    create view see_t3 as select * from t3;

    create view see_t4 as select * from t4;

    视图

    drop view if exists see_t4;

    用户管理

    创建用户,设置其密码为LIUrong123@

    create user 'lr'@'%';

    set password for 'lr'@'%' = password('LIUrong123@');

    另一种方法:

    create user 'lr01'@'%' identified by 'LIUrong123@';

    查看用户的各项权限

    select * from mysql.user where user = 'lr'G;

    给用户赋予权限

    all privileges表示赋予所有权限,*.*的第一个*表示数据库,第2个*是库中的表。所以下面sql语句表示给lr01用户赋予了所有数据库表的所有权限。

    grant all privileges on *.* to 'lr01'@'%' identified by 'LIUrong123@';

    可以只赋予select权限

    grant select on *.* to 'lr01'@'%' identified by 'LIUrong123@';

    与grant相对应的是revoke(回收权限)

    revoke  select  on  *.*  from  'lr01'@'%';

  • 相关阅读:
    关于递归的理解
    every few days
    相见恨晚
    VC中自定义消息处理函数的步骤
    wparam和lparam的区别
    VC中新建的类不见了的解决方法
    接连遇到大牛
    老总NB的 romman.sys
    [恢]hdu 1159
    [恢]hdu 1996
  • 原文地址:https://www.cnblogs.com/liurong07/p/12810531.html
Copyright © 2011-2022 走看看