MacPortsからMySQLをインストールする


毎回、忘れてしまうため備忘録

## 1. MacPortsからインストールする
```bash
$ sudo port install mysql56-server
Portfile changed since last build; discarding previous state.
--->  Computing dependencies for mysql56-server
--->  Dependencies to be installed: mysql56
Portfile changed since last build; discarding previous state.
--->  Fetching archive for mysql56
--->  Attempting to fetch mysql56-5.6.19_1.darwin_13.x86_64.tbz2 from http://packages.macports.org/mysql56
--->  Attempting to fetch mysql56-5.6.19_1.darwin_13.x86_64.tbz2 from http://jog.id.packages.macports.org/macports/packages/mysql56
--->  Attempting to fetch mysql56-5.6.19_1.darwin_13.x86_64.tbz2 from http://mse.uk.packages.macports.org/sites/packages.macports.org/mysql56
--->  Fetching distfiles for mysql56
--->  Attempting to fetch mysql-5.6.19.tar.gz from http://mysql.ntu.edu.tw/Downloads/MySQL-5.6
--->  Attempting to fetch mysql-5.6.19.tar.gz from http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.6
--->  Verifying checksums for mysql56
--->  Extracting mysql56
--->  Applying patches to mysql56
--->  Configuring mysql56
--->  Building mysql56
--->  Staging mysql56 into destroot
--->  Installing mysql56 @5.6.19_1
The mysql56 client has been installed.
To install the mysql56 server, install the mysql56-server port.
--->  Activating mysql56 @5.6.19_1

On activation if no /opt/local/etc/mysql56/my.cnf file exists one
will be created which loads
/opt/local/etc/mysql56/macports-default.cnf.

If a /opt/local/etc/mysql56/my.cnf file exists MacPorts does not
touch it and any changes you make to /opt/local/etc/mysql56/my.cnf
will be preserved (e.g., during port upgrades, deactivations or
activations). /opt/local/etc/mysql56/my.cnf is a good place to
customize your mysql56 installation.

Any changes made to /opt/local/etc/mysql56/macports-default.cnf
will be lost during port upgrades, deactivations or activations so you
are advised to not make changes here. Currently
/opt/local/etc/mysql56/macports-default.cnf contains only one
directive; to disable networking. With disabled networking it is
possible to install and have running all the MacPorts mysql ports
simultaneously.

--->  Cleaning mysql56
--->  Fetching archive for mysql56-server
--->  Attempting to fetch mysql56-server-5.6.19_1.darwin_13.noarch.tbz2 from http://packages.macports.org/mysql56-server
--->  Attempting to fetch mysql56-server-5.6.19_1.darwin_13.noarch.tbz2.rmd160 from http://packages.macports.org/mysql56-server
--->  Installing mysql56-server @5.6.19_1
--->  Activating mysql56-server @5.6.19_1

If this is a new install you might want to run:

$ sudo /opt/local/lib/mysql56/bin/mysql_install_db --user _mysql

--->  Cleaning mysql56-server
--->  Updating database of binaries
--->  Scanning binaries for linking errors
--->  No broken files found.
```

