티스토리 뷰

9. Mysql

1. [MySQL] 설치(CentOS)

미니대왕님 2020. 4. 15. 02:09

1. [MySQL] 설치(CentOS)

2. [MySQL] 기본 명령어 익히기

3. [MySQL] 외부에서 접근하는방법

4. [MySQL]워크벤치 설치하기

5. [MySQL]리플리케이션 방법

6. [MySQL]my.conf 환경 설정하기

7. [MySQL] MySQL 리플리케이션 UUID 관련 에러

8. [MySQL] mysql 데이터샘플 밀어 넣기  & 백업복구

9. [MySQL]Workbench & DA# 모델링 그리기

 

 

1. yum repository package 다운로드

wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm  명령어를 사용해서 패키지를 다운로드 받습니다.

 

2. Package 설치

yum localinstall mysql57-community-release-el7-11.noarch.rpm 명령어를 이용해서 다운로드 받은 패키지를 설치합니다.

 

3. MySQL yum repository 활성화

yum repolist enabled | grep "mysql.*-community.*" 명령어를 사용해 repository를 활성화 시키면 아래와 같은 화면을 확인할 수 있습니다.

 

 

그럼 본격적으로 MySQL의 설치를 진행합니다.

 

4. MySQL 설치

 

yum install mysql-community-server mysql mysql-libs mysql-devel mysql-server 명령어를 사용해 MySQL을 설치합니다.yum install mysql-community-server mysql mysql-libs mysql-devel mysql-server 명령어를 사용해 MySQL을 설치합니다.

 

5. MySQL 시작

systemctl start mysqld.service 명령어를 사용해 mysql을 시작합니다.

systemctl status mysqld.service 명령어를 사용해 현재 상태를 확인할 수 있습니다.

 

 

6. MySQL 부팅시 등록

자동 실행되도록 설정합니다.

systemctl enable mysqld.service 명령어를 사용해서 부팅시 mysql이 자동 실행되도록 설정합니다.

 

 

7. 패키지 설치시 root 패스워드가 임의로 설치되기 때문에 해당 임시 패스워드는

 /var/log/mysqld.log에 저장되어 있습니다.

 임시 패스워드를 확인합니다.

grep 'temporary password' /var/log/mysqld.log 명령어를 사용해서 임시 패스워드를 확인합니다.

 

 

위와 같이 본인의 패스워드를 확인할 수 있습니다.

 

8. Secure 환경설정

mysql_secure_installation 명령어를 사용해서 본인에게 맞는 Secure 환경 설정을 해줍니다. 아래와 같이 질문들이 나오면 아래를 참조해서 패스워드 변경 및 각종 여부를 물어보는 것을 진행하시면 됩니다.

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:  

 ... Failed! Error: Your password does not satisfy the current policy requirements 

 

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

 

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

 

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 

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 

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


출처: https://toma0912.tistory.com/64 [토마의 개발노트]

 

 

 

 

 

9. my.cnf 수정

 

vi /etc/my.cnf 명령어를 사용해서 수정을 하는데 아래의 내용 중에서 필요한 것들만 입력하거나 수정해주면 됩니다.

 

 

 

10. 포트 열어주기

 

firewall-cmd --zone=public --add-port=3306/tcp --permanentfirewall-cmd --reload

 

위의 두 명령어를 사용해서 포트를 열어줍니다.

 

11. 접속

mysql -u root -p 명령어를 사용해서 mysql에 접속을 시도하면, 각자가 설정한 패스워드를 입력하라는 입력란이 나오고 패스워드를 입력하면 다음과 같이 mysql에 접속한 화면을 확인할 수 있습니다.

 

 

 

12. 최초 패스워드 변경! & 외부 접속 허용

set password=password('패스워드') 

mysql> use mysql         >> mysql 디비 선택 

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '패스워드' WITH GRANT OPTION; 

mysql> GRANT TRIGGER ON *.* TO 'root'@'%' WITH GRANT OPTION; 

mysql> GRANT SUPER ON *.* TO 'root'@'%'; 

mysql> FLUSH PRIVILEGES; 

 

 

ALTER USER 'root'@'localhost' IDENTIFIED BY '패스워드';    // 로컬에서 접근 할 수 있게 등록
ALTER USER 'root'@'127.0.0.1' IDENTIFIED BY '패스워드';    // 127.0.0.1(로컬)로 접근 할 수 있게 등록
ALTER USER 'root'@'%' IDENTIFIED BY '패스워드';            // 어디서나 접근할 수 있게 등록
FLUSH PRIVILEGES;

 

위의 명령어를 사용해서 외부 접속을 허용할 수 있습니다.

 

13. MySQL 상태 보기

status 명령어를 사용해서 MySQL의 상태를 확인할 수 있습니다.

 

 

이것으로 CentOS에서 MySQL을 설치하는 방법에 대한 포스팅을 마치도록 하겠습니다. : )



