mysql-server をインストールする
インストールをした後に、デーモンとしての設定を行う。
そのあと、MySQL に登録されているユーザーのパスワードを設定し、セキュリティ上の観点から匿名ユーザーを削除する。
# yum search mysql-server Loading "installonlyn" plugin Setting up repositories Reading repository metadata in from local files mysql-server.i386 5.0.22-2.2.el5_1.1 update Matched from: mysql-server mysql-server.i386 5.0.22-2.1.0.1 base Matched from: mysql-server # yum -y install mysql-server # cp /etc/my.cnf /etc/my.cnf.orig # vi /etc/my.cnf # cat /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwords=1 default-character-set=utf8 [mysql.server] user=mysql basedir=/var/lib [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [mysql] default-character-set=utf8 # /etc/rc.d/init.d/mysqld start Initializing MySQL database: Installing all prepared tables Fill help tables 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 little password 'new-password' See the manual for more instructions. You can start the MySQL daemon with: cd /usr ; /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 http://shop.mysql.com [ OK ] Starting MySQL: [ OK ] # chkconfig --list mysqld mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off # chkconfig mysqld on # chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off # mysql -u root <- root ユーザーでログイン Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 to server version: 5.0.22 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> select user, host, password from mysql.user; <- 登録されているユーザーを表示 +------+-----------+----------+ | user | host | password | +------+-----------+----------+ | root | localhost | | | root | little | | | | little | | | | localhost | | +------+-----------+----------+ 4 rows in set (0.01 sec) mysql> set password for root@localhost=password('mypassword'); <- パスワードを設定する Query OK, 0 rows affected (0.00 sec) mysql> set password for root@little=password('mypassword'); <- パスワードを設定する Query OK, 0 rows affected (0.00 sec) mysql> select user, host, password from mysql.user; <- パスワードが設定されたかを確認する +------+-----------+------------------+ | user | host | password | +------+-----------+------------------+ | root | localhost | **************** | | root | little | **************** | | | little | | | | localhost | | +------+-----------+------------------+ 4 rows in set (0.00 sec) mysql> exit Bye # mysql -u root <- パスワードなしでログインできないことを確認する ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) # mysql -u root -h little <- パスワードなしでログインできないことを確認する ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) # mysql -u root -p <- パスワードを入力してログインできることを確認する Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 to server version: 5.0.22 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> exit Bye # mysql -u root -h little -p <- パスワードを入力してログインできることを確認する Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 to server version: 5.0.22 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> exit Bye mysql> select user, host from mysql.user; <- 登録されているユーザーを表示 +------+-----------+ | user | host | +------+-----------+ | | little | | root | little | | | localhost | | root | localhost | +------+-----------+ 4 rows in set (0.00 sec) mysql> select user, host from mysql.user where user=''; <- 匿名ユーザーのみを表示する +------+-----------+ | user | host | +------+-----------+ | | little | | | localhost | +------+-----------+ 2 rows in set (0.00 sec) mysql> delete from mysql.user where user=''; <- セキュリティ上の理由で匿名ユーザーを削除する Query OK, 2 rows affected (0.00 sec) mysql> select user, host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | little | | root | localhost | +------+-----------+ 2 rows in set (0.00 sec) mysql> exit Bye #