MYSQL 常用查询sql


目的

个人笔记,便于后续的查找。


一、记录原因

在这里插入图片描述

工作中难免会遇到上述涉及到权限的问题,这个时候的办法最快捷的大概有两个:1.麻烦公司的dba修改权限;2.请示上级后自己修改权限。

二、具体内容

1.查看当前用户的权限,注赋权时候最好根据实际情况来缺什么给什么,方便问题的排查,赋权结束后最好重新登录:

show grants for test;--查看现有的权限
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON dataA.test TO 'test'@'%';-- 赋予缺失的权限
flush privileges;--最后执行

2.其他常用的运维sql

--查询一个数据库中表名字
select table_name from information_schema.tables where table_schema='aa';
--查询表的创建时间
select create_time from information_schema.tables where table_schema='aa' and table_name in ('xx','yy');
-- 获取包含字段'zxl'的所有表
select table_name,column_name,data_type,column_type,column_comment from information_schema.columns where column_name='zxl' and table_schema='aa'-- mysql 查看某个数据库中所有表的数据量
select table_name,table_rows from information_schema.tables where TABLE_SCHEMA = 'zxl_test' order by table_rows desc;
-- mysql在终端执行sql并把结果写入文件的方法
mysql -h127.0.0.1  -P 3306 -u zxl -pzxl456 -N </home/zxl/sql/tmp/zxl.sql >/home/zxl/sql/tmp/zxl.txt
-- 查询索引
select CONCAT('create index ',INDEX_NAME,' on ',table_name,'(',GROUP_CONCAT(COLUMN_NAME),');') from information_schema.STATISTICS where table_name in ('cs_zxl') and TABLE_SCHEMA='aa' and INDEX_NAME<>'PRIMARY' group by table_name,index_name 
-- 根据已存在的表创建备份表
create table xstext as select * from cs_zxl
-- 添加表字段
alter table table1 add transactor varchar(10) not Null;
alter table   table1 add id int unsigned not Null auto_increment primary key;
-- 修改某个表的字段类型及指定为空或非空
alter table 表名称 change 旧字段名称 新字段名称 字段类型 [是否允许非空];
alter table 表名称 modify 字段名称 字段类型 [是否允许非空];
alter table 表名称 modify 字段名称 字段类型 [是否允许非空];
-- 修改某个表的字段名称及指定为空或非空
alter table 表名称 change 字段原名称 字段新名称 字段类型 [是否允许非空]
-- 如果要删除某一字段,可用命令:
ALTER TABLE mytable DROP 字段名;
-- 重命名表
alter table  旧名 rename 新名; 

总结

记录于此作为后续自己的回忆,也便于自己的查找,后续有需要会继续更新。。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值