ラベル MySQL の投稿を表示しています。 すべての投稿を表示
ラベル MySQL の投稿を表示しています。 すべての投稿を表示

2015年7月23日木曜日

MySQLを読む(1) ソースコードからのビルド

MySQLのソースコードを読む。

参考:詳解MySQL オライリー Sasba Pacbev著/伊藤直也、田中慎司、吉川英興 監訳/菅野良二訳

目標:
・SQLパーサー&オプティマイザ部分の理解

ビルド参考:
開発ソースツリーを使用して MySQL をインストールする

環境はAWS EC2 t1.microインスタンス

1、ソースの取得


[centos@mirage mysql-server]$ git clone https://github.com/mysql/mysql-server.git
[centos@mirage mysql-server]$ git branch -r
  origin/5.5
  origin/5.6
  origin/5.7
  origin/HEAD -> origin/5.7
  origin/cluster-7.2
  origin/cluster-7.3
  origin/cluster-7.4
[centos@mirage mysql-server]$ git branch
  5.6
* 5.7

2、ビルド環境の準備


動きを追うためデバッグオプションつきでビルド。

[centos@mirage mysql-server]$ cd bld_debug/
[centos@mirage bld_debug]$ cmake .. -DCMAKE_BUILD_TYPE=Debug
-- Running cmake version 2.8.11
-- Found Git: /usr/bin/git (found version "1.8.3.1") 
-- Configuring with MAX_INDEXES = 64U
-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is GNU 4.8.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for SHM_HUGETLB
-- Looking for SHM_HUGETLB - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void *
-- Check size of void * - done
-- SIZEOF_VOIDP 8
-- MySQL 5.7.7-rc
-- Packaging as: mysql-5.7.7-rc-Linux-x86_64
-- Looked for boost/version.hpp in  and 
-- BOOST_INCLUDE_DIR BOOST_INCLUDE_DIR-NOTFOUND
-- LOCAL_BOOST_DIR 
-- LOCAL_BOOST_ZIP 
-- Could not find (the correct version of) boost.
-- MySQL currently requires boost_1_57_0

CMake Error at cmake/boost.cmake:76 (MESSAGE):
  You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=

  This CMake script will look for boost in .  If it is not there,
  it will download and unpack it (in that directory) for you.

  If you are inside a firewall, you may need to use an http proxy:

  export http_proxy=http://example.com:80

Call Stack (most recent call first):
  cmake/boost.cmake:228 (COULD_NOT_FIND_BOOST)
  CMakeLists.txt:452 (INCLUDE)


-- Configuring incomplete, errors occurred!

こけた
5.7ではboostが必要らしい

最新版にはこだわらないので5.6に切り替えてリトライ

[centos@mirage bld_debug]$ pwd
/home/centos/mysql-server/bld_debug
[centos@mirage bld_debug]$ cd ..
[centos@mirage mysql-server]$ git checkout 5.6
Switched to branch '5.6'
[centos@mirage mysql-server]$ 

[centos@mirage mysql-server]$ cd bld_debug/
[centos@mirage bld_debug]$ cmake .. -DCMAKE_BUILD_TYPE=Debug
-- Running cmake version 2.8.11
-- Found Git: /usr/bin/git (found version "1.8.3.1") 
-- Configuring with MAX_INDEXES = 64U
-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is GNU 4.8.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
........................省略
-- Check size of wint_t - done
-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH) 
CMake Error at cmake/readline.cmake:85 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:128 (FIND_CURSES)
  cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:409 (MYSQL_CHECK_EDITLINE)


-- Configuring incomplete, errors occurred!

こけた

cursesインストール

$ sudo yum install ncurses-devel

リトライ

