まず、コンパイルにcmake-2.8.2以上が必須。centosで提供されているcmakeは2.6.4なので、別途epelリポジトリからインストールを行う。guiな画面でコンパイルできる便利なcmake28-guiがあるけど、ここではコマンドラインのcmake28のみを使う
[root@c ~]# yum --enablerepo=epel install cmake28
mysqlデータベースを動かすユーザを別途作る。uid/gidは適当で構わないがyumでmysqlをインストールしたときに使われるuid/gidを継承した。
[root@c ~]# groupadd -r -g 27 mysql
[root@c ~]# useradd -r -g mysql -d /opt/mysql -m -u 27 mysql
管理者権限[root]のままコンパイル・インストールを行う
[root@c ~]# mkdir /opt/src; cd /opt/src
[root@c src]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.19.tar.gz
[root@c src]# gzip -cd mysql-5.6.19.tar.gz | tar xf -
[root@c src]# mkdir mysql-5.6.19-build; cd mysql-5.6.19-build
[root@c mysql-5.6.19-build]#
[root@c mysql-5.6.19-build]# cmake28 ../mysql-5.6.19 \
-DCMAKE_INSTALL_PREFIX=/opt/mysql/5.6.19 \
-DMYSQL_DATADIR=/opt/mysql/data \
-SYSCONFDIR=/etc \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
[root@c mysql-5.6.19-build]# make && make test && make install
[root@c mysql-5.6.19-build]# cd /opt/mysql
[root@c mysql]# ln -s 5.6.19 curt
[root@c mysql]# cd curt/
[root@c curt]#
[root@c curt]# ls -CF
COPYING README data/ include/ man/ scripts/ sql-bench/
INSTALL-BINARY bin/ docs/ lib/ mysql-test/ share/ support-files/
[root@c curt]#
データベース作成
[root@c ~]# cd /opt/mysql/curt
[root@c curt]# ./scripts/mysql_install_db --user=mysql --datadir=/opt/mysql/data
[root@c curt]# ls -CF
COPYING README data/ include/ man/ mysql-test/ share/ support-files/
INSTALL-BINARY bin/ docs/ lib/ my.cnf scripts/ sql-bench/
[root@c curt]#
これで /opt/mysql/dataが作成され、同時に /opt/mysql/curt/my.cnf が作られる
引き続き、自動起動設定
[root@c curt]# cp ./support-files/mysql.server /etc/init.d
[root@c curt]# chkconfig --add mysql.server
[root@c curt]# chkconfig --list mysql.server
mysql.server 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@c curt]#
ここで一旦mysqlを稼働させてみる
[root@c curt]# /etc/init.d/mysql.server start
Starting MySQL... SUCCESS!
[root@c curt]#
その後、ツール(mysql_secure_installation)を使ってrootのパスワード定義と不要なデータベースを削除します
[root@c curt]# ./bin/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): *そのままリターン(まだ定義してないので)
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
New password: *ここでrootのパスワードを定義
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] *不要なユーザを削除
... 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 *testデータベースは削除
- 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!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
[root@c curt]#
これで完了。
試しにrootユーザでアクセスしてみる
[root@c ~]# /opt/mysql/curt/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.6.19 Source distribution
Copyright (c) 2000, 2014, 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 |
| performance_schema |
+--------------------+
3 rows in set (0.06 sec)
mysql> quit
Bye
[root@c ~]#
php-mysqlはlocalhost接続先では /var/lib/mysql/mysql.sock を参照しているそうな。
っで、ここで作ったMySQLのsocketは /tmp/mysql.sock である(mysql_config --socket から)。
はてどちらを修正した方がいいのか。php-mysql?それともmysql側?
php-mysqlならphp.iniで
mysql.default_socket = /tmp/mysql.sock
と指定するか、逆に
[root@c ~]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
とリンクで逃げる
mysqlなら、my.cnfで
[client]
socket=/var/lib/mysql/mysql.sock
[mysqld]
socket=/var/lib/mysql/mysql.sock
とする。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
この段階での状況確認
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
コマンドラインからは
1 2 3 |
|
ちみに削除は
mysqladmin -u root -p drop xoops
1.同じマシン(localhost)からユーザfooは、特定のデータベースにあるテーブルTABLE_BのみSELECT権限を持つ
|
*注意:データベース名とかテーブル名の大文字小文字は区別するみたい。
2.リモート(%)からユーザfooは、DB_A上の全てのテーブルにSELECT権限を持つ
|
3.同じマシン(localhost)からユーザfooは、全てのデータベースの全てのテーブルにSELECT権限を持つ
|
4.リモートからユーザfooは、DB_A上の全てのテーブルに参照、登録、更新、削除、INDEX付与、テーブル変更権限を持つ
|
5.単純にすべての権限をもつユーザ
|