mysqlサーバ構築 †ウェブサービスをやろうとした場合、自作して小さい規模ではじめるならファイルに保存するなど、 DBにはmysql,postgres,sqlite,sqlserver,oracleなどいくつか種類がありますが、 mysql-serverインストール †yumを使ってmysql-serverをインストールします。 # yum -y install mysql-server Setting up Install Process Parsing package install arguments Resolving Dependencies --> Running transaction check ---> Package mysql-server.i386 0:5.0.45-6.fc8 set to be updated --> Finished Dependency Resolution Dependencies Resolved ============================================================================= Package Arch Version Repository Size ============================================================================= Installing: mysql-server i386 5.0.45-6.fc8 updates 9.8 M Transaction Summary ============================================================================= Install 1 Package(s) Update 0 Package(s) Remove 0 Package(s) Total download size: 9.8 M Downloading Packages: (1/1): mysql-server-5.0.4 100% |=========================| 9.8 MB 00:07 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing: mysql-server ######################### [1/1] Installed: mysql-server.i386 0:5.0.45-6.fc8 Complete* mysqlの設定 †mysqlの設定は、/etc/my.cnfで行います。 default-character-set=utf8 を追加します。 [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # 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] default-character-set=utf8 mysql起動 †/etc/rc.d/init.d/mysqld start # /etc/rc.d/init.d/mysqld start
MySQL データベースを初期化中: Installing MySQL system tables...
OK
Filling help tables...
OK
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.longearth.net 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 mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
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 ]
MySQL を起動中: [ OK ]
mysqlの自動起動登録 †mysqlを電源ON時に自動起動させるために、軌道登録をします。 # chkconfig --list mysqld mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off すべてのランレベルでoffとなっていたら、2-5のレベルで起動するよう登録する。 # chkconfig mysqld on 登録されたか確認する。 # chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off rootの設定 †defaultでは、mysqlのrootユーザはパスワードが設定されていません。 # mysql -u root mysqlのユーザ情報は、mysqlスキーマのuserテーブルで管理されています。 mysql> select user , host , password from mysql.user; +------+-------------------+----------+ | user | host | password | +------+-------------------+----------+ | root | localhost | | | root | www.longearth.net | | | root | 127.0.0.1 | | +------+-------------------+----------+ 3 rows in set (0.00 sec) ユーザはroot一人だけですが、hostがlocalhost,www.longearth.net,127.0.0.1の3つが設定されています。 とりあえず、3ホスト分パスワードを登録します。
mysql> set password for root@localhost=password('password');
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@www.longearth.net=password('password');
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@127.0.0.1=password('password');
Query OK, 0 rows affected (0.00 sec)
確認してみる †設定されたか確認してみます。 mysql> select user , host , password from mysql.user; +------+-------------------+------------------+ | user | host | password | +------+-------------------+------------------+ | root | localhost | 7259fa7604f34644 | | root | www.longearth.net | 7259fa7604f34644 | | root | 127.0.0.1 | 7259fa7604f34644 | +------+-------------------+------------------+ 3 rows in set (0.00 sec) 暗号化されていますが、パスワードが設定されていることが分かります。 ユーザ追加してみる †mtスキーマの全テーブルに対して、全権限を持ったmtユーザ(localhostから接続)で、 mysql> grant all privileges on mt.* to mt@localhost identified by 'mt' with grant option; Query OK, 0 rows affected (0.00 sec) grant all privilegesで全ての権限を指定しています。select,insert権限のみを与える場合は、grant select,insertとなります。 ユーザを削除してみる †grant許可ユーザなんていらないので、早々に削除します。 mysql> delete from mysql.user where user='mt'; Query OK, 1 row affected (0.00 sec) 以上。 |