MySQL で 実行計画を取る

はじめに MySQLで実行計画を取りたい場合の書き方は EXPLAIN をつければいいが、 SQLのコスト表示がされないので、これを付けたい。 その場合の指定方法 まとめ 結果 解決方法 先頭に以下をつけて、JSONフォーマットを指定する。 query_cost 付きでJSONの結果が表示できる EXPLAIN FORMAT=JSON select * from sample where id = 1;

2024-02-14 ·  2024-08-01 · 1 分 · 22 文字

Docker mysql 5.7 イメージで初期化処理に失敗して、ログインできない

発生したエラー MySQL 5.7 のイメージ を使用して単純に起動しても下記エラーが発生して、初期化処理に失敗していた。 厳密には初期化時に上記エラーが出て、初期化SQLまでたどり着かなかった。 初期化処理に失敗すると、mysql userの設定や admin パスワードの設定がうまくできないようで、どうしようもない状態になるようで、、これをなんとかしたかった… /usr/local/bin/docker-entrypoint.sh: line 137: 126 Killed "$@" --skip-networking --default-time-zone=SYSTEM --socket="${SOCKET}" ログをみると怪しい部分は上記のみで、どうもプロセスがいきなり Kill されているように見える 原因はリソースの使いすぎ 以下のようなコメントにたどり着いた 1708115 – Running mysql container in moby-engine results in 100% memory usage Really high memory usage · Issue #579 · docker-library/mysql Thank you so much @evolbug! The bug you found put me on the right tracks. The issue is caused by the ulimit nofile. By default, on arch, the value is too low I guess. running the container with --ulimit nofile=262144:262144 solve the issue and mysql behaves normally. I guess the best way to fix this would be to set this option by default. Should this be documented on docker images prone to this issue? Edit: Actually, it's weird, I think the default limit is way to high, this is what I get by default: > docker run --rm centos:7 /bin/bash -c 'ulimit -Hn && ulimit -Sn' 1073741816 1073741816 So lowering the value fixes the issue The ulimits does the trick. I added this to my docker-compose and make it work. @vodkhard ulimits: nproc: 65535 nofile: soft: 26677 hard: 46677 ...

2023-08-04 ·  2023-09-24 · 2 分 · 305 文字

debian wheezy mysql 設定、データ移行

インストール sudo aptitude install mysql-server alive check mysqladmin ping -u root -p mysqlパスワード変更 mysql -u root -p rootパスワード入力 SET PASSWORD FOR root@localhost=PASSWORD('new_password'); ユーザ確認 ログイン mysql -u root -p SQL実行 SELECT host,user,password FROM mysql.user; 文字コード設定 charset UTF8 check mysql> status -------------- mysql Ver 14.14 Distrib 5.5.38, for debian-linux-gnu (armv7l) using readline 6.2 Connection id: 39 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.5.38-0+wheezy1 (Debian) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /var/run/mysqld/mysqld.sock Uptime: 5 hours 20 min 7 sec Threads: 1 Questions: 114 Slow queries: 0 Opens: 171 Flush tables: 1 Open tables: 41 Queries per second avg: 0.005 if your env is not seted to utf8, add utf8 settings below sudo vim /etc/mysql/conf.d/character_set.cnf ...

2014-10-11 ·  2014-10-11 · 3 分 · 426 文字

Linkstation(debian wheezy) へ mysql を設定、データ移行

インストール sudo aptitude install mysql-server alive check mysqladmin ping -u root -p mysqlパスワード変更 mysql -u root -p rootパスワード入力 SET PASSWORD FOR root@localhost=PASSWORD('new_password'); ユーザ確認 ログイン mysql -u root -p SQL実行 SELECT host,user,password FROM mysql.user; 文字コード設定 charset UTF8 check mysql> status -------------- mysql Ver 14.14 Distrib 5.5.38, for debian-linux-gnu (armv7l) using readline 6.2 Connection id: 39 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.5.38-0+wheezy1 (Debian) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /var/run/mysqld/mysqld.sock Uptime: 5 hours 20 min 7 sec Threads: 1 Questions: 114 Slow queries: 0 Opens: 171 Flush tables: 1 Open tables: 41 Queries per second avg: 0.005 if your env is not seted to utf8, add utf8 settings below sudo vim /etc/mysql/conf.d/character_set.cnf ...

2014-10-11 ·  2014-10-11 · 3 分 · 427 文字

玄箱HG(debian lenny) mysqlディレクトリ変更

参考 mysql停止 sudo /etc/init.d/mysql stop データ移行 mkdir -p /path/to/mysql_directory chown mysql:mysql /path/to/mysql_directory cd /path/to/mysql_directory mkdir mysqldata mysqldump chown mysql:mysql mysqldata chown mysql:mysql mysqldump sudo cp -fprv /var/lib/mysql/ ./mysqldata/ ディレクトリ指定設定 sudo vi /etc/mysql/conf.d/my_datadir.cnf 修正内容は以下 [mysqld] datadir = /path/to/mysql_directory/mysqldata/mysql 正しく設定変更され起動できるか確認する為、元のデータは別場所へ移動 mkdir /data/tmp sudo mv /var/lib/mysql /data/tmp mysql 再起動 sudo /etc/init.d/mysql restart 不要となったデータを削除 sudo rm /data/tmp

2012-10-20 ·  2012-10-20 · 1 分 · 53 文字