MySQL 8 최초 설치 후 ALTER USER

MySQL 8을 최초 설치 후 Database에 접속하려고 한다.
암호는 rpm 설치시에는 /var/log/mysqld.log 파일에 아래와 같이 출력된다.

2020-02-18T02:09:43.292948Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19)  MySQL Community Server - GPL.
2020-02-18T02:10:28.573643Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 25770
2020-02-18T02:10:32.337916Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: wGKhAHrPg1?_

위와같이 wGKhAHrPg1?_ 라는 암호로 초기화 된것을 확인할 수 있다.

일단 MySQL Database에 접속을 해보자

[root@test7 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.19

Copyright (c) 2000, 2020, 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> use myql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

위와같이 처음 접속 후 무언가 작업을 하려고 하면 일단 암호를 변경하라고 나온다. 최초 설치 후 설정된 기본 암호는 로그상에 노출되어있기 때문에 다른 암호로 변경한 이후에만 사용이 가능하다.

mysql> alter user 'root'@'localhost' identified by 'MySQL2020!';
Query OK, 0 rows affected (0.00 sec)

설정할 암호는 복잡성을 만족해야 한다. MySQL 8은 암호 복잡성 설정이 기본적으로 적용되어있다. 복잡성 설정에 대한 부분은 MySQL 8 암호 복잡성 설정 를 참조하면 된다.
하지만 반드시 최초 1회는 무조건 일단 암호를 변경해야 root 계정을 사용할 수 있다는것을 참고하도록 한다.

암호를 예전의 방식으로 로그인 하려면 아래처럼 사용한다.

mysql> alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysql2020!';
Query OK, 0 rows affected (0.00 sec)

보통 처음 접속하는 root계정은 localhost에서만 접속할 수 있도록 설정되어있다.
아무곳에서나 원격으로 접속할 수 있도록 하려면 host 설정이 %로 되어있는 계정을 추가하면 된다.

mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'P@ssW0rd';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
mysql> commit;
mysql> flush privileges;
로그인하면 댓글을 남길 수 있습니다.
  • mysql_8_최초_설치_후_alter_user.txt
  • 마지막으로 수정됨: 2020/02/18 04:24
  • 저자 koov