6-1-4 データベースの用意
「eコミグループウェアインストールマニュアル」の「1.7 データベースの用意」を参考にします。
MySQL の設定
「DB サーバー(MySQL)のインストールと設定 〜 CentOS6(http://easyramble.com/install-setup-mysql.html)」などを参考にします。
MySQL バージョンを確認します。
[user@centos6 ~]$ su - パスワード: [root@centos6 ~]# mysql -V mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
my.cnf ファイルを編集して文字コードを設定します。
[root@centos6 ~]# vim /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 character-set-server=utf8 # 追加 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [mysql] # 追加 default-character-set=utf8 # 追加
自動起動を設定します。
[root@centos6 ~]# chkconfig --list |grep mysql mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@centos6 ~]# chkconfig mysqld on [root@centos6 ~]# service 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 centos6.myhome.net 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. 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 /usr/mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/bin/mysqlbug script! [ OK ] mysqld を起動中: [ OK ]
[root@centos6 ~]# chkconfig --list |grep mysql mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off対話モードで初期設定をします。
[root@centos6 ~]# 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): # rootパスワードは空なので Enter キーを押します。 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 # root のパスワードを設定するので。 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 # root によるリモートのログインを拒否するので ... 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!MySQL のデータベースを確認します。
[root@centos6 ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, 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 databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | +--------------------+ 2 rows in set (0.00 sec)MySQL ユーザを確認します。
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed
mysql> SELECT user, password, host FROM user; +------+-------------------------------------------+-----------+ | user | password | host | +------+-------------------------------------------+-----------+ | root | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA | localhost | | root | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA | 127.0.0.1 | +------+-------------------------------------------+-----------+ 2 rows in set (0.00 sec)MySQL サーバ
サーバ(ホスト)名は、「localhost」、「127.0.0.1」、または、次のコマンドで確認します。
mysql> show variables like 'hostname'; +---------------+--------------------+ | Variable_name | Value | +---------------+--------------------+ | hostname | centos6.myhome.net | +---------------+--------------------+ 1 row in set (0.00 sec)MySQL 接続ユーザ、接続パスワード
データベースに接続するユーザを次のコマンドで作成します。
mysql> CREATE USER 'gware'@'localhost' IDENTIFIED BY 'gware'; Query OK, 0 rows affected (0.00 sec) mysql> SELECT user, host FROM mysql.user; +-------+-----------+ | user | host | +-------+-----------+ | root | 127.0.0.1 | | gware | localhost | | root | localhost | +-------+-----------+ 3 rows in set (0.00 sec) mysql> show grants for 'gware'@'localhost'; +--------------------------------------------------------------------------------------------------------------+ | Grants for gware@localhost | +--------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'gware'@'localhost' IDENTIFIED BY PASSWORD '*E945979236735ADEDD4C55F67E06AAB3ED13D56A' | +--------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)MySQL データベース
ecomgware というデータベースを作成します。
mysql> CREATE DATABASE ecomgware; Query OK, 1 row affected (0.00 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | ecomgware | | mysql | +--------------------+ 3 rows in set (0.00 sec)gware ユーザで ecomgware データベースに接続します。gware ユーザに ecomgware データベース権限を適用します。
mysql> GRANT all ON ecomgware.* TO 'gware'@'localhost'; Query OK, 0 rows affected (0.00 sec) mysql> show grants for 'gware'@'localhost'; +--------------------------------------------------------------------------------------------------------------+ | Grants for gware@localhost | +--------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'gware'@'localhost' IDENTIFIED BY PASSWORD '*E945979236735ADEDD4C55F67E06AAB3ED13D56A' | | GRANT ALL PRIVILEGES ON `ecomgware`.* TO 'gware'@'localhost' | +--------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)
gware ユーザで ecomgware データベースに接続します。
mysql> quit Bye [nob61@centos6 ~]$ mysql -u gware -p ecomgware Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, 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> quit Bye
0 件のコメント:
コメントを投稿