MySQL、PHPの設定とデータベース作成
2015年3月24日(火)

データベースの初期設定
MySQLのセキュアインストレーションを実行する
[root@www ~]# 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): ⏎ (1) 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 (2) New password: (3) Re-enter new password: (4) Password updated successfully! Reloading privilege tables.. ... Success! (省略) Remove anonymous users? [Y/n] y (5) ... 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 (5) ... 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 (5) - 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 (5) ... Success! (省略) Thanks for using MySQL! (6) [root@www ~]#
- vを入力
- Yを入力する
- パスワードを入力する
- 再度パスワードを入力する
- Yを入力する
- MySQLの設定が終了
my.cnfを設定する
MySQLの文字コードの設定を確認します。デフォルトでは、UTF-8に設定されています。
MySQLの設定ファイル
[root@www ~]# vi /etc/my.cnf⏎
viが起動しました。
[mysqld] (1) 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 skip-character-set-client-handshake [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [client] (2) default-character-set=utf8 [mysql] (3) default-character-set=utf8
- MySQLサーバーの設定
- MySQLクライアントの設定
- MySQL全体の設定
保存して終了します。
MySQLのシステム構成は
MySQLは、データベースを管理するMySQLサーバーとユーザーがコマンドを入力するクライアントによって構成されています。端末の画面に「mysql>」といプロンプトを出しているのは、SQL文を入力するためのクライアントプログラムです。MySQLサーバーは、「mysql51」というサービスとして実行されています。
MySQLのコマンドについて
MySQLのデータベースに対して実行される命令は、SQL文と呼ばれるもので、リレーショナルデータベースの命令文として、標準化されているものです。SQL文や独自のコマンドも含め、大文字小文字の区別などはありません。ただ、慣習的に予約語(SQL文やコマンド)は、データベース名やテーブル名と区別しやすいように、大文字で表記されることが多いようです。ここでもその例にならっていますが、入力はすべて小文字で入力しても問題ありません。
MySQLのユーザー管理
MySQLで登録するroot、MySQLユーザーは、Linuxで登録されているスーパーユーザーや一般ユーザーとは別に、MySQL自体で管理しているものです。
データベース操作
CREATE DATABASEは、データベースの作成、GRANT ALL PRIVILEGES ONは、MySQLユーザーの権限を設定するSQL文です。SQL文の詳細については、MySQLの解説書を参考にしてください。
wordpressデータベースの作成
MySQLを起動します。データベース名、ユーザー名、パスワードは、すべて「wordpress」になります。
[root@www ~]# mysql -u root -p⏎ Enter password: (1) Welcome to the MySQL monitor. Commands end with ; or ¥g. Your MySQL connection id is 13 Server version: 5.1.71 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> mysql> CREATE DATABASE wordpress ;⏎ (2) Query OK, 1 row affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON wordpress.* TO wordpress@localhost identified by "wordpress" ;⏎ (3) Query OK, 0 rows affected (0.00 sec) mysql> mysql> FLUSH PRIVILEGES ;⏎ (4) Query OK, 0 rows affected (0.00 sec) mysql> quit⏎ (5)
- パスワードを入力
- wordpressデータベースを作成
- 権限、ユーザー名、パスワードの設定
- 権限の書き込み
- MySQLを終了する
連載バックナンバー
Think ITメルマガ会員登録受付中
Think ITでは、技術情報が詰まったメールマガジン「Think IT Weekly」の配信サービスを提供しています。メルマガ会員登録を済ませれば、メルマガだけでなく、さまざまな限定特典を入手できるようになります。
全文検索エンジンによるおすすめ記事
- WordPress コース 2nd Stage を攻略しよう(Linux 仮想マシン編)
- ownCloud導入はじめの一歩(仮想マシンイメージとCentOS 7のインストール手順)
- Windows AzureにPerlのアプリケーションをインストールする(クエスト9)
- CentOSにインストールするWordPressパッケージの入手
- PHPによるファイルアップロード処理のあれこれ
- Serverspecテストコード実例の紹介とコード記述の際のポイント
- MySQLの準備とOSSインストール
- Pythonで作られた便利なコマンドラインツール MySQL Utilities
- NginxでハイパフォーマンスWordPress in SoftLayer
- Windows Azure上にLinuxインスタンスを立ち上げる(クエスト5)