CONTENTS


Lastmodified 2023-01-18 (水) 08:53:59

Counter: 1898, today: 1, yesterday: 0


mysql-80 root のパスワード変更

root@localhost [mysql]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MySecretPassword';   #MySQLの管理者rootのパスワードを設定
Query OK, 0 rows affected (0.00 sec)

mysql_upgrade: unknown variable 'max_allowed_packet=16M'

mysql_upgrade しようとしたところエラー

# mysql_upgrade -u root -p
mysql_upgrade: unknown variable 'max_allowed_packet=16M'

これは、my.cnf の[client]セクションに

max_allowed_packet = 16M

の記述があると現れるようで、[mysqld]セクションにのみ記述することで回避出来る様です。

https://bugs.mysql.com/bug.php?id=68313

MySQL が起動しない

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

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

# rm -r /var/db/mysql または mv /var/db/mysql /var/db/mysql_bk

して、起動したらおk

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

mysqlフォルダをmvしても起動出来ない場合

エラーログ /var/db/mysql/FQDN.err をよ~く見る。

150829 11:25:21 InnoDB: Initializing buffer pool, size = 128.0M
150829 11:25:21 InnoDB: Completed initialization of buffer pool
150829 11:25:21 InnoDB: highest supported file format is Barracuda.
150829 11:25:22  InnoDB: Waiting for the background threads to start
150829 11:25:23 InnoDB: 5.5.44 started; log sequence number 1589339
150829 11:25:23 [ERROR] /usr/local/libexec/mysqld: unknown option '--skip-locking'
150829 11:25:23 [ERROR] Aborting

150829 11:25:23  InnoDB: Starting shutdown...
150829 11:25:24  InnoDB: Shutdown completed; log sequence number 1589339
150829 11:25:24 [Note] /usr/local/libexec/mysqld: Shutdown complete

この場合は、/usr/local/etc/my.cnf に、

[mysqld]
socket		= /tmp/mysql.sock
skip-locking            この行があったためのエラー。コメントアウトする。

これで、起動できました。

エラーログ /var/db/mysql/FQDN.err に「mysqld: File './mysql-bin.******' not found」がある場合

2023-01-17T23:34:04.941808Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 
2023-01-17T23:34:16.874925Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysqld: File './mysql-bin.002815' not found (OS errno 2 - No such file or directory)
2023-01-17T23:34:17.693982Z 0 [ERROR] [MY-010958] [Server] Could not open log file.
2023-01-17T23:34:17.694009Z 0 [ERROR] [MY-010041] [Server] Can't init tc log
2023-01-17T23:34:17.694022Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-01-17T23:34:18.880764Z 0 [System] [MY-010910] [Server] /usr/local/libexec/mysqld: Shutdown complete (mysqld 8.0.31)  Source distribution.
2023-01-17T23:41:40.575239Z 0 [Warning] [MY-010140] [Server] Could not increase number of max_open_files to more than 32768 (request: 32929)

ログファイルにアクセス出来ないというエラーで、/var/db/mysql に、mysql-bin.002815 がないと言っている。

ログファイルの情報は、/var/db/mysql/mysql-bin.index に記述されているので、ここに記述されている mysql-bin.002815 の行を削除。

と、起動しました。

【参考URL】https://freefielder.jp/blog/2012/03/mysql-1.html

一つのDBを別サーバに移行

# mysqldump -a --user=UserName --password=PassWored DB_Name > DB_Name.mysql
# scp DB_Name.mysql TargetServer.example.domain:/var/db/

TargetServer.example.domain

phpMyAdminなどで、UserName DB_Name を作成しておくこと。でないとエラーでる

root@k149:/var/db # mysql --user=UserName --password=PassWored DB_Name < DB_Name.mysql
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'UserName'@'localhost' (using password: YES)

上手く行くと

Warning: Using a password on the command line interface can be insecure.

とか言われながらも、移行OK

MySQL-Server 56

Lastmodified 2023-01-18 (水) 08:53:59

何かの依存関係で、自動的にMySQL-Client 56 が入ってしまったので、まぁ、56のサーバを。

# portinstall mysql56-server
Using existing group 'mysql'.
Using existing user 'mysql'.
************************************************************************

Remember to run mysql_upgrade the first time you start the MySQL server
after an upgrade from an earlier version.

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

===> 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 mysql56-server-5.6.24

