프로그래밍

[토막팁] global gitignore & MySQL charset default 설정

2kindsofcs 2020. 4. 18. 23:02

1. global gitignore 

git을 써본 적이 있다면 .gitignore의 존재를 알 것이다.

.gitignore에 추가된(작성된) 디렉토리들은 말 그대로 무시되며, untracked files에도 내역이 보이지 않는다. 

http://gitignore.io/ 같은 사이트를 쓰면 편리하다.

운영체제와 프로그래밍 언어 등을 고르면 적당한 .gitignore를 손쉽게 만들 수 있다. 

 

그런데, global gitignore도 존재한다. 

https://help.github.com/en/github/using-git/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer

You can also create a global .gitignore file to define a list of rules for ignoring files in every Git repository on your computer. For example, you might create the file at ~/.gitignore_global and add some rules to it.

1. Open Terminal.
2. Configure Git to use the exclude file ~/.gitignore_global for all Git repositories.$ git config --global core.excludesfile ~/.gitignore_global

global gitignore를 작성해두면 작성된 디렉토리들은 해당 컴퓨터에 있는 모든 git 저장소에서 무시된다.

IDE와 관련된 파일들은 global gitignore에 넣어두면 좋을 것이다. 

 

Ex) 나는 goland를 사용하는데, 다른 사람은 visual studio code를 쓸 수도 있다. 

 

2. MySQL charset default 설정

CREATE DATABASE db_name
    [[DEFAULT] CHARACTER SET charset_name]
    [[DEFAULT] COLLATE collation_name]

ALTER DATABASE db_name
    [[DEFAULT] CHARACTER SET charset_name]
    [[DEFAULT] COLLATE collation_name]

character set과 collation은 database에만 설정할 수 있는 게 아니다.

테이블과 컬럼에도 각기 설정할 수 있다. 

 

고로 기본 character set과 collation을 설정해서 database 생성하고 난 뒤 table을 생성할 때 주의해야 한다. 

공식 문서를 보면 아래와 같은 내용이 있다. 

For CREATE TABLE statements, the database character set and collation are used as default values for table definitions if the table character set and collation are not specified. To override this, provide explicit CHARACTER SET and COLLATE table options.

만약 내가 아래와 같은 SQL로 database를 만들었다고 가정하자.

CREATE DATABASE example_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

그렇다면 example_db 밑에 table을 만들 때 character set과 collation을 지정해주지 않아야

각각 utf8mb4와 utf8mb4_unicode_ci가 적용된다는 것이다.

간단한 부분이지만 실수할 수 있으므로 주의하면 좋겠다. 

반응형