2년전, 학생때 이런 정보를 제대로 포스팅 해줬던 분들이 없었던 것 같아서 고생을 많이 했었던적이 몇 번 있었는데,

지금은 2년전 나와 같은 분들을 위하여 이 글을 작성합니다.

 

본 글은 Google Cloud Platform의 Compute Engine, Centos7 환경에서 세팅한 글입니다.

 

편의상 VM을 만들고, 접속하는 단계까지는 사람마다 방법이 모두 다를 수 있으니,

SSH를 통하여 서버에 접속한 것 부터 진행하겠습니다.

 

먼저 로컬에 mysql 5.7버전을 다운로드 합시다.

$ sudo yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

localinstall은 처음 보는사람들이 있을 것 같아서 제가 알고있는대로 말씀 드리자면,

터미널의 working directory를 찾아서 여기에 다운로드 의존성 있는 애들을 다운로드하고, 설치까지 해줍니다.

여기에서 말하는 다운로드 의존성이 있는건, mysql 5.7버전과 관련된거겠죠.

여기까지 치면 아래처럼 실행될겁니다.

뭐 물어보면 다 그냥 y 누르시면 됩니다.

$ sudo yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
Loaded plugins: fastestmirror
mysql57-community-release-el7-11.noarch.rpm                                                                                                   |  25 kB  00:00:00     
Examining /var/tmp/yum-root-bArCKx/mysql57-community-release-el7-11.noarch.rpm: mysql57-community-release-el7-11.noarch
Marking /var/tmp/yum-root-bArCKx/mysql57-community-release-el7-11.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================================
 Package                                      Arch                      Version                    Repository                                                   Size
=====================================================================================================================================================================
Installing:
 mysql57-community-release                    noarch                    el7-11                     /mysql57-community-release-el7-11.noarch                     31 k

Transaction Summary
=====================================================================================================================================================================
Install  1 Package

Total size: 31 k
Installed size: 31 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql57-community-release-el7-11.noarch                                                                                                           1/1 
  Verifying  : mysql57-community-release-el7-11.noarch                                                                                                           1/1 

Installed:
  mysql57-community-release.noarch 0:el7-11                                                                                                                          

Complete!

그 다음 로컬에 설치한 mysql을 아래의 키워드로 정식으로 설치해 주면 됩니다.

$ sudo yum install mysql-community-server

 

정상적으로 설치가 완료되면 다음처럼 노출될겁니다.

$ sudo yum install mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: repos-va.psychz.net
 * epel: d2lzkl7pfhq30w.cloudfront.net
 * extras: mirror.team-cymru.com
 * updates: repos-va.psychz.net
ㅛ
mysql-tools-community                                                                                                                         | 2.5 kB  00:00:00     
mysql57-community                                                                                                                             | 2.5 kB  00:00:00     
(1/3): mysql-connectors-community/x86_64/primary_db                                                                                           |  41 kB  00:00:00     
(2/3): mysql57-community/x86_64/primary_db                                                                                                    | 177 kB  00:00:00     
(3/3): mysql-tools-community/x86_64/primary_db                                                                                                |  58 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.26-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.26-1.el7 for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.2)(64bit) for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.1)(64bit) for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Processing Dependency: libnuma.so.1()(64bit) for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Processing Dependency: libaio.so.1()(64bit) for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
---> Package mysql-community-client.x86_64 0:5.7.26-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.26-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.26-1.el7 will be installed
---> Package numactl-libs.x86_64 0:2.0.9-7.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.26-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.26-1.el7 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================================
 Package                                           Arch                         Version                                Repository                               Size
=====================================================================================================================================================================
Installing:
 mysql-community-libs                              x86_64                       5.7.26-1.el7                           mysql57-community                       2.2 M
     replacing  mariadb-libs.x86_64 1:5.5.60-1.el7_5
 mysql-community-libs-compat                       x86_64                       5.7.26-1.el7                           mysql57-community                       2.0 M
     replacing  mariadb-libs.x86_64 1:5.5.60-1.el7_5
 mysql-community-server                            x86_64                       5.7.26-1.el7                           mysql57-community                       166 M
Installing for dependencies:
 libaio                                            x86_64                       0.3.109-13.el7                         base                                     24 k
 mysql-community-client                            x86_64                       5.7.26-1.el7                           mysql57-community                        24 M
 mysql-community-common                            x86_64                       5.7.26-1.el7                           mysql57-community                       274 k
 numactl-libs                                      x86_64                       2.0.9-7.el7                            base                                     29 k

Transaction Summary
=====================================================================================================================================================================
Install  3 Packages (+4 Dependent packages)

