理解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#,'');

猜你喜欢

转载自maozhr520.iteye.com/blog/2384933
今日推荐