Google Cloud PlatformでたてたCentOS7上のMySQL5.7の初期セットアップを行う方法のご紹介です。
Google Cloud Platform以外の場合でもCentOS7上のMySQL5.7では共通です。
まずは、mysqldを起動します。
1 |
[root@gogs gogs]# systemctl start mysqld |
次に自動起動を有効にします。
1 |
[root@gogs gogs]# systemctl enable mysqld |
次にDBへ接続するためのrootの初期パスワードを確認します。
1 2 3 |
[root@gogs gogs]# grep 'temporary password' /var/log/mysqld.log 2019-03-03T12:59:48.344314Z 1 [Note] A temporary password is generated for root@localhost: So#,fiYz_7Bt [root@gogs gogs]# |
この場合、「root@localhost:」の後ろの「So#,fiYz_7Bt」がパスワードです。
続いて、「mysql_secure_installation」を実行しましょう。
最初にパスワードを聞かれるので、先ほど調べたパスワードを入力します。
その後パスワードを変更します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
[root@gogs gogs]# mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: The 'validate_password' plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : No ... 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? (Press y|Y for Yes, any other key for No) : 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) : No ... skipping. 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 - 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 Success. All done! [root@gogs gogs]# |
初期セットアップは以上で完了です。
試しにつないでみましょう。パスワードは変更後のパスワードを入力しましょう。
1 2 3 4 5 6 7 8 9 10 11 |
[root@gogs gogs]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.7.25 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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> |