mysql常用命令selected_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);

1cfaf9a82ba9a8e90eb33c6e8a7666e6.png

字符串函数

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

9154e00b7e606913a5539ccdb8cec0d1.png

日期函数

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

7f8edf2bf4fb8858d587c4192e5b2b2a.png

其他

select user(), version();

53a9b5ff78268eb8f5858eb8ac41a5e1.png

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;

827e89ca5b773590c05718cb079b1f15.png

修改表结构

增加列

alter table t1 add id3 int;

删除列

alter table t1 drop id3;

show table status\G

1e4f417743545dded8a161a5f977b895.png

删除表

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;

5c4bfe49dc20e671df8f9af86a73fa7e.png

视图

drop view if exists see_t4;

用户管理

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

create user 'lr'@'%';

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

7b13a7b105dc55e431d43cd1126bcf6f.png

另一种方法:

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

5b056864a32fc261ac41ad039ad56755.png

查看用户的各项权限

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'@'%';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值