MySQL

2009-03-05

InnoDB: Error: trying to declare trx to enter InnoDB, but InnoDB: it already is declared.

Bug#20090 のバグで内部ステータスの設定ミスにより、処理の多重度が上がった際、
間違ったステータスによって、エラーと判断してしまうようです。対応策としてはバージョンアップしかないんだとか・・・。対応版は5.0.48移行になります。

090227 11:17:11  InnoDB: Error: trying to declare trx to enter InnoDB, but InnoDB: it already is declared.
TRANSACTION 0 1116880420, ACTIVE 0 sec, process no 6375, OS thread id 1167493472,
thread declared inside InnoDB 0
mysql tables in use 1, locked 1
1 lock struct(s), heap size 368
MySQL thread id 48, query id 1180 192.168.1.10 yaruo_db update

| | コメント (16) | トラックバック (0)

2008-08-04

[mysql] my.cnf設定変更

my.cnf設定の変更内容を動的に変更するには?

設定内容のほぼ全般は、mysqldの再起動が必要かと思っていましたが、結構動的に変更できるようです。下記URLに一覧が表記されています。Var Scope ”Global” or ”Global”となっているものが対象となります。ちなみにそのセッション限りの変更は”set session” 等で変更できます。

http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#option_mysqld_max_allowed_packet

下記例で、DB接続数の変更をしてみます。設定変更後、一度セッションアウトしてから再度確認しても、値が変更された状態となっています。

mysql> set @@global.max_connections=256;
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 256   |
+-----------------+-------+
1 row in set (0.00 sec)

変更後はmy.cnfの修正をしておきましょう。

----------------------------------------

現場で使える MySQL (DB Magazine SELECTION)
MySQL
松信 嘉範
翔泳社翔泳社翔泳社
定価 : ¥ 2,730
2006-03-17
amazonで詳しく見る

| | コメント (0) | トラックバック (0)

2008-06-20

[mysql] やる夫のMySQL設定ミス

Unknown database

正直ネタがないので昨日30分くらい詰まったところを紹介します。 そんなDBは知らないよといっています。DB名が違うのではないでしょうか?

クライアント側から何度も接続できるし・・・DB名も間違ってないよなぁ~と思っていたのですが、”port”を”post”と記述してしまったため、エラーとなっていました。なるほど注意深く見ていた箇所は、DB名とport番号だけ・・・。まぁいいやセットアップできたし。

-----
failed: Unknown database 'yauro_db:post=13306' at /usr/local/yaruo/Data/ObjectDriver/Driver/DBI.pm line 24
-----

# /usr/bin/mysql -h indigo01 -P 13306 yaruo_db
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 32
Server version: 5.0.42-enterprise-gpl-log MySQL Enterprise Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> Bye

----------------------------------------

現場で使える MySQL (DB Magazine SELECTION)
MySQL
松信 嘉範
翔泳社翔泳社翔泳社
定価 : ¥ 2,730
2006-03-17
amazonで詳しく見る

続きを読む "[mysql] やる夫のMySQL設定ミス"

| | コメント (0) | トラックバック (0)

2008-06-09

[mysql] やる夫がクエリサイズに苦戦しているようです。

MySQLエラーメッセージ

テーブルを定義するときに、カラム長を決めますが、どうやらクエリサイズがカラム長をより大きいデータとなってしまったようです。クエリを短くするか、テーブルを定義し直すか、ご利用は計画的に・・・。

DBD::mysql::st execute failed: Data too long for column 'yaruo_neet_data' at row 1 at /usr/local/yaruo/Data/ObjectDriver/Driver/DBI.pm

----------------------------------------

現場で使える MySQL (DB Magazine SELECTION)
Mysql
松信 嘉範
翔泳社翔泳社翔泳社
定価 : ¥ 2,730
2006-03-17
amazonで詳しく見る

| | コメント (0) | トラックバック (0)

2008-05-27

[mysql] やる夫が1台で複数のDBを管理しているようです。

インスタンスについて

データベースシステムのまとまりのことであり、データベースを起動・停止する単位を表します。検証環境にて世代管理をする場合や、リソースの有効活用で、1台のDBにいくつもDBを構築したりすると思います。

複数のDBを管理する

やる夫は、試験環境MySQL-DBを構築していて、1台のサーバ内で、複数のインスタンス構成を取り、世代管理運用をしていました。yaruoシステムがver2.0にアップするため、ver2.0検証用のDBを作成することになりました。今回はver1.5を削除して、ver2.0用のDBを構築する手順を記すことにします。

          ____
       / \  /\ キリッ
