slowlog
[mysqld]
log-slow-queries=/var/log/mysqld-slow.log
long-query-time=1
slowlogをメール
dailyでlogrotateしておいて、下記。
% crontab -l
50 3 * * * mysqldumpslow -s t /var/log/mysqld-slow.log | mail -s "mysql slowlog" foo@bar.com
CSVにエクスポート
SELECT * FROM employees INTO OUTFILE "/tmp/employees.csv" FIELDS TERMINATED BY ',' optionally enclosed by '"';
CSVからインポート
load data infile "item.csv" into table item fields terminated by ',' optionally enclosed by '"';
CSVからインポート(1行目を無視)
load data infile "item.csv" into table item fields terminated by ',' OPTIONALLY ENCLOSED BY '"' ignore 1 lines;
auto_incrementの値を設定
ALTER TABLE test AUTO_INCREMENT = 1;
ユーザー追加
grant all on dbname.* to `username`@localhost identified by 'password';
rootのパスワード削除
set password for root@localhost=password('');
DBバックアップ
% crontab -e
0 5 * * * mysqldump -uproject -pxxxxxxx project_production | bzip2 > /var/www/html/project/backups/project_production.`date +\%Y\%m\%d\%H\%M\%S`.dmp.bz2
カラム追加
ALTER TABLE `foos` ADD COLUMN `foo_id` int(11) NOT NULL DEFAULT 123 AFTER `title`;
Macにインストール
% sudo port install mysql5 +server
% sudo -u mysql mysql_install_db5
% sudo cp /opt/local/share/mysql5/mysql/my-small.cnf /etc/my.cnf
Macで起動
% sudo /opt/local/share/mysql5/mysql/mysql.server start
Macでlaunchdで再起動
% sudo launchctl stop org.macports.mysql5
% sudo launchctl start org.macports.mysql5
文字化け
# my.cnf
default-character-set = utf8
skip-character-set-client-handshake
外部からの接続禁止
# my.cnf
skip-networking
クエリーのログを取る
[mysqld]
log=/var/log/mysqld-query.log