理解mysql_常用经典sql

1、允许mysql远程连接 
      同4 

    3、查看字符集设置 
       show variables like 'character%'; 

    4、数据库赋权 

      grant all on *.* to 'root'@'%' identified by 'Reset123QWE'; 
      flush privileges; 

      grant 权限名(所有的权限用all) on 库名(*全部).表名(*全部) to ‘要授权的用户名’@’%’(%表示所有的IP,可以只些一个IP) 
     
      grant USAGE on cms.* to testread@'%' identified by '123456'; 
      grant select on cms.* to testread@'%' identified by '123456'; 
      grant all on test.* to 'testread'@'%' identified by '123456'; 

     5、修改mysql密码 
      >use mysql 
      >update user set password=PASSWORD('Reset123QWE') where user='root' 
      >flush privileges 

6、看你的mysql当前默认的存储引擎: 
        mysql> show variables like '%storage_engine%'; 

7、看你的mysql现在已提供什么存储引擎: 
       mysql> show engines; 

8、查看当前隔离级别 
      SELECT @@tx_isolation; 

9、设置全局事务隔离级别 
      set global transaction isolation level read committed; 
          set session transaction isolation level read committed; 

     10、导出mysql 
        mysqldump -uroot -pReset123QWE --all-databases > cms.sql 

11、查看当前连接数配置 
     show variables like 'max_connections'; 

12、设置最大连接数 
     set global max_connections=1000; 

  13、修改my.cnf,配置最大连接数 
    max_connections=2000 

14、获取前1天日期 
   select date_sub(curdate(), interval 1 day); 

15、查询某天的日期 
       SELECT * FROM tb_task_info_20160301 WHERE DATE(create_time) = '2016-03-01' ORDER BY create_time DESC 

16、查询某个库所有表的记录数 
select table_name,table_rows from tables order by TABLE_ROWS desc limit 0,100 

17、忘记密码, 用另一种方式启动 
mysqld --defaults-file="C:\mysql-5.5.39-win32\my.ini" --console --skip-grant-tables 

18. 分组统计 having 
   SELECT domain, COUNT(id) c FROM tb_tencent_cfg_domain GROUP BY domain HAVING(c)>1 

19. 过滤删除 
   DELETE  FROM  tb_tencent_cfg_domain  WHERE (`domain`, `id`) IN ( 
        SELECT v.domain, v.id FROM 
                (SELECT domain, MAX(id) id  FROM tb_tencent_cfg_domain GROUP BY domain HAVING COUNT(id)>1 ) v 
    ) ; 

20.查看sql是否有变化 
       WHERE id = #id#            
            and ifnull(date_format(modify_time,'%Y-%m-%d %H:%i:%s'),'') = ifnull(#modifyTime#,''); 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值