.     / (ー)  (ー)\
    /   ⌒(__人__)⌒ \   試験環境DBはインスタンス毎で管理するお
    |      |r┬-|    |  
     \     `ー'´   /   
    ノ            \
  /´               ヽ
 |    l              \
 ヽ    -一''''''"~~``'ー--、   -一'''''''ー-、.
  ヽ ____(⌒)(⌒)⌒) )  (⌒_(⌒)⌒)⌒))

# ps axuw | grep mysql
mysql     9228  0.0  0.2 263768 17820 ?      Sl   Apr23   6:51 /usr/sbin/mysqld
mysql     9395  0.0  3.4 1656920 283764 ?    Sl   Apr23   1:26 /usr/sbin/mysqld --defaults-group-suffix=_yaruo_s
mysql     9322  0.0  2.3 2043012 195480 ?    Sl   Apr02   1:52 /usr/sbin/mysqld --defaults-group-suffix=_yaruo_ver1_5_m
mysql     9914  0.0  7.1 5398488 580780 ?    Sl   Apr23   1:47 /usr/sbin/mysqld --defaults-group-suffix=_yaruo_ver1_6_m
root     12430  0.0  0.0 53268  804 pts/0    S+   14:29   0:00 grep mysql

# /usr/bin/mysqladmin shutdown -S /var/lib/mysql/yaruto_ver1_5.sock

# ps axuw | grep mysql
mysql     9228  0.0  0.2 263768 17820 ?      Sl   Apr23   6:51 /usr/sbin/mysqld
mysql     9395  0.0  3.4 1656920 283764 ?    Sl   Apr23   1:26 /usr/sbin/mysqld --defaults-group-suffix=_yaruo_s
mysql     9914  0.0  7.1 5398488 580780 ?    Sl   Apr23   1:47 /usr/sbin/mysqld --defaults-group-suffix=_yaruo_ver1_6_m
root     12430  0.0  0.0 53268  804 pts/0    S+   14:29   0:00 grep mysql

バージョンが変わるので、ディレクトリ管理しやすいように変えてしまいます。1からDBを構築する場合は、dataディレクトリを削除してしまいます。

# cd /usr/local/yaruo/data
# ls
mysql  yaruo_ver1_5  yaruo_ver1_6    work
# mv yaruo_ver1_5 yaruo_ver2_0
# cd yaruo_ver2_0
binlog  ibdata  iblogs  logs  mysql  relays  test  tmp  yaruo_db
# rm -rf yaruo_db

ディレクトリ名がver2_0に変わるので、ver1_5記載箇所をver2_0に変える必要があります。 viで手で変更しても可ですが、sed使う方が楽です。diffで変更点を確認してみて下さい。

# cd ../mysql
# sed 's/ver1_5/ver2_0/g' yaruo_ver1_5_my.cnf > yaruo_ver2_0_my.cnf
# diff yaruo_ver2_0_my.con yaruo_ver1_5_my.cnf
# chown mysql:mysql yaruo_ver2_0_my.cnf

インスタンスについては、親のmy.cnfからincludeさせているので、こちらの修正も必要です。

# vi my.cnf
-----
- /usr/local/yaruo/data/mysql/ yaruo_ver1_5_my.cnf
+ /usr/local/yaruo/data/mysql/ yaruo_ver2_0_my.cnf
-----

起動してみます。

# /usr/sbin/mysqld --defaults-group-suffix=_yaruo_ver2_0_m &
[1] 31886
#
[1]+  Exit 1                  /usr/sbin/mysqld --defaults-group-suffix=_yaruo_ver2_0_m

失敗・・・。エラーログを確認します。

            ___
       /      \         
      /ノ  \   u. \ !?
    / (●)  (●)    \ おっお・・・
    |   (__人__)    u.   |
     \ u.` ⌒´      /     またMySQLが立ち上がらないお
    ノ           \
  /´               ヽ
 |    l              \
 ヽ    -一''''''"~~``'ー--、   -一'''''''ー-、.
  ヽ ____(⌒)(⌒)⌒) )  (⌒_(⌒)⌒)⌒))

やる夫が困ってます。何とかしてあげましょう・・・。