## 2. 指定されたコマンドを実行
```bash
$ sudo /opt/local/lib/mysql56/bin/mysql_install_db --user _mysql
Password:
Installing MySQL system tables...2014-07-23 23:02:43 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-07-23 23:02:43 17650 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-07-23 23:02:43 17650 [Note] InnoDB: The InnoDB memory heap is disabled
2014-07-23 23:02:43 17650 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-07-23 23:02:43 17650 [Note] InnoDB: Compressed tables use zlib 1.2.8
2014-07-23 23:02:43 17650 [Note] InnoDB: Using CPU crc32 instructions
2014-07-23 23:02:43 17650 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-07-23 23:02:43 17650 [Note] InnoDB: Completed initialization of buffer pool
2014-07-23 23:02:43 17650 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2014-07-23 23:02:43 17650 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2014-07-23 23:02:43 17650 [Note] InnoDB: Database physically writes the file full: wait...
2014-07-23 23:02:44 17650 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2014-07-23 23:02:45 17650 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2014-07-23 23:02:46 17650 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2014-07-23 23:02:46 17650 [Warning] InnoDB: New log files created, LSN=45781
2014-07-23 23:02:46 17650 [Note] InnoDB: Doublewrite buffer not found: creating new
2014-07-23 23:02:46 17650 [Note] InnoDB: Doublewrite buffer created
2014-07-23 23:02:46 17650 [Note] InnoDB: 128 rollback segment(s) are active.
2014-07-23 23:02:46 17650 [Warning] InnoDB: Creating foreign key constraint system tables.
2014-07-23 23:02:46 17650 [Note] InnoDB: Foreign key constraint system tables created
2014-07-23 23:02:46 17650 [Note] InnoDB: Creating tablespace and datafile system tables.
2014-07-23 23:02:46 17650 [Note] InnoDB: Tablespace and datafile system tables created.
2014-07-23 23:02:46 17650 [Note] InnoDB: Waiting for purge to start
2014-07-23 23:02:46 17650 [Note] InnoDB: 5.6.19 started; log sequence number 0
2014-07-23 23:02:46 17650 [Note] RSA private key file not found: /opt/local/var/db/mysql56//private_key.pem. Some authentication plugins will not work.
2014-07-23 23:02:46 17650 [Note] RSA public key file not found: /opt/local/var/db/mysql56//public_key.pem. Some authentication plugins will not work.
2014-07-23 23:02:54 17650 [Note] Binlog end
2014-07-23 23:02:54 17650 [Note] InnoDB: FTS optimize thread exiting.
2014-07-23 23:02:54 17650 [Note] InnoDB: Starting shutdown...
2014-07-23 23:02:55 17650 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2014-07-23 23:02:55 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-07-23 23:02:55 17651 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-07-23 23:02:55 17651 [Note] InnoDB: The InnoDB memory heap is disabled
2014-07-23 23:02:55 17651 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-07-23 23:02:55 17651 [Note] InnoDB: Compressed tables use zlib 1.2.8
2014-07-23 23:02:55 17651 [Note] InnoDB: Using CPU crc32 instructions
2014-07-23 23:02:55 17651 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-07-23 23:02:55 17651 [Note] InnoDB: Completed initialization of buffer pool
2014-07-23 23:02:55 17651 [Note] InnoDB: Highest supported file format is Barracuda.
2014-07-23 23:02:55 17651 [Note] InnoDB: 128 rollback segment(s) are active.
2014-07-23 23:02:55 17651 [Note] InnoDB: Waiting for purge to start
2014-07-23 23:02:55 17651 [Note] InnoDB: 5.6.19 started; log sequence number 1625977
2014-07-23 23:02:55 17651 [Note] RSA private key file not found: /opt/local/var/db/mysql56//private_key.pem. Some authentication plugins will not work.
2014-07-23 23:02:55 17651 [Note] RSA public key file not found: /opt/local/var/db/mysql56//public_key.pem. Some authentication plugins will not work.
2014-07-23 23:02:55 17651 [Note] Binlog end
2014-07-23 23:02:55 17651 [Note] InnoDB: FTS optimize thread exiting.
2014-07-23 23:02:55 17651 [Note] InnoDB: Starting shutdown...
2014-07-23 23:02:56 17651 [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:

  /opt/local/lib/mysql56/bin/mysqladmin -u root password 'new-password'
  /opt/local/lib/mysql56/bin/mysqladmin -u root -h TOKUDOME-no-MacBook-Pro.local password 'new-password'

Alternatively you can run:

  /opt/local/lib/mysql56/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 /opt/local ; /opt/local/lib/mysql56/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

WARNING: Found existing config file /opt/local/etc/mysql56/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /opt/local/etc/mysql56/my-new.cnf,
please compare it with your file and take the changes you need.
```

## 3. start MySQL daemon
```bash
cd /opt/local ; sudo /opt/local/lib/mysql56/bin/mysqld_safe &
```

## 4. root ユーザのパスワードの変更
```bash
/opt/local/lib/mysql56/bin/mysqladmin -u root password 'xxxxxx'
```

## 5. my.cnf の編集
```bash
$sudo vim /opt/local/etc/mysql56/my.cnf

# 下の行をコメントアウト
#!/opt/local/etc/mysql56/macports-default.cnf

[mysqld]
port = 3306

[client]
port = 3306
```

## 6. データベースの作成
```bash
$ mysql -u root -p

mysql> show variables like 'character_set%';
+--------------------------+------------------------------------+
| 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       | /opt/local/share/mysql56/charsets/ |
+--------------------------+------------------------------------+
8 rows in set (0.00 sec)
mysql>create database xxxx;
```

## 7. ユーザ作成とか権限とか ...