본문 바로가기

리눅스

[리눅스] mysql root 패스워드 변경

728x90

MySQL root 패스워드 변경

테스트 환경

$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.9.2009 (Core)
Release:        7.9.2009
Codename:       Core
$ mysqld -V
/usr/sbin/mysqld  Ver 8.0.31 for Linux on x86_64 (MySQL Community Server - GPL)

mysqld(mysql server)에 접속

mysql -u root -p mysql
$ mysql -u root -p mysql
Enter password: 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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>
SELECT Host,User,authentication_string FROM user;

mysql user 생성

CREATE USER 'tuser'@'localhost' IDENTIFIED BY 'P@ssw0rd1!';
mysql> CREATE USER 'tuser'@'localhost' IDENTIFIED BY 'P@ssw0rd1!';
Query OK, 0 rows affected (0.05 sec)

DB 권한 부여

GRANT ALL PRIVILEGES ON *.* to 'tuser'@'localhost';
mysql> GRANT ALL PRIVILEGES ON *.* to 'tuser'@'localhost';
Query OK, 0 rows affected (0.07 sec)
FLUSH PRIVILEGES;

mysql 패스워드 변경

ALTER USER 'tuser'@'localhost' IDENTIFIED BY 'Ahslxjfld1!';
mysql> ALTER USER 'tuser'@'localhost' IDENTIFIED BY 'Ahslxjfld1!';
Query OK, 0 rows affected (0.06 sec)
FLUSH PRIVILEGES;

 

728x90