기초 맛보기 

1. MySQL 정지

 

$ systemctl stop mysqld

2. MySQL 환경 옵션 설정

기존의 솔루션은 mysqld safe를 통해 재설정을 진행하는 것이다. 하지만 MySQL 5.7.6부터 RPM 배포판을 사용해서 설치하는 경우에는 systemd에서 관리를 하기 때문에 mysqld safe가 필요 없어 설치가 되지 않는다. 아래와 같은 환경 옵션을 설정 해준다.

$ systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

3. MySQL 시작

$ systemctl start mysqld

4. MySQL 로그인

루트의 비밀번호 없이 로그인 가능

 

$ mysql -u root -p

5. 루트 비밀번호 변경

5.7부터 비밀번호 컬럼이 password에서 authentication_string으로 변경됐다.

 


alter user 'root'@'localhost' identified by '1q2w3e4r%T';

mysql> UPDATE mysql.user SET authentication_string = PASSWORD('새로운 비밀번호') -> WHERE User = 'root' AND Host = 'localhost'; mysql> FLUSH PRIVILEGES; mysql> exit

6. MySQL 환경 옵션 설정 해제

다음 접속부터는 정상적으로 로그인할 수 있도록 환경 옵션 설정 해제를 한다.

 

$ systemctl unset-environment MYSQLD_OPTS

7. MySQL 시작

 

$ systemctl start mysqld

8. MySQL 로그인

 

$ mysql -u root -p

정상적으로 로그인이 되는 걸 확인할 수 있다. 그러나 로그인 해서 쿼리를 날려보니까 또 문제가 있다. 아래와 같은 메세지를 출력한다.

You must reset your password using ALTER USER statement before executing this statement.

비밀번호를 재설정하라고 한다. 위에서 재설정을 했는데 왜 그런걸까... 아직 이건 잘 모르겠다. 일단 재설정 해본다.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '비밀번호'; mysql> FLUSH PRIVILEGES;

재설정이 잘 되었다. 다시 한번 쿼리를 날려본다. 그랬더니 또 다음과 같은 메세지를 출력한다.

Your password does not satisfy the current policy requirements

이번에는 재설정한 비밀번호가 MySQL password validation에 맞지 않는다라는 메세지이다.

기존의 잘 사용하던 비밀번호를 바꾸기 싫어서 나는 password validation을 삭제했다. password validation을 지킬려면 비밀번호를 다시 변경하면 될거같다.

9. MySQL 로그인 후 password validation 삭제

 

$ mysql -u root -p mysql> uninstall plugin validate_password;

삭제하고 다시 해보니 잘 진행된다. 설치는 잘 된거 같고 마지막으로 사용자 추가와 외부 접근 허용 하는 것이 남았다. 루트는 로컬에서만 접속 가능하고 특정 사용자는 외부에서 접속 가능하도록 설정을 했다.

10. 사용자 추가

 

mysql> create user '사용자'@'localhost' identified by '비밀번호';

11. 권한 부여

모든 디비에 어디서든 접속할 수 있는 권한을 줬다. 사실 이러면 루트랑 다를 것도 없는데 최소한의 보안을 위해서 이렇게 진행했다.

 

mysql> grant all privileges on *.* to '사용자'@'%';

12. 외부 접속 허용

외부의 MySQL 워크벤치와 같은 툴에서 접속을 가능하게 하기 위해서 아래의 설정을 추가한다.

 

$ vi /etc/my.cnf bind-address 0.0.0.0 # 없으면 추가해준다.

 

13. 대소문자 변경방법 

show variables like 'lower_case_table_names';

my.conf 파일에

다음과 같은 명령을 실행하고 확인 하였을 경우

lower_case_table_names = 1 입력한다.

lower_case_table_names의 값이 0인지 1인지 2인지를 확인해야 한다.




 

MySQL 대소문자 구분 안하기 - lower_case_table_names 변경

MySQL로 간혹가다 작업 도중 분명히 테이블이 존재하는데  Table '테이블명' doesn't exist 라는 문구가 나올때가 존재한다. 윈도우에서는 대부분 대소문자 구분없이 설치가 되지만, 간혹가다가 리눅��

roqkffhwk.tistory.com

 

 

1. [MySQL] 설치(CentOS)

2. [MySQL] 기본 명령어 익히기

3. [MySQL] 외부에서 접근하는방법

4. [MySQL]워크벤치 설치하기

5. [MySQL]리플리케이션 방법

6. [MySQL]my.conf 환경 설정하기

7. [MySQL] MySQL 리플리케이션 UUID 관련 에러

8. [MySQL] mysql 데이터샘플 밀어 넣기

9. [MySQL]Workbench & DA# 모델링 그리기9. MySQL Workbench - 모델링 다이어그램(EER Diagram) 그리기

 

댓글