• mysql开发之---每日一得01


    2015年7月7日-------------------------

    1、truncate表会清空建表语句auto_increment的值;某个表的id即是主键也是自增,你能够选择插入随意id值,假设不从1開始插入。从3開始insert,再插入没有id的值时。自增值是4

    2、查看每种引擎的索引大小。来优化数据库參数
    SELECT  ENGINE,  
    ROUND(SUM(data_length) /1024/1024, 1) AS "Data MB",  
    ROUND(SUM(index_length)/1024/1024, 1) AS "Index MB",  
    ROUND(SUM(data_length + index_length)/1024/1024, 1) AS "Total MB",  
    COUNT(*) "Num Tables"  
    FROM  INFORMATION_SCHEMA.TABLES  
    WHERE  table_schema not in ("information_schema", "performance_schema")  
    GROUP BY  ENGINE; 

    3、使用prepare stmt from准备一个动态sql语句时。主要
    (1)被准备的语句定义时必须是会话级的变量不能是local变量,须要加@进行定义。准备后的语句直到会话结束才会丢失。能够使用deallocate prepare stmt消除分配的语句
    表名不确定,检查这个表最大id。从id+1開始插入10行数据
    BEGIN
    -- 在存储过程中,一般的sql中values能够是变量,可是表名、字段名不能是变量
    declare v_xname varchar(20) default 'testincre1';
    delete from test.testincre1 where id=1;
    select ifnull(max(id),0)+1 into @incre from test.testincre1;
    set @end=@incre+10;
    repeat
     set @sql=concat('insert into test.',v_xname,' values(@incre,''yangsq'',now());');
     select @sql;
     prepare stmt from @sql;
     execute stmt;
     deallocate prepare stmt;
    set @incre=@incre+1;
    until @incre=@end end repeat;
    END
    4、sql_slave_skip_counter
    Last_SQL_Error: Error 'Unknown table 'sakila.testrepldb'' on query. Default database: 'sakila'. Query: 'DROP TABLE `testrepldb` /* generated by server */'
    mysql> start slave sql_thread; 报错:会重复运行引起错误的sql,可是io_thread仍然正常会接受
    2015-07-08 10:42:25 12378 [Warning] Slave SQL: If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0
    2015-07-08 10:42:25 12378 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000012' at position 4449, relay log './yaolansvr_slave01-relay-bin.000014' position: 283
    2015-07-08 10:42:25 12378 [ERROR] Slave SQL: Error 'Unknown table 'sakila.testrepldb'' on query. Default database: 'sakila'. Query: 'DROP TABLE `testrepldb` /* generated by server */', Error_code: 1051
    2015-07-08 10:42:25 12378 [Warning] Slave: Unknown table 'sakila.testrepldb' Error_code: 1051
    2015-07-08 10:42:25 12378 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000012' position 4449

    select @@sql_slave_skip_counter;
    stop slave;--或者stop slave sql_thread
    set global sql_slave_skip_counter=1;
    start slave;

    --log-error:
    2015-07-08 10:53:30 12378 [Warning] Slave SQL: If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0
    2015-07-08 10:53:30 12378 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000012' at position 4449, relay log './yaolansvr_slave01-relay-bin.000014' position: 283
    2015-07-08 10:53:30 12378 [Note] 'SQL_SLAVE_SKIP_COUNTER=1' executed at relay_log_file='./yaolansvr_slave01-relay-bin.000014', relay_log_pos='283', master_log_name='mysql-bin.000012', master_log_pos='4449' and new position at relay_log_file='./yaolansvr_slave01-relay-bin.000014', relay_log_pos='410', master_log_name='mysql-bin.000012', master_log_pos='4576' 

    5、从 sqlserver 查询mysql 报错 从数据类型 dbtype_dbtimestamp 转化为 datetime 时出错
    mysql某表datetime类型数据是0028-01-01 00:00:00。插入sqlserver datetime报错,sqlserver datime支持的日期类型范围是1753 年 1 月 1 日到 9999 年 12 月 31 日

    6、replicate的相关參数比較
    --replicate-do-table:没有like pattern的功能,多个表须要指定多次
    --replicate-wild-do-table:用like pattern的功能Example: --replicate-wild-do-table=foo%.bar% replicates only updates that use a table where the database name starts with foo and the table name starts with bar

  • 相关阅读:
    flask框架+上传文件接口实战【软件测试培训】【多测师_王sir】
    读取Excel中的视频文件地址+requests库下载后存入本地文件夹【软件测试培训】【多测师_王sir】
    UI和接口自动化中的设计模式:单例模式【软件测试培训】【多测师_王sir】
    Python+BeautifulReport生成完美的接口自动化测试报告【多测师_王sir】
    Linux命令中查找以.log结尾文件中不包含某个特定字符串这行的内容【多测师_王sir】
    查询多条数据
    django登录装饰接口封装
    django使用redis作为session缓存
    tinymce配置
    django重写authcenticate方法兼容用户、邮箱、密码认证登录
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/8456352.html
Copyright © 2020-2023  润新知