루트패스워드변경
mysql 서버에 패스워드 없이 로그인 하게되면 서버에 만들어진 데이터베이스나 테이블
기타 이곳에 저장된 자료가 외부인에게 노출될 수 있다. 따라서 이러한 보안을 목적으로
root 패스워드를 지정하면 mysql 서버를 안전하게 보호할 수 있다.
mysql> use mysql;
mysql> update user set password=password(‘패쓰워드’) where user=’root’;
Query OK, 2 rows affected (0.03 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> flush privileges; <— 적용
flush privileges; 를 하지 않으면 mysql에서 빠져나와서 root 로그인이 안된다.
확인한다.
mysql> select host, user, password from user;
+—————————————————————-+
| Host user password |
+—————————————————————-+
| localhost root 2e01146f5c065853 |
| localhost.localdomain root 2e01146f5c065853 |
+—————————————————————-+
#유저 추가.
INSERT INTO mysql.user (host,user,password) VALUES (‘%’,’root’,password(‘*2E71CAC033CBFF15613A02B9F655E72B4910D937’));
#개별 DB 에 테이블 에 맞게 계정 추가
mysql> insert into USERTABLE (id,passwd,priviledge,name,email) values (‘SUNGHO’,’c4ca4238a0b923820dcc509a6f75849b’,3,’HongSungho’,’hongsungho@email.com’);
# 5.x 버전에서부터추가된보안관련사항, ssl_cipher 관련입력값이없으면, 유저생성이안된다. 아래처럼해주길; 보안관련필드에빈값 ‘ ‘ 을넣어줌.
insert into user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject ) values(‘localhost’,’사용자명’,password(‘비밀번호’),”,”,”);
Grant all privileges on *.* to ‘USER’@’LOCALHOST or IP or %’ identified by ‘PASSWORD’ with grant option;
# 모든 권한 주귀..
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’;
# 모든 권한을 주는 바른 예
grant all privileges on *.* to ‘root’@’%’ identified by ‘암호’;
# HONG DB에읽기권한만을가진 sungho 라는 유저를생성하는바른예
Grant select on HONG.* to ‘sungho’@’%’ identified by ‘암호’;
# HONG DB에 readerhong 계정으로 10.0.0.10 주소를 갖는 서버만 접속 가능하고, 읽기 권한만 설정하는 예;
Grant select on HONG.* to ‘readerhong’@’10.0.0.10’ identified by ‘암호’;
# 이미 생성되어 있는 sungho 계정의 경우는 % 로 모든곳에서 접근이 가능하다.
# 보안을 위해서 로컬 호스트로만 접근이 가능하도록 설정을 변경하는 방법
update user set host=’localhost’ where host=% and user=’sungho’;
# 적용
FLUSH PRIVILEGES;