phpMyAdminの手当

# mysql -u root -p
mysql> source /usr/local/www/phpMyAdmin/sql/create_tables.sql
Query OK, 1 row affected (0.00 sec)

ダウングレードしたらDBへのアクセス時のエラー回避ができなかったので、元へと返す

2013-03-25 13:47:36

/var/db/mysql/FQDN.err

 1056  13:28   /usr/local/etc/rc.d/mysql-server stop
 1057  13:29   cd /usr/ports/databases/
 1058  13:29   ll
 1059  13:30   cd /usr/ports/databases/mysql55-client
 1060  13:30   make deinstall
 1061  13:30   cd /usr/ports/databases/mysql55-server/
 1062  13:30   make deinstall
 1063  13:31   cd /usr/ports/databases/mysql56-c
 1064  13:31   cd /usr/ports/databases/mysql56-client
 1065  13:31   make install
 1066  13:33   cd /usr/ports/databases/mysql56-server/
 1067  13:33   make install
 1068  13:42   rehash
 1069  13:43   /usr/local/etc/rc.d/mysql-server start
 1070  13:43   top
 1071  13:43   /usr/local/etc/rc.d/mysql-server status
 1072  13:44   history
root@g7:/usr/ports/databases/mysql56-server # mysql -V
mysql  Ver 14.14 Distrib 5.6.10, for FreeBSD9.1 (amd64) using  5.2
root@g7:/usr/ports/databases/mysql56-server #

--sql-mode=value[,value[,value...]]

http://search.net-newbie.com/mysql41/mysql-database-administration.html

オプション値として、次の任意の組み合わせを設定できる。

REAL_AS_FLOAT、PIPES_AS_CONCAT、ANSI_QUOTES、IGNORE_SPACE、ONLY_FULL_GROUP_BY、NO_UNSIGNED_SUBTRACTION、NO_AUTO_VALUE_ON_ZERO、NO_TABLE_OPTIONS、NO_FIELD_OPTIONS、NO_KEY_OPTIONS、NO_DIR_IN_CREATE、MYSQL323、MYSQL40、DB2、MAXDB、MSSQL、ORACLE、POSTGRESQL、および ANSI。

リセットするには、値を空白にする(--sql-mode="")。

NO_AUTO_VALUE_ON_ZERO は、AUTO_INCREMENT カラムの処理に影響を与える。通常、NULL または 0 のいずれかをカラムに挿入することにより、カラムの次のシーケンス番号を生成する。

NO_AUTO_VALUE_ON_ZERO を指定すると、0 のこの働きが抑制されるため、NULL だけが次のシーケンス番号を生成することになる。このモードは、0 がテーブルの AUTO_INCREMENT カラムに保存されている場合に役に立つ(これは推奨されている方法ではないが)。

たとえば、mysqldump でテーブルをダンプしてから再読み込みした場合、MySQL は通常、0 値に遭遇したときに新規シーケンス番号を生成するため、ダンプされたテーブルと再読み込みしたテーブルの内容が異なる結果になる。

この場合、ダンプしたファイルを再読み込みする前に NO_AUTO_VALUE_ON_ZERO を有効にするとこの問題が解決する(このオプションが使用可能になった MySQL 4.1.1 以降、mysqldump によるダンプ出力には、自動的に NO_AUTO_VALUE_ON_ZERO を有効にするためのステートメントが含まれている)。


mysql 56 から 55へダウングレード

したら、起動しなくなりますた。

/var/db/mysql/FQDN.err

130323 11:04:58 mysqld_safe mysqld from pid file /home/mysql/g7.kuji-clinic.net.pid ended
130323 11:05:15 mysqld_safe Starting mysqld daemon with databases from /home/mysql
130323 11:05:15 InnoDB: The InnoDB memory heap is disabled
130323 11:05:15 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130323 11:05:15 InnoDB: Compressed tables use zlib 1.2.7
130323 11:05:15 InnoDB: Initializing buffer pool, size = 128.0M
130323 11:05:15 InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 50331648 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
130323 11:05:15 [ERROR] Plugin 'InnoDB' init function returned error.
130323 11:05:15 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
130323 11:05:15 [ERROR] Unknown/unsupported storage engine: InnoDB
130323 11:05:15 [ERROR] Aborting

130323 11:05:15 [Note] /usr/local/libexec/mysqld: Shutdown complete

130323 11:05:15 mysqld_safe mysqld from pid file /home/mysql/g7.kuji-clinic.net.pid ended

ib_logfile0 と ib_logfile1 を消去するも、起動コマンドで再作成される。

130323 11:38:54 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

というエラーがでて、起動せず。

http://server-helper.doorblog.jp/archives/4988735.html

root@g7:/home/mysql # mysql_install_db

FATAL ERROR: Could not find ./bin/my_print_defaults

If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

root@g7:/home/mysql # locate /bin/my_print_defaults
/usr/home/Backups/222_all/usr/local/bin/my_print_defaults
/usr/local/bin/my_print_defaults
root@g7:/home/mysql #
root@g7:/home/mysql #
root@g7:/home/mysql #
root@g7:/home/mysql #
root@g7:/home/mysql #
root@g7:/home/mysql # cd /usr/local
root@g7:/usr/local # mysql_install_db
Installing MySQL system tables...
130323 11:45:54 [ERROR] ./libexec/mysqld: Incorrect information in file: './mysql/tables_priv.frm'
ERROR: 1033  Incorrect information in file: './mysql/tables_priv.frm'
130323 11:45:54 [ERROR] Aborting

130323 11:45:54 [Note] ./libexec/mysqld: Shutdown complete


Installation of system tables failed!  Examine the logs in
/home/mysql for more information.

You can try to start the mysqld daemon with:

    shell> ./libexec/mysqld --skip-grant &

and use the command line tool ./bin/mysql
to connect to the mysql database and look at the grant tables:

    shell> ./bin/mysql -u root mysql
    mysql> show tables

Try 'mysqld --help' if you have problems with paths.  Using --log
gives you a log in /home/mysql that may be helpful.

Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS.  Another information source are the
MySQL email archives available at http://lists.mysql.com/.

Please check all of the above before mailing us!  And remember, if
you do mail us, you MUST use the ./bin/mysqlbug script!

root@g7:/usr/local #
root@g7:/home/mysql # chown -R mysql:mysql /home/mysql/mysql

mysql root パスワードの変更 2013/03/07

mysql> SET PASSWORD FOR root@localhost=PASSWORD('hoge');
Query OK, 0 rows affected (0.00 sec)

g7へ導入 2012/12/20

g7# portinstall databases/mysql55-server
===> 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.28
===>   Registering installation for mysql-server-5.5.28
===> 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.28
[Updating the pkgdb <format:bdb_btree> in /var/db/pkg ... - 289 packages found (-0 +1) . done]
# cp /usr/local/share/mysql/my-large.cnf /usr/local/etc/my.cnf
# chmod 644 /usr/local/etc/my.cnf

デフォルトでは /var/db/mysql にデータベースファイルが作成されます。もし他の場所にしたい場合は rc.conf に以下のような設定を追加します。このディレクトリが起動時になければパーミッション 700、オーナー mysqlで作成されます。

mysql_dbdir="/path/to/mysql"

g7サーバでは、こんかいこれを

mysql_dbdir="/tank/mysql"

とした。

管理用テーブル作成SQL

mysqlにログイン

mysql -u

管理用テーブル作成SQL実行

source /usr/local/www/phpMyAdmin/examples/create_tables.sql
mysql> source /usr/local/www/phpMyAdmin/examples/create_tables.sql
Query OK, 1 row affected (0.01 sec)

Database changed
Query OK, 0 rows affected (0.05 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

mysql> grant all privileges on phpmyadmin.* to pma@localhost identified by '********';
Query OK, 0 rows affected (0.00 sec)

管理用テーブル用ユーザ作成(パスワードは適宜変更)

grant all privileges on phpmyadmin.* to pma@localhost identified by '*****';

設定ファイルをコピー

cp /usr/local/www/phpMyAdmin/config.sample.inc.php /usr/local/www/phpMyAdmin/config.inc.php

設定ファイルを編集

vi /usr/local/www/phpMyAdmin/config.inc.php
$cfg['Servers'][$i]['controlhost'] = ”;から
$cfg['Servers'][$i]['auth_swekey_config'] = ‘/etc/swekey-pma.conf’;まで

コメントを解除

http://FQDN/phpmyadmin でもアクセスするように

/usr/local/www/apache22/data/phpmyadmin という空ディレクトリを作っておく。:-)

server のmysql 51 から 55へ