# tail -f /usr/local/yaruo/data/yaruo_ver2_0/logs/yaruo_ver2_0_m.errorlog
080527 15:31:58  InnoDB: Started; log sequence number 0 130390540
/usr/sbin/mysqld: File '/usr/local/yaruo/data/yaruo_ver2_0/binlog/yaruo_db1_m.000001' not found (Errcode: 2)
080527 15:31:58 [ERROR] Failed to open log (file '/usr/local/yaruo/data/yaruo_ver2_0/binlog/yaruo_db1_m.000001', errno 2)
080527 15:31:58 [ERROR] Could not open log file
080527 15:31:58 [ERROR] Can't init tc log
080527 15:31:58 [ERROR] Aborting

080527 15:31:58  InnoDB: Starting shutdown...
080527 15:32:00  InnoDB: Shutdown completed; log sequence number 0 130390540
080527 15:32:00 [Note] /usr/sbin/mysqld: Shutdown complete

どうもver1.5時のデータが残っているのが原因らしいですね。なので、ログを全て削除してしまいます。

# /usr/sbin/mysqld --defaults-group-suffix=_yaruo_ver2_0_m &
[1] 1219
# ps axuw | grep mysql
mysql     9228  0.0  0.2 263768 17820 ?      Sl   Apr23   6:51 /usr/sbin/mysqld
mysql     9395  0.0  3.4 1656920 283764 ?    Sl   Apr23   1:26 /usr/sbin/mysqld --defaults-group-suffix=_yaruo_s
mysql     9914  0.0  7.1 5398488 580780 ?    Sl   Apr23   1:47 /usr/sbin/mysqld --defaults-group-suffix=_yaruo_ver1_6_m
mysql     9322  0.0  2.3 2043012 195480 ?    Sl   Apr02   1:52 /usr/sbin/mysqld --defaults-group-suffix=_yaruo_ver2_0_m
root     12430  0.0  0.0 53268  804 pts/0    S+   14:29   0:00 grep mysql

再度起動コマンドを実行指定見ます・・・。今回はうまく行ったようです。

      ___
     /_ノ   ヽ_\
   /( >)  (<)\
  /::::::⌒(__人__)⌒::::: \  ね!かんたんだお
  |     |r┬-/      |
  \     ` ̄'´     /

----------------------------------------

現場で使える MySQL (DB Magazine SELECTION)
Mysql
松信 嘉範
翔泳社翔泳社翔泳社
定価 : ¥ 2,730
2006-03-17
amazonで詳しく見る

| | コメント (0) | トラックバック (0)

2008-04-30

[mysql] やる夫がselect結果をソートするようです。

select 結果をソートする

最近何をムキになって更新しているか、考える今日この頃・・・。そろそろ同でも良くなってきたが、ソート表示する方法を記載します。

  • select [column_name] from [table_name] order by;

ソート

# mysql
mysql> select yaruo_time from yaruo_table order by yauro_time LIMIT 5;
+------------+
| yaruo_time |
+------------+
|       NULL |
|       NULL |
|       NULL |
|         12 |
|         23 |
+------------+
5 rows in set (0.14 sec)

逆順ソート

# mysql
mysql> select yaruo_time from yaruo_table order by yaruo_time DESC LIMIT 5;
+------------+
| yaruo_time |
+------------+
|      12096 |
|       8552 |
|       6112 |
|       5892 |
|       5736 |
+------------+
5 rows in set (0.14 sec)

----------------------------------------

現場で使える MySQL (DB Magazine SELECTION)
松信 嘉範
翔泳社翔泳社翔泳社
定価 : ¥ 2,730
2006-03-17
amazonで詳しく見る

| | コメント (0) | トラックバック (0)

2008-04-28

[mysql] やる夫がスロークエリログを見やすくするようです。

mysqldumpsloでスロークエリログを見やすくする

見出しの通り・・・

  • mysqldumpslow [log_name]

スロークエリ調査には下記cronとか仕掛けておけばよいでしょう。下記例では、ファイル名の形式は、”[hostname].slowqueries.yyyynndd”で出力先は”/usr/local/mysql/logs/slowqueries/”配下となります。

# crontab -e
-----
16 8 * * * /usr/bin/mysqldumpslow /usr/local/mysql/logs/yaruo_db.slowqueries.1 > /usr/local/mysql/logs/slowqueries/`hostname`.slowqueries.`date +%Y%m%d --date '1 day ago'`
-----

  • --date '1 day ago' は一日前の日付時間を取得します。

いや・・・たんにスロークエリログは1日に一回ログローテートするので、1日前の日付の方がいいかな?とかそんな感じです。

----------------------------------------

現場で使える MySQL (DB Magazine SELECTION)
松信 嘉範
翔泳社翔泳社翔泳社
定価 : ¥ 2,730
2006-03-17
amazonで詳しく見る

| | コメント (0) | トラックバック (0)

2008-04-16

[shell] やる夫がindexを確認するようです。

INDEXの確認方法

”show index from [table_name]”で確認できます。postgreSQLだと、”\d [table]”で確認できるので楽ですね・・・。

mysql> show index from yaruo_tb;
+----------+------------+---------------+--------------+--------------+----
| Table    | Non_unique | Key_name      | Seq_in_index | Column_name  |
+----------+------------+---------------+--------------+--------------+----
| yaruo_tb |          0 | PRIMARY       |            1 | neet_id      |   
| yaruo_tb |          0 | PRIMARY       |            2 | jitaku_id    |   
| yaruo_tb |          0 | yaruo_neet_id |            1 | neet_user_id |   
+----------+------------+---------------+--------------+--------------+----
3 rows in set (0.00 sec)

----------------------------------------

現場で使える MySQL (DB Magazine SELECTION)
松信 嘉範
翔泳社翔泳社翔泳社
定価 : ¥ 2,730
2006-03-17
amazonで詳しく見る

| | コメント (0) | トラックバック (0)

2008-04-14

[mysql] やる夫がDBコネクションをkillするようです。

やる夫がスロークエリに悩まされているようです。

週明け早々からアボンヌしてしまいました。活性保守メンテナンスなのですが、処理が重くついでに、他の設定も加えたため、idleが0に差し込みました。休み中雲隠れしとけばよかった・・・。

         ____
       /::::::::::  u\  
      /:::::::::⌒ 三. ⌒\    監視からの電話が鳴り止まないお・・・。
    /:::::::::: ( ○)三(○)\ 
    |::::::::::::::::⌒(__人__)⌒  | ________
     \::::::::::   ` ⌒´   ,/ .| |          |
    ノ::::::::::u         \ | |          |
  /:::::::::::::::::      u       | |          |
 |::::::::::::: l  u             | |          |
 ヽ:::::::::::: -一ー_~、⌒)^),-、   | |_________|
  ヽ::::::::___,ノγ⌒ヽ)ニニ- ̄   | |  |

