月別アーカイブ: 2010年3月

CentOS4.6+MySQL 4.0.26 その2

昨年末より色々と調べていた、MySQL 4.0.26 の設置にようやく成功した。

# rpm -ivh ./MySQL-server-4.0.26-0.i386.rpm
Preparing...                ########################################### [100%]
1:MySQL-server           ########################################### [100%]
Preparing db table
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
Fatal error: Can't change to run as user 'mysql'.  Please check that the user exists!
091130  7:05:11 Aborting
091130  7:05:11 /usr/sbin/mysqld: Shutdown Complete
Installation of grant tables failed!
Examine the logs in /var/lib/mysql for more information.
You can also try to start the mysqld daemon with:
/usr/sbin/mysqld --skip-grant &
You can use the command line tool
/usr/bin/mysql to connect to the mysql
database and look at the grant tables:
shell> /usr/bin/mysql -u root mysql
mysql> show tables
Try 'mysqld --help' if you have problems with paths. Using --log
gives you a log in /var/lib/mysql that may be helpful.
The latest information about MySQL is available on the web at
http://www.mysql.com
Please consult the MySQL manual section: 'Problems running mysql_install_db',
and the manual section that describes problems on your OS.
Another information source is the MySQL email archive.
Please check all of the above before mailing us!
And if you do mail us, you MUST use the /usr/bin/mysqlbug script!

とりあえず、以下コマンドにて、ちゃんとmysqlという名称のDBが設置されているかどうか、確認した。

# mysql -u root mysql

すると、

-bash: mysql: command not found

との事。

mysql のクライアントを入れ忘れていたので、他のも含めてインストール。

# rpm -ivh MySQL-client-4.0.26-0.i386.rpm
# rpm -ivh MySQL-devel-4.0.26-0.i386.rpm
# rpm -ivh MySQL-Max-4.0.26-0.i386.rpm

でもって、再度「mysql -u root mysql」を実行も、mysql自体が動いていないから見れないわけで・・・

/etc/my.cnf を作って、mysqlのログを吐くように指定などなど。

# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
[mysql.server]
user=mysql
basedir=/var/lib
[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

でもって、「/etc/rc.d/init.d/mysql start」を実行も、動かない。

ログを参照したところ、以下が出力されていましたわ。

100309 03:18:51  mysqld started
100309  3:18:51  InnoDB: Started
100309  3:18:51 Fatal error: Can't open privilege tables: Table 'mysql.host' doesn't exist
100309  3:18:51 Aborting
100309  3:18:51  InnoDB: Starting shutdown...
100309  3:18:53  InnoDB: Shutdown completed
100309  3:18:53 /usr/sbin/mysqld-max: Shutdown Complete
100309 03:18:53  mysqld ended

あれ?

そもそも、「mysql.host」が無いって、ダメじゃね?

って事で、色々とまた調査開始。

そう言えば、postgreSQLは「initdb」とかあったな、とか思って、実はMySQLでも必要じゃね?と。

ありました。

「mysql_install_db」が。

つか、最初のエラーメッセージのところにも、ちゃんと書いてあったね。。。

「’Problems running mysql_install_db’」

って。。。

早速実行。

/usr/bin/mysql_install_db
# mysql_install_db
Neither host 'localhost.localdomain' nor 'localhost' could not be looked up with
/usr/bin/resolveip
Please configure the 'hostname' command to return a correct hostname.
If you want to solve this at a later stage, restart this script with
the --force option

おう?

ホスト名を設定しろって事かね?

とりあえず、ホスト名を設定。

hostname www.example.com

再度実行。

/usr/bin/mysql_install_db
# mysql_install_db
Neither host 'www.example.com' nor 'localhost' could not be looked up with
/usr/bin/resolveip
Please configure the 'hostname' command to return a correct hostname.
If you want to solve this at a later stage, restart this script with
the --force option

あれ?

また調査開始。

「–no-defaults」オプションを付けると出来るってエントリがあったので、やってみたけど、結果変わらず。

エラーメッセージを良く読んだところ、「–force」を付けろとの事。

やってみた。

# /usr/bin/mysql_install_db --force
Preparing db table
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
100309  3:29:05 /usr/sbin/mysqld: Shutdown Complete
To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system
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 www.example.com password 'new-password'
See the manual for more instructions.
You can start the MySQL daemon with:
cd / ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
cd sql-bench ; perl run-all-tests
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at https://order.mysql.com

ふむ、どうやら出来たっぽい。

では、起動してみようって事で「/etc/rc.d/init.d/mysql start」を実行。

しかし、起動せず。

エラーログ参照。

100309 03:29:46  mysqld started
100309  3:29:46  InnoDB: Started
100309  3:29:46 /usr/sbin/mysqld-max: Can't find file: './mysql/host.frm' (errno: 13)
100309  3:29:46 Fatal error: Can't open privilege tables: Can't find file: './mysql/host.frm' (errno: 13)
100309  3:29:46 Aborting
100309  3:29:46  InnoDB: Starting shutdown...
100309  3:29:48  InnoDB: Shutdown completed
100309  3:29:48 /usr/sbin/mysqld-max: Shutdown Complete
100309 03:29:48  mysqld ended

エラーログ変わった。

「host.frm」が無い?

あぁ~・・・

多分、パーミッションの問題っぽい。

って事で、パーミッションの設定を実施。

# cd /var/lib/mysql
# chown -R mysql:mysql ./mysql

んでもって、起動スクリプトを実施。

ログを参照。

100309 03:31:04  mysqld started
100309  3:31:04  InnoDB: Started
/usr/sbin/mysqld-max: ready for connections.
Version: '4.0.26-Max'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Official MySQL RPM

プロセスを参照。

# ps auxwww | grep mysql
root      2531  0.0  0.1   2412  1076 pts/0    S    03:31   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/www.example.com.pid
mysql     2562  0.0  1.5 120272 15792 pts/0    Sl   03:31   0:00 /usr/sbin/mysqld-max --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/www.example.com.pid --skip-locking --socket=/var/lib/mysql/mysql.sock

動いた!!!!

長い闘いは終わった・・・

あとは、Webのミドルウェアとの繋ぎ込みだな。

でわ。

MySQL備忘録-その1

■auto_incrementの値を初期化する方法

該当テーブルのレコードを全て削除し、以下SQLを発行する。

ALTER TABLE TABLE_NAME AUTO_INCREMENT = 1;

■重複レコードを抽出する方法

SELECT * FROM TABLE_NAME GROUP BY FIELD_A HAVING COUNT(FIELD_A) > 1;

ちょっとした事だし、忘れそうなので、書いておきます。

でわ。