MySQL51 で稼働中のサーバに55をインストールすると

===>   Registering installation for mysql55-client-5.5.44_1
Installing mysql55-client-5.5.44_1...
pkg-static: mysql55-client-5.5.44_1 conflicts with mysql51-client-5.1.73_3 (installs files into the same place).  Problematic file: /usr/local/bin/mysql
*** [fake-pkg] Error code 70

Stop in /usr/ports/databases/mysql55-client.
*** [install] Error code 1

となるため(あたりまえ?)

# pkg delete mysql51-client-5.1.73_3
Updating database digests format: 100%
Checking integrity... done (0 conflicting)
Deinstallation has been requested for the following 2 packages (of 0 packages in the universe):

Installed packages to be REMOVED:
        mysql51-client-5.1.73_3
        mysql51-server-5.1.73_2

The operation will free 59 MiB.

Proceed with deinstalling packages? [y/N]: y
[1/2] Deinstalling mysql51-server-5.1.73_2...
==> You should manually remove the "mysql" user.
[1/2] Deleting files for mysql51-server-5.1.73_2: 100%
[2/2] Deinstalling mysql51-client-5.1.73_3...
[2/2] Deleting files for mysql51-client-5.1.73_3: 100%

してから、

# portinstall databases/mysql55-client

続いて

# portinstall databases/mysql55-server

ここで、バージョン確認。

# mysql -V
mysql  Ver 14.14 Distrib 5.5.44, for FreeBSD9.3 (amd64) using  5.2

ここで、そのままupgradeしようとすると

# mysql_upgrade -u root -p
Enter password:
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
Error: Server version (5.1.73-log) does not match with the version of
the server (5.5.44) with which this program was built/distributed. You can
use --skip-version-check to skip this check.
FATAL ERROR: Upgrade failed

で、サーバをリスタートしてみる

# /usr/local/etc/rc.d/mysql-server restart
Stopping mysql.
Waiting for PIDS: 742, 742.
Starting mysql.

起動せず。・・・、もう一回

# mysql_upgrade -u root -p
Enter password:
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
FATAL ERROR: Upgrade failed

と、ここで、MySQL_Data_Dir/FQDN.err をみると、

[ERROR] /usr/local/libexec/mysqld: unknown option '--skip-locking'

エラーを参考にして、my.cnfを編集

skip-locking
      ↓
skip-external-locking

skip-federated 
      ↓ 
#skip-federated

で、55があがるっぽい。

ここで、mysql 51 でのdbを55へアップグレードする。

# mysql_upgrade -u root -p
Enter password:
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'
BB3.phpbb_acl_groups                               OK
BB3.phpbb_acl_options                              OK
BB3.phpbb_acl_roles                                OK
BB3.phpbb_acl_roles_data                           OK
BB3.phpbb_acl_users                                OK
BB3.phpbb_attachments                              OK
BB3.phpbb_banlist                                  OK
BB3.phpbb_bbcodes                                  OK
BB3.phpbb_bookmarks                                OK
BB3.phpbb_bots                                     OK
             :                :
             :                :
phpmyadmin.pma_column_info                         OK
phpmyadmin.pma_designer_coords                     OK
phpmyadmin.pma_history                             OK
phpmyadmin.pma_pdf_pages                           OK
phpmyadmin.pma_recent                              OK
phpmyadmin.pma_relation                            OK
phpmyadmin.pma_table_coords                        OK
phpmyadmin.pma_table_info                          OK
phpmyadmin.pma_table_uiprefs                       OK
phpmyadmin.pma_tracking                            OK
phpmyadmin.pma_userconfig                          OK
Running 'mysql_fix_privilege_tables'...
OK
#

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

phpmyadminで確認

ということで、DBが55にUPされたので、最新版のphpMyAdmin-4.4.14が使えるようになります。

phpmyadmin_mysql51to55.PNG

phpmyadmin のテーブルを作成する

phpMyAdminもアップされたので、追加されているテーブルを作る。

mysql -u root -p < /usr/local/www/phpMyAdmin/sql/create_tables.sql

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		= ****
socket		= /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
#port		= 3306
port		= ****
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 *.****                 *.*                    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>

添付ファイル: filephpmyadmin_mysql51to55.PNG 963件 [詳細] fileautomysqlbackup-2.5.1-01.sh 471件 [詳細]

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-01-18 (水) 08:53:59