# sar
07時45分01秒       CPU     %user     %nice   %system   %iowait     %idle
07時50分01秒       all     20.90      0.00      9.95     60.64      8.51
07時55分01秒       all     16.33      0.00      7.79     72.91      2.97
08時00分02秒       all     15.26      0.00      6.73     76.42      1.59
08時05分01秒       all     14.20      0.00      6.31     78.51      0.98
08時10分01秒       all     14.82      0.00      6.29     78.05      0.83
08時15分01秒       all     14.14      0.00      5.85     79.47      0.53
08時20分01秒       all     13.16      0.00      5.47     80.84      0.53
08時25分01秒       all     13.23      0.00      5.48     80.84      0.45
08時30分01秒       all     12.49      0.00      4.98     82.04      0.48
08時35分01秒       all     11.78      0.00      4.88     82.88      0.46

DBへのコネクションがやたら多い・・・。

# netstat | grep -c ESTABLISHED
502
# netstat | grep ESTABLISHED | grep -c 192.168.2.12
240

  • Maxconectionsは512です。普段は260くらいとします。
  • 上記例だと、”192.168.2.12”からのコネクションで半分を使い果している感じです。

”192.168.2.12”は監視orバッチ系のサーバなので、アプリを停止しました・・・が、selectはDBサーバに滞留しちゃうので、DB側でプロセスを停止しないといけません。

特定ホストからのプロセスを停止する方法

# mysqladmin processlist  | grep 192.168.2.12
| 245713 | neet | 192.168.2.12 | yaruo_db | Sleep   | 5018565  |                |
| 250366 | neet | 192.168.2.12 | yaruo_db | Sleep   | 40324525 |                |

結構見やすいように整形しちゃいましたが、こんな感じで出力されます。左端の数字がプロセスIDなので、ひたすらkillしてやればよいです。kill方法は下記にしるします。

# mysqladmin kill 171491 -u root

----------------------------------------

現場で使える MySQL (DB Magazine SELECTION)
松信 嘉範
翔泳社翔泳社翔泳社
定価 : ¥ 2,730
2006-03-17
amazonで詳しく見る

| | コメント (0) | トラックバック (0)

2008-03-28

MySQL リファレンス

インストール

パフォーマンスチューニング

SQL

こんなときどうする?

| | コメント (0) | トラックバック (0)