- 追加された行はこの色です。
- 削除された行はこの色です。
[[FrontPage]]
#contents
*MySQL DB Backup [#hdeda97f]
**mysqlhotcopy [#t8afeec6]
http://www2.nl.freebsd.org/mysql/doc/refman/5.1/ja/mysqlhotcopy.html
mysqlhotcopyは元々Tim Bunceによって書かれ、提供されたPerlスクリプトです。データベースバックアップを速やかに作成するため、LOCK TABLES、FLUSH TABLES、cpあるいはscpを使用します。データベースやシングルテーブルのバックアップを作成する最速の方法ですが、データベースディレクトリが存在する同じマシン上でしか作動しません。mysqlhotcopyはMyISAMとARCHIVEテーブルのバックアップのためのみ作動します。UnixとNetWareで作動します。
portinstall databases/mysql51-scripts
install -o root -g wheel -m 444 'msql2mysql.1' '/usr/local/man/man1/msql2mysql.1'
install -o root -g wheel -m 444 'mysql_convert_table_format.1' '/usr/local/man/man1/mysql_convert_table_format.1'
install -o root -g wheel -m 444 'mysql_find_rows.1' '/usr/local/man/man1/mysql_find_rows.1'
install -o root -g wheel -m 444 'mysql_fix_extensions.1' '/usr/local/man/man1/mysql_fix_extensions.1'
install -o root -g wheel -m 444 'mysql_secure_installation.1' '/usr/local/man/man1/mysql_secure_installation.1'
install -o root -g wheel -m 444 'mysql_setpermission.1' '/usr/local/man/man1/mysql_setpermission.1'
install -o root -g wheel -m 444 'mysql_zap.1' '/usr/local/man/man1/mysql_zap.1'
install -o root -g wheel -m 444 'mysqlaccess.1' '/usr/local/man/man1/mysqlaccess.1'
install -o root -g wheel -m 444 'mysqldumpslow.1' '/usr/local/man/man1/mysqldumpslow.1'
install -o root -g wheel -m 444 'mysqlhotcopy.1' '/usr/local/man/man1/mysqlhotcopy.1'
install -o root -g wheel -m 444 'mysqld_multi.1' '/usr/local/man/man1/mysqld_multi.1'
===> Compressing manual pages for mysql-scripts-5.1.49
===> Registering installation for mysql-scripts-5.1.49
===> Cleaning for p5-DBD-mysql51-4.016
===> Cleaning for mysql-scripts-5.1.49
k222# rehash
k222# mysqlhotcopy
Database name to hotcopy not specified
/usr/local/bin/mysqlhotcopy Ver 1.23
Usage: /usr/local/bin/mysqlhotcopy db_name[./table_regex/] [new_db_name | directory]
-?, --help display this help-screen and exit
-u, --user=# user for database login if not current user
-p, --password=# password to use when connecting to server (if not set
in my.cnf, which is recommended)
-h, --host=# hostname for local server when connecting over TCP/IP
-P, --port=# port to use when connecting to local server with TCP/IP
-S, --socket=# socket to use when connecting to local server
--allowold don't abort if target dir already exists (rename it _old)
--addtodest don't rename target dir if it exists, just add files to it
--keepold don't delete previous (now renamed) target when done
--noindices don't include full index files in copy
--method=# method for copy (only "cp" currently supported)
-q, --quiet be silent except for errors
--debug enable debug
-n, --dryrun report actions without doing them
--regexp=# copy all databases with names matching regexp
--suffix=# suffix for names of copied databases
--checkpoint=# insert checkpoint entry into specified db.table
--flushlog flush logs once all tables are locked
--resetmaster reset the binlog once all tables are locked
--resetslave reset the master.info once all tables are locked
--tmpdir=# temporary directory (instead of /tmp)
--record_log_pos=# record slave and master status in specified db.table
--chroot=# base directory of chroot jail in which mysqld operates
Try 'perldoc /usr/local/bin/mysqlhotcopy' for more complete documentation
k222# mysqlhotcopy -p xxxxxxxxxx PNE3 PNE3_bk --allowold
Existing hotcopy directory renamed to '/var/db/mysql/PNE3_bk_old'
**AutoMySQLBackup [#v48849d9]
http://members.multimania.co.uk/wipe_out/automysqlbackup/
*MySQL port change [#w6d55793]
3306ポートへの不正アクセスが増加してきたので?
/usr/local/etc/my.conf
[client]
#password = your_password
#port = 3306
port = 9998
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
#port = 3306
port = 9998
socket = /tmp/mysql.sock
これで、
piano:root {47} % netstat -an
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp4 0 0 219.117.246.200.80 210.255.122.209.64004 TIME_WAIT
tcp4 0 52 219.117.246.200.9997 210.255.122.209.60186 ESTABLISHED
tcp4 0 0 219.117.246.200.9997 210.255.122.209.63596 ESTABLISHED
tcp4 0 0 *.3306 *.* LISTEN
が
tcp4 0 0 *.9998 *.* LISTEN
になる。
*MySQL Upgrade [#u0de8cfe]
**新規インストール [#d6bcfd72]
# portinstall databases/mysql51-client
# portinstall databases/mysql51-server
**再インストール [#s54364b7]
# portupgrade -f databases/mysql51-client
# portupgrade -f databases/mysql51-server
**バージョンアップ [#uea20e3f]
# portupgrade databases/mysql51-client
# portupgrade databases/mysql51-server
**以下の起動スクリプトで制御できます。 [#d4391efc]
# /usr/local/etc/rc.d/mysql-server start ←デーモンを起動します
# /usr/local/etc/rc.d/mysql-server restart ←デーモンを再起動します
# /usr/local/etc/rc.d/mysql-server stop ←デーモンを停止します
http://www.peach.ne.jp/freebsd/mysql.html
*MySQL on FreeBSD [#o72ad0b0]
http://www.peach.ne.jp/freebsd/mysql.html
http://www.bugbearr.jp/?FreeBSD%2FMySQL
http://uls.fam.cx/freebsd/archives/000093.html
http://www.machu.jp/diary/20060206.html#p01
**Port de install [#cecf05d3]
# portinstall databases/mysql51-client
# portinstall databases/mysql51-server
/etc/rc.conf
mysql_enable="YES"
デフォルトでは /var/db/mysql にデータベースファイルが作成されます。もし他の場所にしたい場合は rc.conf に以下のような設定を追加します。このディレクトリが起動時になければパーミッション 700、オーナー mysqlで作成されます。
mysql_dbdir="/path/to/mysql"
mysqlの設定ファイルの雛形をコピーしておきます。(より大規模なシステムなら large や huge に)
# cp /usr/local/share/mysql/my-medium.cnf /usr/local/etc/my.cnf
# chmod 644 /usr/local/etc/my.cnf
以下の起動スクリプトで制御できます。
# /usr/local/etc/rc.d/mysql-server start ←デーモンを起動します
# /usr/local/etc/rc.d/mysql-server restart ←デーモンを再起動します
# /usr/local/etc/rc.d/mysql-server stop ←デーモンを停止します
起動できたら、rootユーザのパスワードを設定します。初期状態ではパスワードなしになっています。ここでは root@localhost の設定を変更しておきます。
# mysqladmin -u root -h localhost password 'XXXXXX' ←XXXXXXに半角でパスワードを書きます。
**接続ユーザの作成・削除・パスワード変更 [#r64f8f0f]
これらは手動でやると慣れない人にはかなり大変なので、細かくは phpMyAdmin を導入してそちらで行います。 phpMyAdmin の実行にはWebサーバとPHPが必要になります。 MySQLのSSL機能を利用した場合はリモート接続を暗号化できますので、 MySQLサーバと管理用の phpMyAdmin は同じマシンでなくとも利用可能です。
ここでは匿名ユーザなど root@localhost 以外を削除しておきます。 mysqlコマンドで接続した後に以下のコマンドを実行します。
mysql> DELETE FROM mysql.user WHERE user!='root' OR host!='localhost';
mysql> FLUSH PRIVILEGES; ←権限テーブルの再読み込み
piano:root {86} % mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.28-rc-log FreeBSD port: mysql-server-5.1.28_1
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database TFC;
Query OK, 1 row affected (0.00 sec)
mysql> use TFC;
Database changed
mysql> grant all privileges on TFC.*
-> to tfc@localhost identified by 'tasaka';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
piano:root {89} % mysqlshow -u root -p
Enter password:
+--------------------+
| Databases |
+--------------------+
| information_schema |
| TFC |
| mysql |
| test |
+--------------------+
piano:root {90} %
piano:root {90} % mysql -u tfc -p TFC
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.28-rc-log FreeBSD port: mysql-server-5.1.28_1
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create table TFC (
-> id int(11) auto_increment,
-> name varchar(255),
-> primary key (id)
-> );
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+---------------+
| Tables_in_TFC |
+---------------+
| TFC |
+---------------+
1 row in set (0.00 sec)
mysql> describe TFC;
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | YES | | NULL | |
+-------+--------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql>