mysql접속 뒤
use mysql;
select user, host from user;
유저의 목록과 접속 허용된 ip를 볼 수 있다.
mysql -uroot -p
로 root 계정으로 접속
mysql> create user USER_ID
@localhost
identified by 'USER_PASSWORD'
;
mysql> grant all privileges on DATABASE_NAME.* to USER_ID
@localhost
;
MariaDB [mysql]> create user taelee@localhost identified by '1234';
Query OK, 0 rows affected (0.001 sec)
MariaDB [mysql]> grant all privileges on *.* to taelee@localhost;
Query OK, 0 rows affected (0.000 sec)
mysql> grant all privileges on DATABASE_NAME.* to USER_ID
@localhost
identified by 'USER_PASSWORD'
;
MariaDB [mysql]> grant all privileges on *.* to secho@localhost identified by '1234';
Query OK, 0 rows affected (0.001 sec)
MariaDB [mysql]> select user, host from user;
+--------+-----------+
| user | host |
+--------+-----------+
| root | localhost |
| secho | localhost |
| taelee | localhost |
| user | localhost |
+--------+-----------+
4 rows in set (0.000 sec)
mysqladmin -u<user이름> -p password;
치고 현비번, 새로운 비번 치면 바뀜
update mysql.user set password=PASSWORD('바꿀 비번'
) where user='유저이름'
flush privileges;
MariaDB [(none)]> update mysql.user set password=PASSWORD('1234') where user='secho';
Query OK, 1 row affected (0.001 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
mysql> delete from user where user='USER_ID';
mysql> flush privileges;
테이블이나 데이터베이스의 권한을 grant로 수정할때는 flush privileges가 필요 없음
하지만 insert, update, delete로 권한을 수정했을때는 바로 반영이 안돼서 flush privileges로 새로고침을 해줘야함
출처: stack overflow
show grants for 'root'@'localhost';