1.对一个表执行ddl(新增字段)会不会阻塞表,影响读写?

在一次项目升级之前需要执行一个新增字段的脚本(alter table...),表的数据量是260多万,执行时间是72秒,感觉略长,不知道会不会影响项目对数据库的操作,故连百度带问一番,得出一些结果。

结论是:执行alter table...会影响读写

2.MySQL官方文档alter table的解释

ALTER TABLE operations that use the COPY algorithm wait for other operations that are modifying the table to complete. After alterations are applied to the table copy, data is copied over, the original table is deleted, and the table copy is renamed to the name of the original table. While the ALTER TABLE operation executes, the original table is readable by other sessions(读,不阻塞) (with the exception noted shortly). Updates and writes to the table started after the ALTER TABLE operation begins are stalled until the new table is ready(更新|写入阻塞), then are automatically redirected to the new table. The temporary copy of the table is created in the database directory of the original table unless it is a RENAME TO operation that moves the table to a database that resides in a different directory.

The exception referred to earlier is that ALTER TABLE blocks reads (not just writes)(读写都会阻塞,当数据库操作.frm文件时) at the point where it is ready to install a new version of the table .frm file, discard the old file, and clear outdated table structures from the table and table definition caches. At this point, it must acquire an exclusive lock. To do so, it waits for current readers to finish, and blocks new reads and writes.

3.总结

肯定会影响写入的,读取会有一段时间的影响,最后决定在升级项目,停服时执行alter table...,这样不会影响写入;

还是要看官方文档,别自己猜。

关于ddl(新增字段)对数据库锁表|读写操作的影响_资料的更多相关文章

  1. informix 数据库锁表分析和解决方法

    一.前言 在联机事务处理(OLTP)的数据库应用系统中,多用户.多任务的并发性是系统最重要的技术指标之一.为了提高并发性,目前大部分RDBMS都采用加锁技术.然而由于现实环境的复杂性,使用加锁技术又不 ...

  2. oracle数据库锁表,什么SQL引起了锁表?ORACLE解锁的方法

    --查询数据库锁表记录 select sess.sid, sess.serial#, lo.oracle_username, lo.os_user_name, ao.object_name, lo.l ...

  3. MySQL基础学习——SQL对数据库进行操作、对数据库的表进行操作

    1.SQL对数据库进行操作: 创建数据库: 语法: create database 数据库名称 [character set 字符集 collate 字符集校对规则];字符集校对规则即所用字符集的数据 ...

  4. Mysql新增字段到大数据表导致锁表

    昨天晚上7点左右,对一张表进行加字段,大概200多万条记录,字段90多个的大表,结果造成mysql锁表,进而导致服务不可用.执行语句如下: ALTER TABLE `sc_stockout_order ...

  5. 解决mySQL数据库锁表问题。

    先用这条命令查询数据库阻塞的进程 SELECT * FROM information_schema.innodb_trx 找到后在根据下图这个字段:try_mysql_thread_id 作为这条数据 ...

  6. Oracle数据库锁表及解锁进程

    下午代码迁移,更新数据库记录时for update语句无法执行,数据库被锁,KILL掉几个进程搞定. Oracle数据库操作中,我们有时会用到锁表查询以及解锁和kill进程等操作,那么这些操作是怎么实 ...

  7. oracle数据库锁表

    在团队开发一个项目的时候,避免不了两个或两个以上的人同时操作某一数据库中的同一张表,这时候,如果一个用户没有提交事务,或者忘记提交事务,那么其他用户就不能对这张表进行操作了,这是很烦人的事情,下面是查 ...

  8. Oracle数据库锁表查询

    --查看数据库最大连接数 select value from v$parameter where name = 'processes'; --更改数据库连接数 alter system scope = ...

  9. Oracle数据库锁表的查询方法以及解锁的方法

    1,锁表语句简单查询方法   select t2.username,t2.sid,t2.serial#,t2.logon_time from v$locked_object t1,v$session ...

随机推荐

  1. 字符是否为SQL的保留字

    要想知道字符是否为MS SQL Server保留字,那我们必须把SQL所有保留字放在一个数据集中.然后我们才能判断所查找的字符是否被包含在数据集中. MS SQL Server保留字: ) = 'ad ...

  2. 【原创】Windows平台下Git的安装与配置

    一.下载     msysgit是Git for Windows版,其Home Page为:http://msysgit.github.io/ 点击页面中“Download”进入下载列表.可根据个人喜 ...

  3. Codechef Bear and Clique Distances

    题目:Bear and Clique Distances 描述:共有N个点,前1—K个点任意两点之间有一条无向边,边的权值为X,再任意给M条边(u,v,w)(不重复),求任意一点到其余各点的最短路. ...

  4. python ----面向对象的三大特性---多态

    多态 多态 不同的子类对象调用相同的父类方法,产生不同的执行结果. 以继承和重写父类方法为前提

  5. LeetCode算法题-Range Addition II(Java实现)

    这是悦乐书的第271次更新,第285篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第138题(顺位题号是598).给定一个m行n列的新二维数组M,其初始值为0.提供一个二 ...

  6. docker容器日志收集方案(方案N,其他中间件传输方案)

    由于docker虚拟化的特殊性导致日志收集方案的多样性和复杂性下面接收几个可能的方案 ​ 这个方案各大公司都在用只不过传输方式大同小异 中间件使用kafka是肯定的,kafka的积压与吞吐能力相当强悍 ...

  7. JAVA—枚举(Enum)学习总结

    1.枚举(Enumeration) 枚举(The Enumeration)接口定义了一种从数据结构中取回连续元素的方式.这种传统接口已被迭代器取代,虽然Enumeration 还未被遗弃,但在现代代码 ...

  8. C++ 既有约定

    Pascal 拼写法: 函数名MultiplyNumbers(),每个单词的首字母都大写 驼峰拼写法: 变量名 firstNumber,第一个单词的首字母采用小写 匈牙利表示法: iFirstNumb ...

  9. ASP.NET Core使用HttpClient的同步和异步请求

    using System; using System.Collections.Generic; using System.Collections.Specialized; using System.I ...

  10. EasyUI datagrid formatter 属性

    easyui的formatter属性可以帮助我们更加灵活的显示数据库中的数据. 比如,我有一个启用禁用字段,使用数字表示,1表示启用,2表示禁用,展示给客户的时候我当然希望是中文的形式. 只需要写这么 ...