Skip to content

Instantly share code, notes, and snippets.

@hachi-eiji
Last active October 13, 2015 03:58
Show Gist options
  • Save hachi-eiji/4136117 to your computer and use it in GitHub Desktop.
Save hachi-eiji/4136117 to your computer and use it in GitHub Desktop.
MySQL Memo
curl -O http://download.softagency.net/MySQL/Downloads/MySQL-5.5/mysql-5.5.28.tar.gz
sudo -s
groupadd mysql
useradd -g mysql -s /noexits -d /usr/local/mysql mysql
curl -O http://download.softagency.net/MySQL/Downloads/MySQL-5.5/mysql-5.5.28-linux2.6-x86_64.tar.gz
cd /usr/local/
tar xzfv /home/ec2-user/mysql-5.5.28-linux2.6-x86_64.tar.gz
rm -rf mysql
ln -s mysql-5.5.28-linux2.6-x86_64 mysql
ls -l mysql-5.5.28-linux2.6-x86_64
chown -R mysql:mysql /usr/local/mysql/data
./scripts/mysql_install_db --user=mysql
./bin/mysqld_safe --user=mysql --character-set-server=utf8 &
./bin/mysql -uroot
kill <pid>
cd /usr/local/mysql/support-files
cp -p mysql.server /etc/init.d/mysql
cd /etc/init.d/
chmod +x mysql
# redirect sql
echo 'select * from sample_table' | mysql -uroot -t test > result.log
# dump script
echo 'show tables' | mysql -upet -p | grep -P '^(c_)?m_.*' | sed -e 's/^\(.*\)$/mysqldump -upet -ppet pet \1 > dump_\1\.sql/' > mastertables_dump.sh

レプリケーション設定

  1. マスタのバイナリログを控える
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)

mysql> show master status;
+-------------------+----------+--------------+------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000001 |      581 |              |                  |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
  1. master側のMySQL停止
  2. データファイルのコピー コピーするのは
  • data/<database名>のファイル
  • ibdata1のファイル(innodbを使っている時のデータファイル)
  1. slave側でmasterを認識させる

master側でレプリケーション用のユーザを作成する

# localhost はスレーブのIP
grant replication slave on *.* to 'repl'@localhost indentified by 'repl00'

slave側で実行する

change master to 
master_host = 'localhost',
master_user = 'repl',
master_password = 'repl00',
master_log_file = 'master-bin.000001',
master_log_pos = 581;

# slaveを起動
start slave;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment