LoginSignup
161
167

More than 5 years have passed since last update.

【MySQL, 開発環境】MySQLのインストールと初期設定

Last updated at Posted at 2014-11-02

前提

・CentOS6.5の環境でのお話です。
・今回利用するMySQLはyumでデフォルトで入る5.1.73のお話です。
・開発環境構築レベルの話なので、詳細なストレージエンジンの設定まではカバーしていません。

MySQLのインストール

# yum install mysql mysql-server mysql-devel -y

MySQLの起動と起動設定

MySQLの起動

# 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 localhost.localdomain 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 &

MySQLの自動起動の設定

サーバを再起動したりした時に自動的にMySQLも起動するように設定

# chkconfig mysqld on

MySQLの基本設定

MySQLをインストールすると使えるようになる、mysql_secure_installationコマンドを実行し、
インストール後の初期設定を行います。

# 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パスワードを設定するので「Y」。
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     <----- 誰でもログインできる状態になっているのでそれをRemoveするので「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でMySQLにリモートログインできるのはセキュリティ的にNGなので「Y」。
 ... 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  <----- testデータベースは不要のため「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    <----- 上記設定による権限の変更等を即時反映したいので「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!

my.cnfの編集

my.cnfファイルとはMySQLの設定を記述するファイルです。
MySQL5.1.73だと /etc/my.cnfに、設定ファイルが存在します。

文字コード設定の編集

# vi /etc/my.cnf
[mysqld]
+ character-set-server=utf8 <-----[mysqld]のセクションの下部に左記を追記。

+ [mysql]                       <-----[mysql]のセクション自体を追記。
+ default-character-set=utf8        <----- [mysql]のセクション以下に左記を追記。

ストレージエンジンの設定

# vi /etc/my.cnf
[mysqld]
+ default-storage-engine=InnoDB     <----- [mysqld]のセクション下部に左記を追記, デフォルトで利用するストレージエンジンにInnoDBを指定。
+ innodb_file_per_table             <----- [mysqld]のセクション下部に左記を追記, InnoDBのファイルをテーブル毎に作成するように指定。

編集したmy.cnf設定の反映

# service mysqld restart    <----- 再起動して設定をMySQLに反映

まとめ

以上で基本的な開発環境のMySQLの設定は終了です。

161
167
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
161
167