FrontPage

mail.server のmysql 51 から 55へ

mysql 51 でのdbを55で

************************************************************************

Remember to run mysql_upgrade (with the optional --datadir=<dbdir> flag)
the first time you start the MySQL server after an upgrade from an
earlier version.

************************************************************************
install-info --quiet /usr/local/info/mysql.info /usr/local/info/dir
===> Correct pkg-plist sequence to create group(s) and user(s)

install しただけでは設定フィル /usr/local/etc/my.cnf は生成されないので、バックアップからコピー。

hotshot# cp my.cnf /usr/local/etc/

が、ここで、バージョンが大きく違うので、設定ファイルの項目が若干違う。そのままでは、mysql-serverは、起動すらしない。/usr/local/share/mysqlのサンプルとにらめっこして、修正。

#skip-locking
skip-external-locking

みたいなのが数カ所┐(´д`)┌

データのアップグレードをする

http://www.icefree.org/182.html

hotshot# /usr/local/etc/rc.d/mysql-server start
Starting mysql.
hotshot# mysql_upgrade --password="パスワード" --datadir=/usr/mysql --verbose
mysql_upgrade: the '--datadir' option is always ignored
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
Running 'mysqlcheck' with connection arguments: '--port=XXXX' '--socket=/tmp/mysql.sock'
Running 'mysqlcheck' with connection arguments: '--port=XXXX' '--socket=/tmp/mysql.sock'
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.event                                        OK
mysql.func                                         OK
mysql.general_log                                  OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.host                                         OK
mysql.ndb_binlog_index                             OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.servers                                      OK
mysql.slow_log                                     OK
mysql.tables_priv                                  OK
mysql.time_zone                                    OK
mysql.time_zone_leap_second                        OK
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
phpmyadmin.pma_bookmark                            OK
phpmyadmin.pma_column_info                         OK
phpmyadmin.pma_designer_coords                     OK
phpmyadmin.pma_history                             OK
phpmyadmin.pma_pdf_pages                           OK
phpmyadmin.pma_relation                            OK
phpmyadmin.pma_table_coords                        OK
phpmyadmin.pma_table_info                          OK
phpmyadmin.pma_tracking                            OK
phpmyadmin.pma_userconfig                          OK
Running 'mysql_fix_privilege_tables'...
OK
hotshot#

できたっぽい( ´▽`)ノ

MySQL が起動しない

# /usr/local/etc/rc.d/mysql-server start ←デーモンを起動します

してもmysql daemon が起動しない・・・ ので、55やら54やらいろいろ変えてみるもだめ。

# rm -r /var/db/mysql

して、起動したらおk

設定ファイルも要チェックだよ

MySQL 2012/07/17

MySQLの再構築ということで、portinstall databases/mysql51-client を入れたら、もうすでに55がはいっとる、といわれた。で、

portinstall databases/mysql55-server


-- Installing: /usr/local/man/man1/resolveip.1
-- Installing: /usr/local/man/man8/mysqld.8
===> Installing rc.d startup script(s)
************************************************************************

Remember to run mysql_upgrade (with the optional --datadir=<dbdir> flag)
the first time you start the MySQL server after an upgrade from an
earlier version.

************************************************************************
install-info --quiet /usr/local/info/mysql.info /usr/local/info/dir
===> Correct pkg-plist sequence to create group(s) and user(s)
===>   Compressing manual pages for mysql-server-5.5.25
===>   Registering installation for mysql-server-5.5.25
===> SECURITY REPORT:
      This port has installed the following files which may act as network
      servers and may therefore pose a remote security risk to the system.
/usr/local/libexec/mysqld

      This port has installed the following startup scripts which may cause
      these network services to be started at boot time.
/usr/local/etc/rc.d/mysql-server

      If there are vulnerabilities in these programs there may be a security
      risk to the system. FreeBSD makes no guarantee about the security of
      ports included in the Ports Collection. Please type 'make deinstall'
      to deinstall the port if this is a concern.

      For more information, and contact details about the security
      status of this software, see the following webpage:
http://www.mysql.com/
===>  Cleaning for mysql-server-5.5.25
piano2nd#

OpnePNEで写真がUPできなくなった?

/usr/local/etc/my.conf で、

max_allowed_packet = 16M

としているにもかかわらず、

blackcube# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.1.60 FreeBSD port: mysql-server-5.1.60

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> show variables like 'max_allowed_packet';
+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
1 row in set (0.38 sec)

