상세 컨텐츠

본문 제목

ubuntu mysql 설치

ETC

by jeonghojin 2022. 12. 20. 17:54

본문

목적 : 개인 프로젝트 개발용 DB 서버 구축


- 오라클 클라우드 사용 : 50G 할당

- mobaXterm


1. 우분투 서버 업데이트

$sudo apt-get update

2. mysql-server 설치

$sudo apt-get install mysql-server

* 설치중 Password 물어볼 경우, OK  누르고 진행. (ubuntu 서버 비밀번호와 자동으로 동기화)


3. MySQL 기본 설정

- mysql 원격접속 허용

$sudo ufw allow mysql

- mysql 실행

$sudo systemctl start mysql

- Ubuntu 서버 재시작시 MySQL 자동 재시작

$sudo systemctl enable mysql

4. MySQL 접속

$sudo mysql -u root -p

 

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

위와 같은 에러 발생 시 mysql 대신 /usr/bin/mysql 과 같이 경로를 정확히 명시할 것


5. MySQL 서버 초기화

$sudo mysql_secure_installation

5-1 : 충분히 강한 패스워드를 생성할 수 있는 플러그인을 활성화하는지 물음. 엔터로 패스

Press y|Y for Yes, any other key for No:

5-2 : MySQL에서 사용될 패스워드를 물음. 데이터베이스 최고 관리자 권한 패스워드 (2번 입력)

Please set the password for root here.

New password:

Re-enter new password:

 

 


에러가 발생하지 않은 경우 선 아래로 진행 (5-3 부터 진행)

... Failed! error: SET PASSWORD has no significance for user 'root'@'localhost' as the authentication method used doesn't store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.

secure_installation에서 비밀번호를 설정하면 root 권한이 아닌 상태로 비밀번호를 설정했기 때문에 root 권한으로 비밀번호를 설정하라는 의미

 

다음과 같은 에러 발생시, 다음을 진행할 것

1. 해당 터미널을 종료하여 mysql_secure_installation 을 종료한다. ( 열려있을 경우, root로 인식하지 않음)

2. 터미널을 실행 후, sudo mysql 입력 후 mysql 접속

3. 다음과 같이 비밀번호를 변경한다.

* 정책에 맞게 설정하여야 한다.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '새로운 비밀번호'

* 이 경우, 또다시

 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

 과 같은 에러가 발생할 경우

 

1. 패스워드 정책 설정 확인

$SHOW VARIABLES LIKE 'validate_password%';

2.

SET GLOBAL validate_password.policy=LOW;

 


5-3 : 익명의 사용자를 제거하는지 물음

Remove anonymous users? (Press y|Y for Yes, any other key for No) : 

5-4 : 최고 관리자 권한으로 외부 로그인을 허용하지 않을 것인지 물음. (외부접속 차단일 경우 y)

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :

5-5 : test 데이터베이스를 삭제할지 물음

Remove test database and access to it? (Press y|Y for Yes, any other key for No) :

5-6 : privileges table 을 다시 로드할지 물음

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :

MySQL 데몬 재시작

$sudo /etc/init.d/mysql restart

MySQL 설정

 

$sudo mysql -u root  -p
CREATE USER '{계정명}'@'%' IDENTIFIED BY '{비밀번호}';

GRANT ALL PRIVILEGES ON * . * TO '{계정명}'@'%' WITH GRANT OPTION; 

FLUSH PRIVILEGES;

* @ 뒤 localhost 를 붙일 경우, local 에서만 접속 가능

* 특정 IP 또는 % 기호를 지정하여 외부에서 접속 할 수 있도록 설정

* /etc/mysql/mysql.conf.d/mysqld.cnf 파일의 [mysqld] 영역에서 bind-address 부분 주석 처리

 

MySQL 서버 데몬 재시작

$ sudo /etc/init.d/mysql restart

 

관련글 더보기