Total download size: 194 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.26-1.el7.x86_64.rpm is not installed
(1/7): mysql-community-common-5.7.26-1.el7.x86_64.rpm                                                                                         | 274 kB  00:00:00     
(2/7): mysql-community-libs-5.7.26-1.el7.x86_64.rpm                                                                                           | 2.2 MB  00:00:00     
(3/7): mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm                                                                                    | 2.0 MB  00:00:00     
(4/7): mysql-community-client-5.7.26-1.el7.x86_64.rpm                                                                                         |  24 MB  00:00:00     
(5/7): libaio-0.3.109-13.el7.x86_64.rpm                                                                                                       |  24 kB  00:00:00     
(6/7): numactl-libs-2.0.9-7.el7.x86_64.rpm                                                                                                    |  29 kB  00:00:01     
(7/7): mysql-community-server-5.7.26-1.el7.x86_64.rpm                                                                                         | 166 MB  00:00:05     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                 34 MB/s | 194 MB  00:00:05     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-11.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]:y   
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-5.7.26-1.el7.x86_64                                                                                                        1/8 
  Installing : mysql-community-libs-5.7.26-1.el7.x86_64                                                                                                          2/8 
  Installing : mysql-community-client-5.7.26-1.el7.x86_64                                                                                                        3/8 
  Installing : libaio-0.3.109-13.el7.x86_64                                                                                                                      4/8 
  Installing : numactl-libs-2.0.9-7.el7.x86_64                                                                                                                   5/8 
  Installing : mysql-community-server-5.7.26-1.el7.x86_64                                                                                                        6/8 
  Installing : mysql-community-libs-compat-5.7.26-1.el7.x86_64                                                                                                   7/8 
  Erasing    : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                                                              8/8 
  Verifying  : mysql-community-server-5.7.26-1.el7.x86_64                                                                                                        1/8 
  Verifying  : numactl-libs-2.0.9-7.el7.x86_64                                                                                                                   2/8 
  Verifying  : mysql-community-client-5.7.26-1.el7.x86_64                                                                                                        3/8 
  Verifying  : mysql-community-libs-5.7.26-1.el7.x86_64                                                                                                          4/8 
  Verifying  : mysql-community-common-5.7.26-1.el7.x86_64                                                                                                        5/8 
  Verifying  : mysql-community-libs-compat-5.7.26-1.el7.x86_64                                                                                                   6/8 
  Verifying  : libaio-0.3.109-13.el7.x86_64                                                                                                                      7/8 
  Verifying  : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                                                              8/8 

Installed:
  mysql-community-libs.x86_64 0:5.7.26-1.el7         mysql-community-libs-compat.x86_64 0:5.7.26-1.el7         mysql-community-server.x86_64 0:5.7.26-1.el7        

Dependency Installed:
  libaio.x86_64 0:0.3.109-13.el7   mysql-community-client.x86_64 0:5.7.26-1.el7   mysql-community-common.x86_64 0:5.7.26-1.el7   numactl-libs.x86_64 0:2.0.9-7.el7  

Replaced:
  mariadb-libs.x86_64 1:5.5.60-1.el7_5                                                                                                                               

Complete!

 

여기까지 진행 되셨으면,

mysql을 시작해 주면서, 서버가 부팅/재부팅 될 때 자동으로 실행될 수 있도록 다음 키워드를 입력해 줍시다.

$ sudo systemctl enable mysqld
$ sudo systemctl start mysqld

 

다음 키워드로 mysql가 정상적으로 실행 되었는지 확인해볼 수 있어요.

$ sudo systemctl status mysqld

● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-07-10 16:39:32 UTC; 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 5835 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 5758 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 5838 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─5838 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Jul 10 16:39:22 instance-2 systemd[1]: Starting MySQL Server...
Jul 10 16:39:32 instance-2 systemd[1]: Started MySQL Server.

 

보통 mysql을 설치하면, default password를 몰라서 재설치 했던적이 엄청 많은데요.

다음 키워드를 입력하면 Mysql 을 설치하면서 자동으로 세팅되었던 비밀번호를 알 수 있어요.

$ sudo grep 'A temporary password' /var/log/mysqld.log

2019-07-10T16:39:28.194886Z 1 [Note] A temporary password is generated for root@localhost: %11/dxwc_OG2

 

mysql에서 알려준 password는 %11/dxwc_OG2였네요.

요걸로 로그인하면 아래처럼 정상적으로 로그인할 수 있습니다.

$ sudo mysql -u root -p

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26

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> 

 

그런데 요 상태에서 뭔갈 해보려고 하니까, 아래처럼 패스워드를 바꾸라고 하네요.

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

 

그럼 다음 키워드를 입력하여 mysql를 나와주시고,

mysql> exit
Bye

 

다음 키워드를 입력해서 비밀번호를 바꿔줍시다.

$ sudo mysql_secure_installation

처음 입력하라는 비밀번호는, Mysql에서 처음 발급해줬던 임시 비밀번호입니다.

저는 다음과 같이 입력했어요.

 

$ sudo 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) : y

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : 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
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) : n

 ... 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) : n

 ... skipping.
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! 

$ 

-> yyynny

nn했던것들

1. 원격에서 DB 접근 막을거냐 ? => 로컬장비에서 서버로 붙어서 쓸거라 n

2. test database가 있는데 이거 지울거야 ? => 테스트할 때 필요할 수도 있을 것 같아서 n

 

이렇게하면, 세팅은 끝납니다.

 

최종적으로 다음처럼 실행되면 됩니다.

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.26 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.06 sec)

mysql> 

 

 

어라? test database가 사라졌네 ?

왜지 ? ㅎㅎㅎ

 

 

언제 쓸지는 모르겠지만, 다음 글에서는 golang에서 DB연결하는걸...써볼까요 

추천받습니다.

 

 

참고 : 

구글링 하면서 나온 수 많은 사이트들.

'Database > MySQL' 카테고리의 다른 글

MySQL에서 Grant 권한  (0) 2016.04.22

+ Recent posts