Software Workshop

MySQL 5.7과 8.0 이상에서는 기존의 DB 접근 ACL을 지정하는 방법에 큰 변화가 있었다.

우선 사용자를 생성해야 한다.

mysql -u root
mysql> create user testid@localhost;
mysql> use mysql
mysql> select * from user where User = 'testid';

testid라는 사용자가 어떤 호스트에서도 접근할 수 있도록 하려면 다음과 같이 생성하는 게 바람직하다. 위에서는 보안 상의 이유로 localhost에서만 접근 가능하도록 제한한 것이다.

mysql> create user testid;

패스워드는 다음과 같이 설정한다.

mysql> alter user 'testid'@'localhost' identified with mysql_native_password by 'testpassword';
mysql> flush privileges;

데이터베이스에 대한 접근권한은 다음과 같이 설정한다.

mysql> create database testdb;
mysql> grant all privileges on testdb.* to 'testid'@'localhost' with grant option;
mysql> flush privileges;

접근 가능한지 다음과 같이 테스트할 수 있다.

mysql -u testid -ptestpassword testdb