Linux

mysql 5.7 이상 설치시 root 암호

Naan 2019. 4. 16. 11:24
320x100

[root@localhost ~]# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@localhost ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
Note: Forwarding request to 'systemctl enable mysqld.service'.
r[root@localhost ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

음..?

설치 하고 root 로그인 하려 하는데 암호가 틀리다고 한다.

난 설치만 했을뿐인데... 암호라니??

5.7 버전 이상부터 암호가 자동 생성이 된다.

로그 파일을 확인해보면

# vi /var/log/mysqld.log

2019-04-16T11:16:48.482472Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-16T11:16:51.488944Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-16T11:16:51.966504Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-16T11:16:52.052390Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 228c27ae-6039-11e9-9813-bc5ff4165f2e.
2019-04-16T11:16:52.053897Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-16T11:16:52.054786Z 1 [Note] A temporary password is generated for root@localhost: Wc/9%o)wjMS+
2019-04-16T11:16:56.114820Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-16T11:16:56.115869Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.25) starting as process 32396 ...
2019-04-16T11:16:56.118708Z 0 [Note] InnoDB: PUNCH HOLE support available
2019-04-16T11:16:56.118731Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-04-16T11:16:56.118738Z 0 [Note] InnoDB: Uses event mutexes
2019-04-16T11:16:56.118742Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2019-04-16T11:16:56.118746Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-04-16T11:16:56.118750Z 0 [Note] InnoDB: Using Linux native AIO
2019-04-16T11:16:56.118941Z 0 [Note] InnoDB: Number of pools: 1
2019-04-16T11:16:56.119013Z 0 [Note] InnoDB: Using CPU crc32 instructions
2019-04-16T11:16:56.120195Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-04-16T11:16:56.126435Z 0 [Note] InnoDB: Completed initialization of buffer pool
2019-04-16T11:16:56.127952Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-04-16T11:16:56.139316Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2019-04-16T11:16:56.146002Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-04-16T11:16:56.146105Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-04-16T11:16:56.474017Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-04-16T11:16:56.475683Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2019-04-16T11:16:56.475710Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2019-04-16T11:16:56.476362Z 0 [Note] InnoDB: Waiting for purge to start
2019-04-16T11:16:56.526513Z 0 [Note] InnoDB: 5.7.25 started; log sequence number 2524303
2019-04-16T11:16:56.526994Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-04-16T11:16:56.527249Z 0 [Note] Plugin 'FEDERATED' is disabled.
2019-04-16T11:16:56.528438Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190416 20:16:56
2019-04-16T11:16:56.532555Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2019-04-16T11:16:56.532888Z 0 [Warning] CA certificate ca.pem is self signed.
2019-04-16T11:16:56.536052Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2019-04-16T11:16:56.536183Z 0 [Note] IPv6 is available.
2019-04-16T11:16:56.536200Z 0 [Note] - '::' resolves to '::';
2019-04-16T11:16:56.536231Z 0 [Note] Server socket created on IP: '::'.
2019-04-16T11:16:56.549700Z 0 [Note] Event Scheduler: Loaded 0 events
2019-04-16T11:16:56.550013Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.7.25' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)

빨간 글씨가 초기 암호다.

바로 찾고 싶으면
grep 'temporary password' /var/log/mysqld.log

암호를 변경하고 싶으면

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Wc/9%o)wjMS+';
Query OK, 0 rows affected (0.00 sec)

을 먼저 해주자 안하면

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

에러가 반겨 줄것이다.

mysql> use mysql;

alter user 'root'@'localhost' identified by '12345qwert!@';

commit;

암호화 정책이 강화 됐다.

mysql> SHOW VARIABLES LIKE 'validate_password%'
-> ;
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+

위에 보는것 처럼 정책에 맞춰서 입력을 해주자 당연히 설정값은 변경도 가능하다.

mysql> flush privileges;

하면 된다.

320x100

'Linux' 카테고리의 다른 글

jetbrains Upsource install  (0) 2019.05.02
svn: E175002 error  (0) 2019.04.17
review board install  (0) 2019.04.15
rhodecode install  (0) 2019.04.02
yona install  (0) 2019.03.28