FreeBSD MySQL5.6 インストール (FreeBSD 11.2)
FreeBSD11にMySQLをインストールします。
MySQLにはいくつかのバージョンがありますが、今回はMySQL5.6をインストールします。
MySQL5.6インストール
MySQLインストール
MySQL5.6をインストールします。
# pkg install mysql56-server |
MySQLを有効化させます。
以下を追記します。
# vi /etc/rc.conf mysql_enable="YES" |
MySQL起動
MySQLを起動します。
# /usr/local/etc/rc.d/mysql-server start または # service mysql-server start |
MySQLに接続
MySQLに接続します。
ユーザーをroot、パスワードはなしで接続します。
mysql> mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its Type 'help;’ or '\h’ for help. Type '\c’ to clear the current input statement. mysql> |
MySQLのバージョン5.6がインストールされているのを確認できます。(上記の黄色部分)
MySQlモードを終了するときは、「exit」を入力します。
MySQL初期設定
文字コードの設定をします。
# vi /usr/local/my.cnf |
下記を「my.cnf」の最後に追記します。
character-set-server=utf8 skip-character-set-client-handshak [client] default-character-set=utf8 |
MySQLを再起動します。
# /usr/local/etc/rc.d/mysql-server restart または # service mysql-server restart |
初期設定
文字コードを確認します。
MySQLに接続します。
mysql> mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its Type 'help;’ or '\h’ for help. Type '\c’ to clear the current input statement. mysql> |
文字コードが「utf-8」になっているかを確認します。
mysql> show variables like “chara%";
+————————–+———————————-+ |
rootのパスワードなどを設定します。
# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL In order to log into MySQL to secure it, we’ll need the current 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 You already have a root password set, so you can safely answer 'n’. Change the root password? [Y/n] y ←パスワードを変更するか?
By default, a MySQL installation has an anonymous user, allowing anyone Remove anonymous users? [Y/n] y ←匿名ユーザを削除するか? … Success! Normally, root should only be allowed to connect from 'localhost’. This Disallow root login remotely? [Y/n] y ←リモートからのrootログインを禁止するか? By default, MySQL comes with a database named 'test’ that anyone can Remove test database and access to it? [Y/n] y ←リモートからのrootログインを禁止するか? Reloading the privilege tables will ensure that all changes made so far Reload privilege tables now? [Y/n] y ←設定をリロードして反映するか? … Success!
All done! If you’ve completed all of the above steps, your MySQL Thanks for using MySQL! Cleaning up… |
ログインできるか確認します。
# mysql -u root -p Enter password: Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its Type 'help;’ or '\h’ for help. Type '\c’ to clear the current input statement. mysql> |
ユーザー作成
ユーザーを作成します。
mysql> create user ユーザー名@localhost identified by 'パスワード’; |
ユーザー確認をします。
mysql> select user,host from mysql.user; |
パスワード変更
rootのパスワードを変更します。(一般ユーザーのときはroot部分を一般ユーザー名にします。)
mysql> set password for root@localhost=password('パスワード’); |
以上で、FreeBSD11のMySQL5.6のインストールは完了です。