何かのきっかけ(システムの更新?)でMySQLがmysql.procからロードできない、なんか壊れてるよ、ってエラーが出た場合にした対処方法をメモ。
mysql_upgrade -u root -p
これをするとMySQLを治してくれた。
参考:
https://dev.mysql.com/doc/refman/5.1/en/upgrading-from-previous-series.html
http://blog.zwiegnet.com/linux-server/error-code-1548-cannot-load-from-mysql-proc-the-table-is-probably-corrupted/
http://serverfault.com/questions/361838/mysql-cannot-load-from-mysql-proc-the-table-is-probably-corrupted
2016年4月27日水曜日
MySQLのダンプとリストアのなかなかよくまとまってるページがあったのでメモ
MySQLのダンプとリストアのなかなかよくまとまってるページがあったのでメモ
http://xpaper.info/information-technology/mysql-backup-and-restore-commands-with-gzip-bzip2/#.Vx-mT6MrLdR
http://xpaper.info/information-technology/mysql-backup-and-restore-commands-with-gzip-bzip2/#.Vx-mT6MrLdR
MySQLのビューでプライマリキーとなるカラムが無い場合、Hibernateのエンティティをどう書くのか?
MySQLのビューでプライマリキーとなる@IDが無い場合、つまり、複数のカラムでユニークキーとなる場合はそれぞれのカラムに@IDを指定する。
但し、これはJPAによると推奨されていないらしい。
http://stackoverflow.com/questions/4381290/hibernate-exception-org-hibernate-annotationexception-no-identifier-specified
但し、これはJPAによると推奨されていないらしい。
http://stackoverflow.com/questions/4381290/hibernate-exception-org-hibernate-annotationexception-no-identifier-specified
2016年2月2日火曜日
MySQLのコネクション数を調べる方法
MySQLのコネクション数を調べるには、
% show processlist
をする。
http://stackoverflow.com/questions/6502036/how-can-i-see-how-many-mysql-connections-are-open
% show processlist
をする。
http://stackoverflow.com/questions/6502036/how-can-i-see-how-many-mysql-connections-are-open
2015年12月2日水曜日
MySQLでの実行コマンドの履歴を表示するには
MySQLのコマンドのログをチェックしたかったので調べたら、どうやらファイルが作成されているようだ。
cat ~/.mysql_history
http://stackoverflow.com/questions/7818031/sql-command-to-display-history-of-queries
cat ~/.mysql_history
http://stackoverflow.com/questions/7818031/sql-command-to-display-history-of-queries
2015年7月30日木曜日
MySQLのSelect文で特定の文字列の場所を見つけると同時に分割する関数
MySQLのSelect文で特定の文字列の場所を見つけると同時に分割する関数でsubstring_indexというのが便利だったのでメモ。indexofとsubstringの両方が合わさったもの。
substring_index("www.google.com",".","2)
1つ目と2つ目の引数は明らかなので割愛。3つ目の引数がポイント。
正の数:分割された文字列の何番目かを左からから指す
負の数:分割された文字列の何番目かを右からから指す
http://www.w3resource.com/mysql/string-functions/mysql-substring_index-function.php
substring_index("www.google.com",".","2)
1つ目と2つ目の引数は明らかなので割愛。3つ目の引数がポイント。
正の数:分割された文字列の何番目かを左からから指す
負の数:分割された文字列の何番目かを右からから指す
http://www.w3resource.com/mysql/string-functions/mysql-substring_index-function.php
2015年6月17日水曜日
MySQLについてくるautomysqlbackupの使い方
MySQLにはバックアップ専用にautomysqlbackupがついてくるので、ちょっと使い方についてメモ書き。
https://serverpilot.io/community/articles/how-to-back-up-mysql-databases-with-automysqlbackup.html
- sudo apt-get install automysqlbackup でインストール
- /var/lib/automysqlbackup にバックアップが毎日作られるが、スクリプト中で保存先は指定できる。
※ BACKUPDIRとDBNAMESぐらいかな、変更したのは。。
https://serverpilot.io/community/articles/how-to-back-up-mysql-databases-with-automysqlbackup.html
MySQL 5.1 をUbuntu 12.04にインストールする方法
MySQL5.1をUbuntu12.04にインストールしようと思ったら、apt-getでは5.5がインストールされてしまうので、ソースからMySQL5.1をインストールするのに以下を参考にした。
シェルスクリプトでもコマンドラインからでもOK。
#!/bin/bash
set -e
cd ~/
wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.65.tar.gz
tar -zxf mysql-5.1.65.tar.gz
cd mysql-5.1.65
./configure '--prefix=/usr' '--exec-prefix=/usr' '--libexecdir=/usr/sbin' '--datadir=/usr/share' '--localstatedir=/var/lib/mysql' '--includedir=/usr/include' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-system-type=debian-linux-gnu' '--enable-shared' '--enable-static' '--enable-thread-safe-client' '--enable-assembler' '--enable-local-infile' '--with-fast-mutexes' '--with-big-tables' '--with-unix-socket-path=/var/run/mysqld/mysqld.sock' '--with-mysqld-user=mysql' '--with-libwrap' '--without-readline' '--with-ssl' '--without-docs' '--with-extra-charsets=all' '--with-plugins=max' '--with-embedded-server' '--with-embedded-privilege-control'
make
sudo make install
参考
http://askubuntu.com/questions/125686/failed-to-spawn-mysql-main-process-unable-to-execute-no-such-file-or-director
シェルスクリプトでもコマンドラインからでもOK。
#!/bin/bash
set -e
cd ~/
wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.65.tar.gz
tar -zxf mysql-5.1.65.tar.gz
cd mysql-5.1.65
./configure '--prefix=/usr' '--exec-prefix=/usr' '--libexecdir=/usr/sbin' '--datadir=/usr/share' '--localstatedir=/var/lib/mysql' '--includedir=/usr/include' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-system-type=debian-linux-gnu' '--enable-shared' '--enable-static' '--enable-thread-safe-client' '--enable-assembler' '--enable-local-infile' '--with-fast-mutexes' '--with-big-tables' '--with-unix-socket-path=/var/run/mysqld/mysqld.sock' '--with-mysqld-user=mysql' '--with-libwrap' '--without-readline' '--with-ssl' '--without-docs' '--with-extra-charsets=all' '--with-plugins=max' '--with-embedded-server' '--with-embedded-privilege-control'
make
sudo make install
参考
http://askubuntu.com/questions/125686/failed-to-spawn-mysql-main-process-unable-to-execute-no-such-file-or-director
2015年5月15日金曜日
MySQL5.5をUbuntuから完全に消去する方法
MySQL5.5をUbuntuからアンインストールしたかったので、やり方を調べてみた。
http://stackoverflow.com/questions/10853004/removing-mysql-5-5-completely
http://askubuntu.com/questions/125686/failed-to-spawn-mysql-main-process-unable-to-execute-no-such-file-or-director
sudo deluser mysql
sudo delgroup mysql
sudo service mysql stop #or mysqld
sudo killall -9 mysql
sudo killall -9 mysqld
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo deluser mysql
sudo rm -rf /var/lib/mysql
sudo apt-get purge mysql-server-core-5.5
sudo apt-get purge mysql-client-core-5.5
参考http://stackoverflow.com/questions/10853004/removing-mysql-5-5-completely
http://askubuntu.com/questions/125686/failed-to-spawn-mysql-main-process-unable-to-execute-no-such-file-or-director
mysqldumpでエラーを無視して実行する方法
mysqldumpでエラーを無視して実行する方法
参考
http://serverfault.com/questions/302151/how-do-i-ignore-errors-with-mysqldump
-f, --force Continue even if we get an sql-error.
参考
http://serverfault.com/questions/302151/how-do-i-ignore-errors-with-mysqldump
mysqldumpでダンプを圧縮して実行する方法
ダンプ
% mysqldump <mysqldump options> | gzip outputfile.sql.gz
リストア
% gunzip < outputfile.sql.gz | mysqldump <mysqldump options>
参考
http://www.ducea.com/2006/10/28/compressing-mysqldump-output/
% mysqldump <mysqldump options> | gzip outputfile.sql.gz
リストア
% gunzip < outputfile.sql.gz | mysqldump <mysqldump options>
参考
http://www.ducea.com/2006/10/28/compressing-mysqldump-output/
2015年3月20日金曜日
mysqldumpでデータのみをダンプする場合
$ mysqldump -uroot -p --no-create-info testdb > dump.sql
http://zetcode.com/databases/mysqltutorial/exportimport/
2015年1月24日土曜日
MySQLで複数のクエリの結果を比較する方法
2つのテーブルの違いを知りたい場合など、MySQLで複数のクエリの結果を比較したい場合がある。そういう時はこれ。
http://stackoverflow.com/questions/1569990/mysql-is-it-possible-to-get-the-difference-of-two-query-results
SELECT id FROM tableA
WHERE id NOT IN (
SELECT id FROM tableB
)
http://stackoverflow.com/questions/1569990/mysql-is-it-possible-to-get-the-difference-of-two-query-results
2015年1月13日火曜日
Hibernateで親エンティティの重複を無くすには?
SQLでJOINを使うと親エンティティが重複されてレコードが取得されてしまう場合がある。この場合、Hibernateで親エンティティの重複を無くして、ユニークなレコードを取得したい場合、Criteria#setResultTransformerを使う。
http://learningviacode.blogspot.in/2013/06/why-need-for-resulttransformers.html
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
http://learningviacode.blogspot.in/2013/06/why-need-for-resulttransformers.html
2015年1月9日金曜日
MySQLで複数のカラムをユニークキーにするには?
MySQLで複数のカラムをユニークキーにするには?
ALTER TABLE `sometable` ADD UNIQUE `unique_index` (`columnA`,`columnB`,`columnC`)
http://stackoverflow.com/questions/635937/how-do-i-specify-unique-constraint-for-multiple-columns-in-mysql
ALTER TABLE `sometable` ADD UNIQUE `unique_index` (`columnA`,`columnB`,`columnC`)
http://stackoverflow.com/questions/635937/how-do-i-specify-unique-constraint-for-multiple-columns-in-mysql
MySQLでauto incrementの値をリセットするには?
MySQLでauto incrementの値をリセットするには?
ALTER TABLE sometable AUTO_INCREMENT=1
http://stackoverflow.com/questions/970597/change-auto-increment-starting-number
ALTER TABLE sometable AUTO_INCREMENT=1
http://stackoverflow.com/questions/970597/change-auto-increment-starting-number
MySQLで複数カラムから最大値を取るには?
MySQLで複数カラムから最大値を取るには?
GREATEST(value1, value2, value3,...)
http://www.w3resource.com/mysql/comparision-functions-and-operators/greatest-function.php
でも、nullは比べたくない場合、
GREATEST(IFNULL(value1, 0), IFNULL(value2, 0), IFNULL(value3,0),...)
http://stackoverflow.com/questions/9831851/mysql-get-max-or-greatest-of-several-columns-but-with-null-fields
GREATEST(value1, value2, value3,...)
http://www.w3resource.com/mysql/comparision-functions-and-operators/greatest-function.php
でも、nullは比べたくない場合、
GREATEST(IFNULL(value1, 0), IFNULL(value2, 0), IFNULL(value3,0),...)
http://stackoverflow.com/questions/9831851/mysql-get-max-or-greatest-of-several-columns-but-with-null-fields
2014年10月3日金曜日
MySQLでデータのダンプとリストアをCSVファイルでやりとりする方法
MySQLでデータのダンプとリストアをCSVファイルでやりとりする方法を簡単にメモ。
ダンプ
SELECT * FROM tableA INTO OUTFILE "/tmp/dump.csv" FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"';
リストア
LOAD DATA INFILE "/tmp/dump.csv" INTO TABLE tableA FIELDS TERMINATED BY ',' ENCLOSED BY '"';
http://sasuke.main.jp/sqlcsv.html
注意した点として、Ubuntuなどではデフォルトで/tmp/ 以下からでしかCSVファイルを扱えなかったので、ダンプ・リストア時のエラーに注意。確かerrorno 13だった気が。。。
ダンプ
SELECT * FROM tableA INTO OUTFILE "/tmp/dump.csv" FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"';
リストア
LOAD DATA INFILE "/tmp/dump.csv" INTO TABLE tableA FIELDS TERMINATED BY ',' ENCLOSED BY '"';
http://sasuke.main.jp/sqlcsv.html
注意した点として、Ubuntuなどではデフォルトで/tmp/ 以下からでしかCSVファイルを扱えなかったので、ダンプ・リストア時のエラーに注意。確かerrorno 13だった気が。。。
2014年7月11日金曜日
MySQLでテーブル作成でエラーが出た時の詳細ログチェックの方法
MySQLで例えばテーブルを作成する時に外部キー制約などが間違ってた場合、error no 150と言われてもさっぱり分からないので、以下のコマンドで詳細をチェック。
>SHOW ENGINE INNODB STATUS
外部キーであれば、テーブル名が存在しないなどと詳しいエラーを教えてくれる。
http://stackoverflow.com/questions/17812616/mysql-error-1005-cant-create-table-errno-150
>SHOW ENGINE INNODB STATUS
外部キーであれば、テーブル名が存在しないなどと詳しいエラーを教えてくれる。
http://stackoverflow.com/questions/17812616/mysql-error-1005-cant-create-table-errno-150
2014年6月27日金曜日
mysqlでダンプファイルから特定の列をリストアするには?
idを指定してやる場合。
http://stackoverflow.com/questions/5658284/how-to-use-mysqldump-for-a-portion-of-a-table
mysqldump -uroot -p db_name table_name --where='id<1000000'
http://stackoverflow.com/questions/5658284/how-to-use-mysqldump-for-a-portion-of-a-table
登録:
投稿 (Atom)