# MySQL CLI (Frequently used)

## 사용자 목록, 추가 , 제거 권한 부여

| 기능                          | 명령어                                                                                                  | 사용예                                                                                                         |
| --------------------------- | ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| <p>서버 로그인 <br>(MySQL접속)</p> | mysql -u \[username] -p;                                                                             | <p>• mysql –u root –p; <br>• password입력</p>                                                                 |
| 사용자 목록 조회                   | <p>use mysql;<br>select user, host from user;</p>                                                    | <p>•mysql기본 스키마 mysql안에<br>•mysql 기본스키마인 user table에서 확인가능.</p>                                             |
| 사용자 추가                      | create user {username}@{ip} identified by '{password}';                                              | <p>•create user bit\@localhost identified by 'bit';<br>•create user bit\@123.456.% identified by 'bit';</p> |
| 사용자 제거                      | <p>drop user {username};<br>drop user 'user'@'localhost';delete from user where user={username};</p> | •drop 추천                                                                                                    |
| 권한 확인                       | show grants for {username}@{ip};                                                                     | • show grants for bit\@localhost;                                                                           |
| 권한 부여                       | grant {권한} privileges on {스키마}.{테이블} to {username}@{ip};                                             | • grant all privileges on \*.\* to bit\@localhost;                                                          |
| 권한 제거                       | revoke {권한} privileges on {스키마}.{테이블} from {username}@{ip};                                          | • revoke all on bit.\* from bit\@localhost;                                                                 |
| 사용자 전환                      | <p>system mysql -u \[사용자명] -p <br>\[password]</p>                                                    | system mysql -u madang -p madang                                                                            |

## DATABASE 생성, 목록, 보기

| 기능        | 명령어                          | 사용 예                      |
| --------- | ---------------------------- | ------------------------- |
| 데이터베이스 생성 | create database \[database]; | • database 생성             |
| 데이터베이스 선택 | use \[database];             | • database 선택             |
| 데이터베이스 보기 | show databases;              | • database 어떤 게 있는지 보여줌   |
| 테이블 보기    | show tables;                 | • database 에 있는 테이블 보여준다. |

## Windows에서 Database 관리

* windows용 MySQL은 windows 재 부팅시 자동 실행 된다. 윈도우 서비스를 통해 관리
* 윈도우 검색 창에서는 services
* 실행창 (window + R) 에서는 services.msc 입력.
* 나의 경우 하루 하루 종일 쓰지 않기 때문에, 부팅 시 수동으로 켤 수 있도록 했다.

![](/files/-MRTIQhMPVg6WREAbjfQ)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://minhee0327.gitbook.io/mini-til/undefined/untitled.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
