티스토리 뷰
1. 우분투 서버 업데이트
$ sudo apt-get update (apt-get 패키지 매니저 이용. 우분투 설치하면 같이 설치됨.)
2. mysql server 설치
$ sudo apt-get install mysql-server
3. 외부 접속 기능 설정 (3306 포트 오픈)
$ sudo ufw allow mysql
4. mysql 실행
$ sudo systemctl start mysql
5. ubuntu 서버 재시작시 mysql 자동 재시작
$ sudo systemctl enable mysql
6. mysql 접속
$ sudo /usr/bin/mysql -u root -p (경로 명시안하고 mysql만 쓰면 디나이 됨.)
7. 사용자 등록 및 권한 설정
mysql> SELECT User, Host, authentication_string FROM mysql.user;
8. mysql 버전 확인
show variables like "%version%";
------------------------------------------------------------------------------------------------------
5버전 mysql에서 8버전으로 변경을 원함.
1. mysql 삭제 및 8버전 설치
$ sudo systemctl stop mysql
$ sudo apt remove mysql-*
$ sudo apt purge mysql-*
$ sudo apt autoremove
$ sudo dpkg -l | grep mysql | grep ii
$ wget https://repo.mysql.com//mysql-apt-config_0.8.12-1_all.deb
$ sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
$ sudo sed -i 's/bionic/'$(lsb_release -sc)'/' /etc/apt/sources.list.d/mysql.list
$ sudo apt update
여기서 퍼블릭키 등록이 안되서 apt update 오류가 나는 경우가 있음.
해당 에러 뒤에 퍼블릭키 확인후 다음 명령어로 입력
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <PUBKEY>
ex) sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
그 다음 설치 진행하면 8버전 설치됨.
$ sudo apt install mysql-server
2. mysql_secure_installation 설정
각자 알맞게 설정 해주면 된다.
Securing the MySQL server deployment.
Enter password for user root:
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: N
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!
3. root 계정 접속해보기
mysql -u root -p
4. MySQL 서비스 시작
sudo systemctl start mysql.service
5. MySQL 서비스 중지
sudo systemctl stop mysql.service
6. MySQL 서비스 재시작
sudo systemctl restart mysql.service
7. MySQL 서비스 상태 검사
sudo systemctl status mysql.service
------------------------------------------------------------------------------------------------------
mysql 접근 테스트해보니 접근 불가.
외부 IP 접속 허용해줘야 함.
특정 IP 대역만 열어줄수도 있고 전체 열어줄수도 있음.
여러 곳에서 접근할 수 있어 전체 열여줌.
8버전은 다음과 같이 해줘야 함.
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'PASSWORD';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
정상 접근 확인.
------------------------------------------------------------------------------------------------------
22.07.25 추가
ubuntu 22로 바꾼 후 재설치에 위에 사항 다 적용했는데 접근이 불가한 증상 발생.
설정 변경없이 설치 했다면 netstat -tnlp 명령어로 포트 확인시 로컬:3306으로 되어 있음.
config 파일은 0.0.0.0으로 바꿔줘야함.
cd /etc/mysql 접근하여 sudo vi mysqld.cnf 명령어 후 파일을 변경해준다.(sudo 안하면 read only로 뜸.)
내리다보면 bind-address 부분을 로컬에서 0.0.0.0으로 열어주면 어디서든 접속가능.
특정 IP만 지정하고 싶을때는 특정 IP 지정해주면 됨.
'DB > MySQL' 카테고리의 다른 글
03. MySQL - timeout parameter (0) | 2022.09.12 |
---|---|
01. MySQL - 기존 테이블 생성문 가져오기 (0) | 2021.10.14 |