mysql>
[client]
max_allowed_packet = 20M
mysql> show global variables like 'max_allowed_packet';
+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
1 row in set (0.00 sec)

mysql> SET GLOBAL max_allowed_packet=16*1024*1024;
Query OK, 0 rows affected (0.00 sec)

mysql> show global variables like 'max_allowed_packet';
+--------------------+----------+
| Variable_name      | Value    |
+--------------------+----------+
| max_allowed_packet | 16777216 |
+--------------------+----------+
1 row in set (0.00 sec)

mysql>

/usr/local/etc/my.conf で、って、それ、/usr/local/etc/my.cnf ですから~!(波田陽区)

そりゃファイル名違ってたらDBにスルーされるわなぁ (´д`)

http://d.hatena.ne.jp/sh2/20091002

MySQL DB Backup

mysqldump

http://www2.nl.freebsd.org/mysql/doc/refman/5.1/ja/mysqldump.html

mysqldumpの最も一般的な用途は、データベース全体のバックアップの作成です。

shell> mysqldump db_name > backup-file.sql
878 15:12 mysqldump -p RSB > RSB_bac.sql

ダンプファイルをサーバに戻し読みすることが可能です。

shell> mysql db_name < backup-file.sql
880 15:13 mysql -p RSB_bk < RSB_bac.sq

また、次のようにもできます。

shell> mysql -e "source /path-to-backup/backup-file.sql" db_name

mysqldumpは1つのMySQLサーバからデータをコピーすることでデータベースのpopulatingに便利です。

shell> mysqldump --opt db_name | mysql --host=remote_host -C db_name

1つのコマンドで複数のデータベースをダンプすることが可能です。

shell> mysqldump --databases db_name1 [db_name2 ...] > my_databases.sql

全てのデータベースをダンプするには、--all-databasesオプションを使用してください。

shell> mysqldump --all-databases > all_databases.sql

InnoDBテーブルに関して、mysqldumpはオンラインバックアップの作成方法を提供しています。

shell> mysqldump --all-databases --single-transaction > all_databases.sql

このバックアップはグローバルリードロックをダンプの最初に、全テーブルで取得することだけが必要です(FLUSH TABLES WITH READ LOCKを使用して)。このロックが取得されれば、バイナリログの座標は読まれ、ロックが開放されます。FLUSHステートメントが発行されている際、1つの長い更新ステートメントが作動している場合にのみ、MySQLサーバはその長いステートメントが終了するまでストールすれば、ダンプがロックフリーとなります。MySQLサーバが受ける更新ステートメントが短い場合(実行時間を指す)、更新の数が多くても最初のロック期間はさほど気にならないはずです。

point-in-timeリカバリは、(もしくは「roll-forward」ーこれは古いバックアップをリストア、そのバックアップが行われてから発生した変更を再生する場合)、バイナリログを回転する、もしくはダンプが対応しているバイナリログの座標だけでも知っているとと便利な場合があります(項4.11.4. 「バイナリ ログ」を参照して下さい)。

shell> mysqldump --all-databases --master-data=2 > all_databases.sql

または

shell> mysqldump --all-databases --flush-logs --master-data=2
             > all_databases.sql

バックアップ作成の追加情報に関しては、項4.9.1. 「データベースのバックアップ」と項4.9.2. 「バックアップとリカバリ手法の例示」を参照してください。

ビューのバックアップの際問題が発生した場合、ビューに対する制限を含むセクションを参照してください。権限が不足している事によって失敗した場合の、ビューバックアップ解決策を記しています。項D.4. 「ビューの規制」 を参照してください。

Top / Previous / Next / Up / Table of Contents

mysqlhotcopy

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

http://members.multimania.co.uk/wipe_out/automysqlbackup/

MySQL port change

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

新規インストール

# portinstall databases/mysql51-client
# portinstall databases/mysql51-server

再インストール

# portupgrade -f databases/mysql51-client
# portupgrade -f databases/mysql51-server

バージョンアップ

# portupgrade databases/mysql51-client
# portupgrade databases/mysql51-server

以下の起動スクリプトで制御できます。

# /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

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

# 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に半角でパスワードを書きます。

接続ユーザの作成・削除・パスワード変更

これらは手動でやると慣れない人にはかなり大変なので、細かくは 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>

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS