FreeBSD 10.1RにMySQL 5.6をインストール

  • FreeBSD 10.1-RELEASE
  • MySQL 5.6.22
2018-10-19追記:mysql55からWITH_CHARSET, WITH_XCHARSETオプションは廃止となっている。指定しても問題はないが意味もない。

UTF-8を使いたいのでMySQLのインストール時にコンパイルオプションを付ける必要があるが、更新時などに忘れがちなので/etc/make.confで指定しておく。

.if ${.CURDIR:M*/databases/mysql*}
WITH_CHARSET=utf8
WITH_XCHARSET=all
.endif

サーバを入れれば自動でクライアントも入る。

portmaster databases/mysql56-server

5.5の時のように/etc/local/share/mysql/my-medium.cnfをコピーしようと思ったらmy-default.cnfというファイルしか無いばかりか、中身がどう見ても空っぽ。

公式サイトによれば、5.6.8から従来のcnfファイルの提供は中止され、mysql_install_dbコマンドで生成するようになったらしい。てなわけで実行してみる。

$ sudo mysql_install_db --user=mysql --basedir=/usr/local --datadir=/usr/home/mysql/data
Installing MySQL system tables...2014-12-31 23:47:49 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-12-31 23:47:49 67043 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-12-31 23:47:49 67043 [Note] InnoDB: The InnoDB memory heap is disabled
2014-12-31 23:47:49 67043 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-12-31 23:47:49 67043 [Note] InnoDB: Memory barrier is not used
2014-12-31 23:47:49 67043 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-12-31 23:47:49 67043 [Note] InnoDB: Using CPU crc32 instructions
2014-12-31 23:47:49 67043 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-12-31 23:47:49 67043 [Note] InnoDB: Completed initialization of buffer pool
2014-12-31 23:47:49 67043 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2014-12-31 23:47:49 67043 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2014-12-31 23:47:49 67043 [Note] InnoDB: Database physically writes the file full: wait...
2014-12-31 23:47:49 67043 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2014-12-31 23:47:50 67043 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2014-12-31 23:47:50 67043 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2014-12-31 23:47:50 67043 [Warning] InnoDB: New log files created, LSN=45781
2014-12-31 23:47:50 67043 [Note] InnoDB: Doublewrite buffer not found: creating new
2014-12-31 23:47:50 67043 [Note] InnoDB: Doublewrite buffer created
2014-12-31 23:47:50 67043 [Note] InnoDB: 128 rollback segment(s) are active.
2014-12-31 23:47:50 67043 [Warning] InnoDB: Creating foreign key constraint system tables.
2014-12-31 23:47:50 67043 [Note] InnoDB: Foreign key constraint system tables created
2014-12-31 23:47:50 67043 [Note] InnoDB: Creating tablespace and datafile system tables.
2014-12-31 23:47:50 67043 [Note] InnoDB: Tablespace and datafile system tables created.
2014-12-31 23:47:50 67043 [Note] InnoDB: Waiting for purge to start
2014-12-31 23:47:50 67043 [Note] InnoDB: 5.6.22 started; log sequence number 0
2014-12-31 23:47:52 67043 [Note] Binlog end
2014-12-31 23:47:52 67043 [Note] InnoDB: FTS optimize thread exiting.
2014-12-31 23:47:52 67043 [Note] InnoDB: Starting shutdown...
2014-12-31 23:47:53 67043 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
 
Filling help tables...2014-12-31 23:47:53 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-12-31 23:47:53 67044 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-12-31 23:47:53 67044 [Note] InnoDB: The InnoDB memory heap is disabled
2014-12-31 23:47:53 67044 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-12-31 23:47:53 67044 [Note] InnoDB: Memory barrier is not used
2014-12-31 23:47:53 67044 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-12-31 23:47:53 67044 [Note] InnoDB: Using CPU crc32 instructions
2014-12-31 23:47:53 67044 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-12-31 23:47:53 67044 [Note] InnoDB: Completed initialization of buffer pool
2014-12-31 23:47:53 67044 [Note] InnoDB: Highest supported file format is Barracuda.
2014-12-31 23:47:53 67044 [Note] InnoDB: 128 rollback segment(s) are active.
2014-12-31 23:47:53 67044 [Note] InnoDB: Waiting for purge to start
2014-12-31 23:47:53 67044 [Note] InnoDB: 5.6.22 started; log sequence number 1625977
2014-12-31 23:47:53 67044 [Note] Binlog end
2014-12-31 23:47:53 67044 [Note] InnoDB: FTS optimize thread exiting.
2014-12-31 23:47:53 67044 [Note] InnoDB: Starting shutdown...
2014-12-31 23:47:55 67044 [Note] InnoDB: Shutdown completed; log sequence number 1625987
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/local/bin/mysqladmin -u root password 'new-password'
  /usr/local/bin/mysqladmin -u root -h MY.HOSTNAME password 'new-password'
 
Alternatively you can run:
 
  /usr/local/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/local/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 at http://bugs.mysql.com/
 
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
 
New default config file was created as /usr/local/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

/usr/local/my.cnfに出来るようだ。

/etc/rc.confに追加。データ置き場も変更しているので、mysql_dbdirも設定する。

mysql_enable="YES"
mysql_dbdir="/usr/home/mysql/data/"

そして起動。

$ sudo /usr/local/etc/rc.d/mysql-server start

mysql_secure_installationで初期設定を行う。

基本的には言われるがままでおk。

$ sudo 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:
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]
 ... 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]
 - 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]
 ... 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...

/usr/local/my.cnfcharacter-set-serverを設定し、MySQLサーバを再起動する。

[mysqld]
character-set-server = utf8

試しに繋いでみる。

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.6.24 Source distribution
 
Copyright (c) 2000, 2015, 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.00 sec)
 
mysql> show variables like 'char%';
+--------------------------+----------------------------------+
| Variable_name            | Value                            |
+--------------------------+----------------------------------+
| character_set_client     | utf8                             |
| character_set_connection | utf8                             |
| character_set_database   | utf8                             |
| character_set_filesystem | binary                           |
| character_set_results    | utf8                             |
| character_set_server     | utf8                             |
| character_set_system     | utf8                             |
| character_sets_dir       | /usr/local/share/mysql/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.00 sec)
 
mysql> show variables like '%dir';
+---------------------------+----------------------------------+
| Variable_name             | Value                            |
+---------------------------+----------------------------------+
| basedir                   | /usr/local                       |
| character_sets_dir        | /usr/local/share/mysql/charsets/ |
| datadir                   | /usr/home/mysql/data/            |
| innodb_data_home_dir      |                                  |
| innodb_log_group_home_dir | ./                               |
| lc_messages_dir           | /usr/local/share/mysql/          |
| plugin_dir                | /usr/local/lib/mysql/plugin/     |
| slave_load_tmpdir         | /tmp/                            |
| tmpdir                    | /tmp/                            |
+---------------------------+----------------------------------+
9 rows in set (0.00 sec)
 
mysql> quit
Bye
  • freebsd/freebsd_10.1r_install_mysql_5.6.txt
  • 最終更新: 2021-02-01 09:53
  • by Decomo