はじめに
CentOS6系の標準リポジトリのMySQLはバージョン5.1なので
それ以外のバージョンを使用するには、自分で該当バージョンのリポジトリを追加して
インストールする作業が必要になります。
かつてはBaseリポジトリのmysql-libsパッケージの依存関係で
スムーズにインストールが出来なかったこともあるようですが
5.7.10では問題なくmysql-libsパッケージをmysql-community-libs-5.7.10にアップグレードしてくれました。
(※2016-01-31現在の情報です)
Yumリポジトリ追加
YumリポジトリダウンロードURLは以下で確認 (※2016-01-31現在)
http://dev.mysql.com/downloads/repo/yum/
以下で追加する
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm
パッケージ情報確認
バージョン等を確認する
yum info mysql-community-server
MySQLインストール
yum install mysql-community-server
インストール確認
rpm -qa | grep mysql
mysql --version
my.cnfの編集
cp -p /etc/my.cnf /etc/my.cnf.orig
vi /etc/my.cnf
[mysqld]
character-set-server=utf8 <-- [mysqld]セクションに追加する
サービス起動
service mysqld start
初期パスワード確認
grep 'temporary password' /var/log/mysqld.log
セキュリティ設定 (mysql_secure_installationコマンド)
※初期パスワードが必要
※ローカルの開発環境では不要かも
# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: (※1)
The existing password for the user account root has expired. Please set a new password.
New password: (※2)
Re-enter new password: (※3)
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n (※4)
... skipping.
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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y (※6)
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? (Press y|Y for Yes, any other key for No) : y (※7)
- 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? (Press y|Y for Yes, any other key for No) : y (※8)
Success.
All done!
============================================================
(※1) Enter password for user root: で root の初期パスワードを入力する。
(※2) New password: で root の新しいパスワードを入力する。
(使用する文字は数字・英小文字・英大文字・記号を混在する必要あり)
(※3) Re-enter new password: で root の新しいパスワードをもう1度入力する。
(※4) Estimated strength of the password: 100 ... でより強固なパスワードに変更するか応答する。
(※5) Remove anonymous users? で匿名ユーザを削除するか応答する。
(※6) Disallow root login remotely? で root のリモート接続可否を応答する。
(※7) Remove test database and access to it? でテストデータベースを削除するか応答する。
(※8) Reload privilege tables now? で権限テーブルを即時リロードするか応答する。
パスワード入力を省略したい場合
MySQLは実行ユーザーの$HOME/.my.cnfファイルを参照するので
クライアント設定としてパスワードを記述しておくと入力を省略することが可能。
touch $HOME/.my.cnf
chmod 600 $HOME/.my.cnf
vi $HOME/.my.cnf
[client]
password="パスワード"
※ファイルの権限は600に設定しておく。
※クライアント設定を記述するためのファイルなのでパスワード専用ではない。
※ここで設定するパスワードは実行時のデフォルトパスワードになり
ユーザー毎に異なるパスワードを設定している場合は対応できません。
自動起動ON
chkconfig mysqld on
接続
mysql -u root -p
mysql -u root (パスワード省略時)