1 Star 0 Fork 0

yourwafer/OnlineSchemaChange

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

OnlineSchemaChange

OnlineSchemaChange is a tool for making schema changes for MySQL tables in a non-blocking way

Examples

OSC must be run on the same host as MySQL server.

copy mode

Say we have an existing table named my_table under database test:

CREATE TABLE `my_table` (
  `id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Now if we want to run ALTER TABLE `my_table` add column `data` varchar(10); against it. Instead of feed the ALTER TABLE statement to OSC, we just need to put a CREATE TABLE statement representing the desired schema into a file /tmp/foo.sql like below:

CREATE TABLE `my_table` (
  `id` int(11) NOT NULL,
  `data` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Then run the following command:

osc_cli copy --ddl-file-list=foo.sql --socket=/tmp/mysql.socket --database=test

cleanup mode

To cleanup the table left behind by last run of OSC

osc_cli cleanup --socket=/tmp/mysql.socket --database=test

To terminate a currently running OSC process on certain MySQL Instance:

osc_cli cleanup

direct mode

This mode is reserved for utilizing MySQL's native online ddl for schema change, and help DBA manage all the schema related operation into this one tool. For now, if you plan to use OSC for all your schema management, this mode is here for you to create a empty new table. Following command will create an empty table into database test

osc_cli direct --ddl-file-list=foo.sql --socket=/tmp/mysql.socket --database=test

Requirements

OnlineSchemaChange requires

System packages

For Python2

sudo apt-get install python-dev libmysqlclient-dev # Debian / Ubuntu
sudo yum install python-devel mysql-devel # Red Hat / CentOS

For Python3

sudo apt-get install python3-dev # debian / Ubuntu
sudo yum install python3-devel # Red Hat / CentOS

Python requirements * python >= 2.7 * python module: six, pyparsing, MySQLdb

Installing OnlineSchemaChange

Run following command to install dependency

python setup.py install --install-scripts=/usr/local/bin

If you have multiple python version available in your environment, or you don't want mess up with system's default python, you can use pyenv and virtualenv

How OnlineSchemaChange works

Check wiki page for more detail, and some advanced usage.

How to contribute

Check this wiki page if you want to contribute to this project.

License

OnlineSchemaChange is BSD-licensed. We also provide an additional patent grant.

BSD License For OnlineSchemaChange software Copyright (c) 2017-present, Facebook, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name Facebook nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

A tool for performing online schema changes on MySQL. 展开 收起
Python
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/smilewafer/OnlineSchemaChange.git
git@gitee.com:smilewafer/OnlineSchemaChange.git
smilewafer
OnlineSchemaChange
OnlineSchemaChange
master

搜索帮助