컴퓨터 / Computer

MySQL/MariaDB DB 생성 및 사용자 아이디 생성

공유지기 2 3,220 2023.07.17 11:42

0_fivEmSUN_cafc0046fceae53820e6e11ed19a3a0d3034ec3c.jpg 






1. update문을 이용하여 root 암호 설정


 $ mysql -u root mysql


 mysql> update user set password = password('new-password') where user = 'root';

 mysql> flush privileges;



2. set password를 이용하여 root 암호 설정


 mysql> set password for root = password('new-password');



3. 데이터베이스 보기


 myslq> show databases;


4. 데이터베이스 생성


 mysql> create database DB명;


5. 일반 사용자 추가

 mysql> grant all privileges on dbuser.* to dbuser@localhost identified by 'password' with grant option;


6. 특정 이름의 데이터베이스에 대한 모든 권한을 가지는 사용자 추가

 mysql> grant all privileges on `dbuser_%`.* to dbuser@localhost identified by 'password' with grant option;


7. 모든 권한을 준다면 아래와 같은 방법을 하는것이 더욱 편리힙니다.


 mysql> GRANT ALL on DB명.* TO id@'localhost'  ;

 mysql> GRANT ALL on DB명.* TO id;

 mysql> GRANT ALL on DB명.* TO id@'xxx.xxx.xxx.%';


8. 반영할때


 mysql> FLUSH PRIVILEGES;

Comments

Sha_bler 2025.02.07 17:39
최근에 1과 2 부분은 "mysql_secure_installation"를 쓰도록 바뀌었다고 한다.

https://docs.vultr.com/how-to-install-mysql-on-freebsd-14-0
Sha_bler 2025.02.11 16:22
MySQL 8.0 이후 부터는 5와 6으로 할 수가 없다. 따로 해 줘야 한다.

즉 계정을 먼저 생성하고 그 후에 DB 권한을 줘야 한다.

https://nonaninona.tistory.com/58
https://gomszone.tistory.com/entry/MySQL-%EC%98%A4%EB%A5%98-%ED%95%B4%EA%B2%B0-ERROR-1064-42000

WL 핑구스티커 펭귄 핑구 핑가 다꾸 스티커 다이어리 노트북 핸드폰 꾸미기 스티커 다꾸 용품
칠성상회
스테들러 피그먼트라이너 흑색 수성펜 6본세트
칠성상회
WL 계기판 차량용 거치대 B형 스마트폰 차량 스파크
칠성상회
포켓몬카드 초전브레이커 1팩
칠성상회