Ubuntu18.04にwordpressをインストール(Apache2,PHP7.2)
MySQL5.7のインストール
以下のコマンドでインストール
$ sudo apt install mysql-server mysql-client
以下のコマンドでサービスの起動確認
$ sudo service mysql status
mysql_secure_installation コマンドを実行し、管理者(root)パスワードなどインストール後の初期設定を行う。基本的には「y」で進める。
$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: Y ★<-[Y]と入力
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 ★<-パスワードのチェックレベル
Please set the password for root here.
New password: ★<-rootパスワード
Re-enter new password: ★<-rootパスワード再入力
Estimated strength of the password: 25
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y ★<-[Y]と入力
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? (Press y|Y for Yes, any other key for No) : Y ★<-[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? (Press y|Y for Yes, any other key for No) : Y ★<-[Y]と入力
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? (Press y|Y for Yes, any other key for No) : Y ★<-[Y]と入力
- 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? (Press y|Y for Yes, any other key for No) : Y ★<-[Y]と入力
Success.
All done!
MySQLサーバへログインしてみる
$ sudo mysql -u root -p
ステータスを確認する
mysql> status
ん(;'∀')!。サーバーの文字コードが「latin1」になっている!!
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
文字コードをUTF-8に変更する。
$ sudo cp -p /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf.20200605
$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
★[mysqld]セクションに下記行を追加する。ついでにパスワード有効期限も無効にしておく。(有効のままだと360日後にパスワードの変更を促されてログインできなくなる)
character-set-server = utf8
default_password_lifetime = 0
ついでに、その他ツールの文字コードもUTF-8にしておく。
$ sudo cp -p /etc/mysql/conf.d/mysqldump.cnf /etc/mysql/conf.d/mysqldump.cnf.20200605
$ sudo vi /etc/mysql/conf.d/mysqldump.cnf
★末尾に「default-character-set=utf8」の行を追加
$ sudo cp -p /etc/mysql/conf.d/mysql.cnf /etc/mysql/conf.d/mysql.cnf.20200605
$ sudo vi /etc/mysql/conf.d/mysql.cnf
★末尾に「default-character-set=utf8」の行を追加
MySQLサービスを再起動する。
$ sudo service mysql restart
MySQLサーバへログインし文字コードを確認してみる。
mysql> show global variables like '%character%';
+--------------------------+----------------------------+
| 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/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
無事、変更されました。