[centos@mirage bld_debug]$ rm -rf *
[centos@mirage bld_debug]$ cmake .. -DCMAKE_BUILD_TYPE=Debug
-- Running cmake version 2.8.11
-- Found Git: /usr/bin/git (found version "1.8.3.1") 
-- Configuring with MAX_INDEXES = 64U
-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is GNU 4.8.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
........................省略
-- Library mysqlclient depends on OSLIBS -lpthread;m;dl
-- Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.
-- If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80
-- Library mysqlserver depends on OSLIBS -lpthread;m;crypt;dl
-- CMAKE_BUILD_TYPE: Debug
-- COMPILE_DEFINITIONS: HAVE_CONFIG_H
-- CMAKE_C_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement -Werror
-- CMAKE_CXX_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter -Werror
-- CMAKE_C_FLAGS_DEBUG: -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DENABLED_DEBUG_SYNC
-- CMAKE_CXX_FLAGS_DEBUG: -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DENABLED_DEBUG_SYNC
-- Configuring done
-- Generating done
-- Build files have been written to: /home/centos/mysql-server/bld_debug

できた

3、ビルド実行


[centos@mirage bld_debug]$ make
Scanning dependencies of target INFO_BIN
[  0%] Built target INFO_BIN
Scanning dependencies of target INFO_SRC
[  0%] Built target INFO_SRC
Scanning dependencies of target abi_check
[  0%] Built target abi_check
Scanning dependencies of target zlib
[  0%] Building C object zlib/CMakeFiles/zlib.dir/adler32.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/compress.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/crc32.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/deflate.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/gzio.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/infback.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/inffast.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/inflate.c.o
........................省略
Scanning dependencies of target mysql_client_test_embedded
[ 98%] Building C object libmysqld/examples/CMakeFiles/mysql_client_test_embedded.dir/__/__/tests/mysql_client_test.c.o
Linking CXX executable mysql_client_test_embedded
[ 98%] Built target mysql_client_test_embedded
Scanning dependencies of target mysql_embedded
[ 98%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/completion_hash.cc.o
[ 99%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/mysql.cc.o
[ 99%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/readline.cc.o
Linking CXX executable mysql_embedded
[ 99%] Built target mysql_embedded
Scanning dependencies of target mysqltest_embedded
[100%] Building CXX object libmysqld/examples/CMakeFiles/mysqltest_embedded.dir/__/__/client/mysqltest.cc.o
Linking CXX executable mysqltest_embedded
[100%] Built target mysqltest_embedded
Scanning dependencies of target my_safe_process
[100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o
Linking CXX executable my_safe_process
[100%] Built target my_safe_process

できた
大体7~8分程度 10分はかかってないと思う

4、テスト


[centos@mirage bld_debug]$ make test
Running tests...
Test project /home/centos/mysql-server/bld_debug
      Start  1: hp_test1
 1/21 Test  #1: hp_test1 .........................   Passed    0.01 sec
      Start  2: hp_test2
 2/21 Test  #2: hp_test2 .........................   Passed    0.53 sec
      Start  3: pfs_instr_class
 3/21 Test  #3: pfs_instr_class ..................   Passed    0.01 sec
      Start  4: pfs_instr_class-oom
 4/21 Test  #4: pfs_instr_class-oom ..............   Passed    0.01 sec
      Start  5: pfs_instr
 5/21 Test  #5: pfs_instr ........................   Passed    0.01 sec
      Start  6: pfs_instr-oom
 6/21 Test  #6: pfs_instr-oom ....................   Passed    0.01 sec
      Start  7: pfs_account-oom
 7/21 Test  #7: pfs_account-oom ..................   Passed    0.01 sec
      Start  8: pfs_host-oom
 8/21 Test  #8: pfs_host-oom .....................   Passed    0.01 sec
      Start  9: pfs_user-oom
 9/21 Test  #9: pfs_user-oom .....................   Passed    0.01 sec
      Start 10: pfs
10/21 Test #10: pfs ..............................   Passed    0.73 sec
      Start 11: pfs_connect_attr
11/21 Test #11: pfs_connect_attr .................   Passed    0.11 sec
      Start 12: regex1
12/21 Test #12: regex1 ...........................   Passed    0.01 sec
      Start 13: regex2
13/21 Test #13: regex2 ...........................   Passed    0.00 sec
      Start 14: regex3
14/21 Test #14: regex3 ...........................   Passed    0.00 sec
      Start 15: queues_test
15/21 Test #15: queues_test ......................   Passed    0.29 sec
      Start 16: simple
16/21 Test #16: simple ...........................   Passed    0.32 sec
      Start 17: skip
17/21 Test #17: skip .............................   Passed    0.00 sec
      Start 18: todo
18/21 Test #18: todo .............................   Passed    0.00 sec
      Start 19: skip_all
19/21 Test #19: skip_all .........................   Passed    0.00 sec
      Start 20: no_plan
20/21 Test #20: no_plan ..........................   Passed    0.00 sec
      Start 21: basic
21/21 Test #21: basic ............................   Passed    0.00 sec

100% tests passed, 0 tests failed out of 21

Total Test time (real) =   2.14 sec
[centos@mirage bld_debug]$ 



できた


5、デバッガインストール

動作を確認するためにデバッガを入れておく

$ sudo yum install gdb

2015年7月18日土曜日

CentOS7 on Amazon EC2(2) MySQL

CentOS7では、mariaDBなるDBになっているらしい!
Wikipedia MariaDB

1、インストール

mysqlをインストールしようとするとmariadbがインストールされる

$ sudo yum install mysql
Loaded plugins: fastestmirror
....
Dependencies Resolved

================================================================================
 Package             Arch          Version                    Repository   Size
================================================================================
Installing:
 mariadb             x86_64        1:5.5.41-2.el7_0           base        8.9 M
Installing for dependencies:
 mariadb-libs        x86_64        1:5.5.41-2.el7_0           base        754 k

Transaction Summary
================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 9.7 M
Installed size: 53 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): mariadb-libs-5.5.41-2.el7_0.x86_64.rpm              | 754 kB   00:00     
(2/2): mariadb-5.5.41-2.el7_0.x86_64.rpm                   | 8.9 MB   00:00     
--------------------------------------------------------------------------------
Total                                               12 MB/s | 9.7 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:mariadb-libs-5.5.41-2.el7_0.x86_64                         1/2 
  Installing : 1:mariadb-5.5.41-2.el7_0.x86_64                              2/2 
  Verifying  : 1:mariadb-5.5.41-2.el7_0.x86_64                              1/2 
  Verifying  : 1:mariadb-libs-5.5.41-2.el7_0.x86_64                         2/2 
Installed:
  mariadb.x86_64 1:5.5.41-2.el7_0                                               
Dependency Installed:
  mariadb-libs.x86_64 1:5.5.41-2.el7_0                                          
Complete!

2、バージョン確認

$ mysql --version
mysql  Ver 15.1 Distrib 5.5.41-MariaDB, for Linux (x86_64) using readline 5.1
mariadbになっている

3、Serverインストール

$ sudo yum install mariadb-server

4、サービス確認

$ systemctl list-unit-files | grep mariadb
mariadb.service                        disabled
無効になっている

5、サービス有効化

$ sudo systemctl enable mariadb.service
ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
$ systemctl list-unit-files | grep mariadb
mariadb.service                        enabled 

6、サービス起動

$ sudo systemctl start mariadb.service

2014年9月14日日曜日

MySQLのバックアップ

mysqlのバックアップにはmysqldumpを使うことにした

●参考
mysqldump に必要な権限
http://blog.enjoitech.jp/article/200

●権限設定
create user 'dbuser'@'localhost';
grant file on *.* to 'dbuser'@'localhost';
grant select,lock tables,show view on dbname.* to 'dbuser'@'localhost';
grant select on mysql.proc to 'dbuser'@'localhost';

●以下のようなシェルを作成
ファイル名にタイムスタンプを持たせ世代管理
なおかつ古いファイルは削除するようにした
#!/bin/bash

dttm=`date +%Y%m%d_%H%M%S`
filename=mydb_${dttm}.dmp.gz
outdir=~/out/dir/to/bkup/

echo mysqldump to ${outdir}/${filename} start

mysqldump mydb | gzip >${outdir}/${filename}

echo mysqldump end

echo delete old archive start
list=`find ${outdir} -mtime +30`
rm -v -f ${list}
echo delete old archive end

2014年5月14日水曜日

MySQLのRaspberryへの移行

Eclipseの接続先をRaspberryPiに向ける

1、Glassfish コンソール起動(localhost:4848)
2、接続プールの編集
  リソース - JDBC - JDBC接続プール - 追加プロパティ タブの URL,user,password を編集
3、Eclipseで接続確認して、OK!

●今後(短期課題)
中(1)一覧画面のページング処理実装
済(2)開発DB環境をRaspberry Piに移行する。
未(3)マスタメンテ画面のテンプレート化

●今後(中期課題)
 (1)本番環境をRaspberry Pi上へ構築する


●今後(長期課題)
 (1)外部公開(Internet経由で入力・参照できるようにする)
 (2)記入用Androidアプリの開発

MySQLの移行



開発用にCentOS上に立てていたMySQLを、Raspberry Pi上に移行する。
さらにMySQL 5.1系(MyISAM)から5.5系(InnoDB)への移行も行う

●移行手順(概要)
1、新MySQL上にDBを作る
2、旧MySQLからmysqldumpでDBをダンプする
3、ダンプ内のEngine設定をMyISAMからInnoDBに変更
4、新MySQL上にダンプをインポートする

●移行手順(詳細)
1、新MySQL上にDBを作る
mysql> create database test;

2、旧MySQLからmysqldumpでDBをダンプする
$ mysqldump -u root -p kakei > kakei.sql

3、ダンプ内のEngine設定をMyISAMからInnoDBに変更
$ vi kakei.sql
%s/MyISAM/InnoDB/g

4、新MySQL上にダンプをインポートする
$ mysql -u kowner -p KakeiWebDev < kakei.sql

一部、キー長が長すぎるなど怒られたが、適宜ダンプを修正し再実行でOK。

●参考
MySQL(DB)の移行

MySQLのデータベースを別サーバーに移行する

Useful sed / awk liners for MySQL


2014年5月12日月曜日

MySQLの設定

KakeiWeb開発をRaspberry Piで行うにあたり、mysqlのセットアップを済ませておく

●MySQLの設定
1、セキュア設定
$ sudo mysql_secure_installation

2、my.cnfの編集
文字化け対策、リモート接続を設定する
[mysqld]
...
character-set-server = utf8
# 以下の行はコメントアウト
#bind-address           = 127.0.0.1

[client]
...
default-character-set=utf8

編集したら、再起動
$ sudo service mysql restart

3、ユーザーの作成
$ mysql -u root -p
mysql> grant all privileges on KakeiWebDev.* to dbuser@localhost identified by 'xxxx';
mysql> grant all privileges on KakeiWebDev.* to dbuser@'111.111.111.%' identified by 'xxxx';

4、ポート開放
$ sudo ufw allow 3306/tcp

5、データベースの作成
mysql> create database KakeiWebDev;

2014年5月9日金曜日

KakeiWeb開発日記(1)

プログラミングスキル維持のため、家計簿システム(KakeiWeb)を作ろうという試み。

●構成
OS:Linux(Raspbian)
Web/AP:GlassFish
アプリケーションフレームワーク:Java EE(JFS+JPA)
バッチ処理:Java+cron
DB:MySQL

●現時点の状況
永続化、画面遷移、その他もろもろ理解を目的として
マスターメンテ画面(クレジットカードマスター)を作成中。
リスト表示、メンテ画面表示、永続化まで一応動く状態。

●今後(短期課題)
(1)一覧画面のページング処理実装
(2)トランザクション開始・終了のスマートな実装
 JTAでトランザクションを実装しているが投げてくるexceptionが多くcatch実装が面倒。
 スマートなやり方を検討する
(3)環境をRaspberry Piに移行する。