YUMSERV
반응형

테스트 한 서버는 CentOS 7.5 Mysql 5.7에서 진행하였습니다.

 

1) root 패스워드 변경

 

Mysql 5.6버전이하에서 패스워드 변경


mysql> use mysql;
Database changed
mysql> update user set password=password(‘바꿀패스워드) where user=’root’;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


Mysql 5.7버전부터 패스워드 설정하는 부분이 변경되었습니다.


mysql> use mysql;
Database changed
mysql> update user set authentication_string=password(‘바꿀패스워드) where user=’root’;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

2) 사용자 확인하기

 

mysql> use mysql;
Database changed
mysql> select host,user,authentication_string from user;
+———–+———–+——————————————-+
| host | user | authentication_string |
+———–+———–+——————————————-+
| localhost | root | *12452E29B4CAB0780697ADC8DE277A129328B150 |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+———–+———–+——————————————-+
3 rows in set (0.00 sec)

 

3) 사용자 계정 생성

 

localhost : 내부 접근 % : 외부접근

test1 계정을 내부에서만 접근하도록 계정을 생성할 때

mysql> create user ‘test1’@’localhost’ identified by ‘패스워드’;
Query OK, 0 rows affected (0.01 sec)


test2 계정을 외부에서만 접근하도록 계정을 생성할 때

mysql> create user ‘test2’@’%’ identified by ‘패스워드’;
Query OK, 0 rows affected (0.00 sec)


만든 사용자 계정 확인

mysql> select host,user,authentication_string from user;
+———–+———–+——————————————-+
| host | user | authentication_string |
+———–+———–+——————————————-+
| localhost | root | *12452E29B4CAB0780697ADC8DE277A129328B150 |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
localhost | test1 | *AE00F4BAF5DDEFD9C47B00DBA92FB87EBBC890CF |
% | test2 | *AE00F4BAF5DDEFD9C47B00DBA92FB87EBBC890CF |
+———–+———–+——————————————-+
5 rows in set (0.00 sec)

 

4) 사용자 접근 권한 설정

 

test1계정에 대해 192.168.0.100에 해당하는 IP만 접근 가능하도록 설정할 때

mysql> grant all privileges on *.* to ‘test1’@’192.168.0.100’;
Query OK, 0 rows affected, 1 warning (0.00 sec)

test2계정에 대해 192.168. 대역에 모두 접근이 가능하도록 설정할 때

mysql> grant all privileges on *.* to ‘test2’@’192.168.%’;
Query OK, 0 rows affected, 1 warning (0.00 sec)

test3계정에 대해 외부 어느곳이든 접근이 가능하도록 설정할 때

mysql> grant all privileges on *.* to ‘test3’@’%’;
Query OK, 0 rows affected, 1 warning (0.00 sec)

 

5) 데이터베이스, 테이블 접근 권한 설정

 

test1에 대한 mytest 데이터 베이스에 select, insert, update 권한을 부여할 때

mysql> grant select, insert, update on mytest.* to test1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

test2에 대한 mytest 데이터 베이스에 모든 권한을 부여할 때

mysql> grant all privileges on mytest.* to test2;
Query OK, 0 rows affected (0.00 sec)

test3에 대한 모든 데이터베이스와, 모든 테이블 권한을 부여할 때

mysql> grant all privileges on *.* to test3 with grant option;
Query OK, 0 rows affected (0.00 sec)

 

6) 권한 확인

 

mysql> show grants for ‘test1’@’localhost’;
+——————————————-+
| Grants for test1@localhost |
+——————————————-+
| GRANT USAGE ON *.* TO ‘test1’@’localhost’ |
+——————————————-+
1 row in set (0.00 sec)

 

7) 권한 삭제

 

mysql> revoke all on *.* from test1@localhost;
Query OK, 0 rows affected (0.00 sec)

 

8) 사용자 삭제

 

mysql> drop user ‘test1’@’%’;
Query OK, 0 rows affected (0.02 sec)

반응형

'LINUX > DB' 카테고리의 다른 글

MYSQL 복구 설정  (0) 2019.05.27
Mariadb 10.1 소스설치  (0) 2019.05.27
Mysql 8.0 소스설치  (0) 2019.05.27
Mysql 5.7 소스설치  (0) 2019.05.27
Mysql 5.6 소스설치  (0) 2019.05.27
profile

YUMSERV

@lena04301

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!