db/mysql

mysql set user password

C/H 2019. 11. 13. 09:41

DB 추가

CREATE DATABASE database_name default CHARACTER SET UTF8mb4;
flush privileges;

DB권한을 가지는 사용자 추가

# GRANT ALL PRIVILEGES ON database_name.* TO user_name@hostname IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON database_name.* TO username@localhost IDENTIFIED BY 'password';

# INSERT INTO mysql.user (host, user, password) VALUES ('hostname', 'username', password('password'));
# insert into 를 사용하기 위해서는 null을 허용하지 않는 필드를 모두 구성해야 합니다.
flush privileges;

# 권한제거
# revoke all on database_name.table_name from user_name;
revoke all on databasename.tablename from username;

호스트 추가

GRANT ALL PRIVILEGES ON database_name.* TO 'root'@'xxx.xxx.xxx.%';
flush privileges;

비밀번호 변경

mysql> SET PASSWORD FOR 'user'@'localhost' = PASSWORD('password')
[20xx-xx-xx 18:15:42] [HY000][1287] 'SET PASSWORD FOR <user> = PASSWORD('<plaintext_password>')' is deprecated and will be removed in a future release. Please use SET PASSWORD FOR <user> = '<plaintext_password>' instead
[20xx-xx-xx 18:15:42] completed in 40 ms
mysql> flush privileges;
mysql> set password for 'user'@'localhost' = 'password'
[2019-xx-xx 18:16:13] completed in 24 ms
mysql> flush privileges;

# mysql8, root
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';
flush privileges;
반응형