MySQL5.5へのアップグレード

概要
MySQL5.0.xxから、MySQL5.5.xxヘバージョンアップを行った。
システム環境

[root@service etc]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)

手順
(1)バックアップ
失敗して後悔しないように、まずは現行データベースの内容をバックアップ

[root@service Backup]# mysqldump -uopentech -popentech --all-databases > all.mysql.dmp

(2)現在のインストール状態を確認

[root@service tmp]# rpm -qa mysql*
mysql-server-5.0.77-4.el5_4.2
mysql-connector-odbc-3.51.26r1127-1.el5
mysql-5.0.77-4.el5_4.2
mysql-5.0.77-4.el5_4.2
[root@service tmp]#

(3)旧パッケージを削除

[root@service tmp]# rpm -e mysql-server-5.0.77-4.el5_4.2
[root@service tmp]# rpm -e mysql-connector-odbc-3.51.26r1127-1.el5
[root@service tmp]# rpm -e mysql-5.0.77-4.el5_4.2
error: "mysql-5.0.77-4.el5_4.2" specifies multiple packages

ここでエラーが発生。よく見ると、同じパッケージが2つインストールされている!?
rpmのデータベースが壊れているかと思い、いろいろと対処。

[root@service tmp]# rpm -qa mysql*
mysql-5.0.77-4.el5_4.2
mysql-5.0.77-4.el5_4.2
[root@service tmp]# rpm --rebuilddb
[root@service tmp]# rpm -qa mysql*
mysql-5.0.77-4.el5_4.2
mysql-5.0.77-4.el5_4.2
[root@service tmp]#

フトした拍子に、パッケージ名の詳細が異なるものが2つインストールされている事に気づく!
下記の通り指定したら削除できた。

[root@service tmp]# rpm -e mysql-5.0.77-4.el5_4.2.i386
[root@service tmp]# rpm -qa mysql*
mysql-5.0.77-4.el5_4.2
[root@service tmp]# rpm -e mysql-5.0.77-4.el5_4.2
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
[root@service tmp]#

(4) ダウンロードしてきた新ばーじょんのzipファイルを解凍してからインストールを実施。

[root@service tmp]# rpm -iv MySQL-server-5.5.16-1.rhel5.x86_64.rpm
Preparing packages for installation...
MySQL-server-5.5.16-1.rhel5

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h service.opentechnobox.com password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

Please report any problems with the /usr/bin/mysqlbug script!

[root@service tmp]# rpm -iv MySQL-client-5.5.16-1.rhel5.x86_64.rpm
Preparing packages for installation...
MySQL-client-5.5.16-1.rhel5
[root@service tmp]# rpm -iv MySQL-shared-5.5.16-1.rhel5.x86_64.rpm
Preparing packages for installation...
MySQL-shared-5.5.16-1.rhel5
[root@service tmp]#

この時点ですでにMySQLを利用可能。

[root@service tmp]# service mysql start
Starting MySQL.. SUCCESS!
[root@service tmp]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.16 MySQL Community Server (GPL)

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> exit
Bye
[root@service tmp]# service mysql stop
Shutting down MySQL. SUCCESS!
[root@service tmp]#

(5) 新たなmy.cnfをコピー

[root@service etc]# find / -name my*cnf -print
/usr/share/mysql/my-huge.cnf
/usr/share/mysql/my-small.cnf
/usr/share/mysql/my-medium.cnf
/usr/share/mysql/my-innodb-heavy-4G.cnf
/usr/share/mysql/my-large.cnf
/usr/share/doc/MySQL-server-5.5.16/my-huge.cnf
/usr/share/doc/MySQL-server-5.5.16/my-small.cnf
/usr/share/doc/MySQL-server-5.5.16/my-medium.cnf
/usr/share/doc/MySQL-server-5.5.16/my-innodb-heavy-4G.cnf
/usr/share/doc/MySQL-server-5.5.16/my-large.cnf
[root@service etc]# cp /usr/share/mysql/my-huge.cnf .
[root@service etc]#

(6) セキュリティ設定
このままだと、パスワード無しでも使えてしまうので、インストール時のコメント通りに最低限のセキュリティ設定を実施。

[root@service etc]# service mysql start
Starting MySQL.. SUCCESS!
[root@service etc]# /usr/bin/mysql_secure_installation




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): ← リターン
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: ← 新パスワードを入力
Re-enter new password: ← 新パスワードを再入力
Password updated successfully!
Reloading privilege tables..
... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
... Success!

Cleaning up...



All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


[root@service etc]#

(6) character-set指定
character-setをutf8にするためにmy.cnfを編集

[root@service etc]# vi my.cnf

・・・
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8
# Here follows entries for some specific programs

# The MySQL server
[mysqld]
default-character-set=utf8
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-locking
・・・

これでよしと再起動したらエラーが発生!!

[root@service etc]# service mysql start
Starting MySQL... ERROR! The server quit without updating PID file (/var/lib/mysql/service.opentechno.com.pid).

調べてみたら、MySQL5.5から記述方法が変わったとの事でした。
次の様に再度修正。

・・・
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
character-set-server=utf8
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-locking
・・・

以上で、MySQL5.5.16のインストール完了。

以上