Serversman@VPSにMySQLをインストールした際の備忘録
インストールとデフォルト
$ sudo yum install mysql-devel mysql-server ==================================================================================================== Package Arch Version Repository Size ==================================================================================================== Installing: mysql-devel x86_64 5.0.77-4.el5_6.6 base 2.5 M mysql-server x86_64 5.0.77-4.el5_6.6 base 9.8 M Installing for dependencies: mysql x86_64 5.0.77-4.el5_6.6 base 4.8 M perl-DBD-MySQL x86_64 3.0007-2.el5 base 148 k perl-DBI x86_64 1.52-2.el5 base 600 k Transaction Summary ====================================================================================================
インストール直後のmy.cnf
$ cat /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwords=1 # Disabling symbolic-links is recommended to prevent assorted security risks; # to do so, uncomment this line: # symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
データベース初期化
$ sudo /etc/init.d/mysqld start MySQL データベースを初期化中: WARNING: The host 'dti-vps-srv00' could not be looked up with resolveip. This probably means that your libc libraries are not 100 % compatible with this binary MySQL version. The MySQL daemon, mysqld, should work normally with the exception that host name resolving will not work. This means that you should use IP addresses instead of hostnames when specifying MySQL privileges ! 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 dti-vps-srv06 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 mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/bin/mysqlbug script! The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com [ OK ] MySQL を起動中: [ OK ]
メッセージ中に書いてある、MySQLのテストができるmysql-test-run.pl
と言うのがあるらしいけど、locate
してもfind
しても見つからない。CentOSのリポジトリにあるMySQLからは取り除かれてるのかな?
もう一つ書いてあるmysql_secure_installation
は後述します。
サービス登録
$ sudo /sbin/chkconfig mysqld on $ /sbin/chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
メモリ
起動前のメモリ
$ free -m total used free shared buffers cached Mem: 1024 92 931 0 0 0 -/+ buffers/cache: 92 931 Swap: 0 0 0
$ ls /usr/share/mysql/my-* -1 /usr/share/mysql/my-huge.cnf /usr/share/mysql/my-innodb-heavy-4G.cnf /usr/share/mysql/my-large.cnf /usr/share/mysql/my-medium.cnf /usr/share/mysql/my-small.cnf
my-large.cnf
$ sudo cp /usr/share/mysql/my-large.cnf /etc/my.cnf $ sudo /etc/init.d/mysqld restart $ free -m total used free shared buffers cached Mem: 1024 486 537 0 0 0 -/+ buffers/cache: 486 537 Swap: 0 0 0
起動しただけでまったく稼動して無い状態で、400MB程消費。
my-medium.cnf
$ sudo cp /usr/share/mysql/my-medium.cnf /etc/my.cnf $ sudo /etc/init.d/mysqld restart $ free -m total used free shared buffers cached Mem: 1024 225 798 0 0 0 -/+ buffers/cache: 225 798 Swap: 0 0 0
こっちだと140MB位を消費する。
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): 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] n #rootのパスワードを設定。今回は実験環境だしポートも閉じてるのでスキップ ... 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? [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はroot@localhostのみ許可する ... 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 #初期に作成されるDATABASE 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! Cleaning up... All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!
匿名ユーザーの削除やtestデータベースの削除など、MySQLをインストールしたらやる作業を、対話型で進めるコマンドがありました。これは知らなかった。