생계/MySQL2024. 1. 15. 14:36

 

mysql 접속시 유저/패스워드 입력안하고 로긴하는 방법을 알아보자 

 

lee@mysql-m:~$ 
lee@mysql-m:~$ mysql_config_editor print --all
lee@mysql-m:~$ 
lee@mysql-m:~$ mysql_config_editor set --login-path=rootconn --host=localhost --user=root --password
Enter password: 
lee@mysql-m:~$ 
lee@mysql-m:~$ 
lee@mysql-m:~$ ls -al
합계 48
drwxr-xr-x  6 lee  lee  4096  1월 16 21:43 .
drwxr-xr-x  3 root root 4096  1월 13 01:00 ..
-rw-------  1 lee  lee   106  1월 14 19:46 .Xauthority
-rw-------  1 lee  lee  1416  1월 16 17:57 .bash_history
-rw-r--r--  1 lee  lee   220  1월 13 01:00 .bash_logout
-rw-r--r--  1 lee  lee  3771  1월 13 01:00 .bashrc
drwx------ 11 lee  lee  4096  1월 13 01:29 .cache
drwx------ 11 lee  lee  4096  1월 14 18:21 .config
drwx------  3 lee  lee  4096  1월 13 01:14 .gnupg
drwxr-xr-x  3 lee  lee  4096  1월 13 01:14 .local
-rw-------  1 lee  lee   136  1월 16 21:44 .mylogin.cnf
lee@mysql-m:~$ mysql_config_editor print --all
[rootconn]
user = "root"
password = *****
host = "localhost"
lee@mysql-m:~$ 

mysql_config_editor 명령으로 credential 을 생성하면 유저 홈 디렉토리에 ".mylogin.cnf" 파일이 생성이 된다.

이후부터는 mysql 로긴시 패스워드를 입력할 필요없이 login-path 옵션을 붙여주면 된다.  

 

반응형
Posted by 돌고래트레이너
생계/MySQL2024. 1. 15. 00:30

virtual box 에 mysql master-slave replication 을 구성해보자  

가상머신은 oracle virtual box 을 사용하고 VM 에는 우분투를 설치하자. 

해당 작업은 이전에 작성한 내용을 참고하자

버추얼박스에 우분투 설치하기

1) 서버구성 

- mysql 설치 (master 역할) 

이것도 이전에 작성한 글을 참고해서 mysql 설치하자. 

버추얼박스에 mysql 설치하기

- vm 복제 (slave 역할)

vm 이 내려간 상태에서 vm 관리자 메뉴에서 대상vm을 복제하자

 

이름과 경로를 설정해준다.

 

같은 네트워크 대역을 사용하여 slave 에서 master 로 통신이 가능하게 설정해야한다. 
 vm 시작전 설정 -> 네트워크 -> 호스트전용어댑터


- hostname 변경 

복제한 vm의 hostname 이 그대로 사용중이니 mysql-s 로 변경해준다. 

@slave 

hostname
sudo hostnamectl set-hostname mysql-s

sudo reboot


2) Replication 설정
 2-1) 설정파일

@master
cd /etc/mysql
sudo vi my.cnf
[mysqld]
log-bin=mysql-bin
server-id=1

sudo service mysql restart

*선택적 설정 고려 
max_binlog_size
expire_log_days
binlog_format=statement|mixed|row


@slave
cd /etc/mysql
sudo vi my.cnf

[mysqld]
server-id=2
relay-log=mysql-relay-bin
read_only

sudo service mysql restart


 2-2) Replication 유저 생성
@master
sudo mysql -u root -p1111

-- slave ip 로 생성한다. 
CREATE USER 'REP_ADM'@'192.168.56.102' IDENTIFIED WITH mysql_native_password BY '1111';
GRANT REPLICATION SLAVE ON *.* TO 'REP_ADM'@' 192.168.56.102';
   
SHOW MASTER STATUS;  

File, Position 값을 확인 

@slave 
sudo mysql -u root -p1111

-- master IP 를 넣는다 
CHANGE MASTER TO
MASTER_HOST='192.168.56.101',  
MASTER_USER='REP_ADM',
MASTER_PASSWORD='1111',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000004',
MASTER_LOG_POS=2391;

START SLAVE;

SHOW SLAVE STATUS \G
=> [ERROR] : equal MySQL server UUIDs

sudo rm -rf /var/lib/mysql/auto.cnf
sudo service mysql restart


START SLAVE;


3) Replicatin 연결 확인 

-- 복제확인
sudo mysql --login-path=rootconn -e 'show slave status \G'|egrep "Master_Host|Master_User|Master_Log_File|Master_Log_Pos|ReplicateIgnore_DB|Running|IO_Err|SQL_Err|Seconds_Behind_Master|SQL_Delay"

** 아래 메세지가 보여야 정상 복제중
Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates


-- 에러확인
show variables like '%log_error%';
=> tail -100f  /var/log/mysql/error.log



4) Replication 에러 메시지별 대응

[ERROR] [MY-013117] [Repl] Replica I/O for channel '': Fatal error: The replica I/O thread stops because source and replica have equal MySQL server UUIDs; these UUIDs must be different for replication to work. Error_code: MY-013117
=> VM 을 복제하면서 동일 uuid 문제 => auto.cnf 삭제 

[ERROR] [MY-013124] [Repl] Replica SQL for channel '': Replica failed to initialize applier metadata structure from the repository, Error_code: MY-013124
=> slave 를 리셋해준다. 
  stop slave; 
  reset slave;
  stop slave;
   
[ERROR] [MY-010584] [Repl] Replica I/O for channel '': Error connecting to source 'REP_ADM@192.17.7.5:3306'. This was attempt 1/86400, with a delay of 60 seconds between attempts. Message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection. Error_code: MY-002061
=> rep user error : Authentication 확인 => mysql.user 의 plugin 확인 후 변경 => WITH mysql_native_password

[ERROR] [MY-010584] [Repl] Replica SQL for channel '': Worker 1 failed executing transaction 'ANONYMOUS' at source log mysql-bin.000003, end_log_pos 342; Error 'Can't create database 'test'; database exists' on query. Default database: 'test'. Query: 'create database test', Error_code: MY-001007
=> 트랜잭션 실패 : 대상 object 가 존재하지 않거나 실행할수 없어서 발생. skip 또는 object 동일하게 만들고 slave 재시작

** 트랜잭션 실패로 인한 에러메세지가 아는 내용이고 굳이 적용할 필요 없으면 아래명령으로 skip 한다. 
stop slave;
set global sql_slave_skip_counter=1;  -- skip 할 error 갯수
start slave;
show slave status\G

 

이상 끗.

도움되었다면 따봉줘!

반응형
Posted by 돌고래트레이너
생계/MySQL2024. 1. 13. 02:33

vm 재설치한 mysql 에 workbench 로 재접속시 에러 발생 

server public key 를 삭제

해당 파일을 날려준다. 

 

반응형

'생계 > MySQL' 카테고리의 다른 글

mysql login-path 로 로그인하기  (0) 2024.01.15
가상머신 virtualbox mysql replication 구성하기  (0) 2024.01.15
mysql 자주쓰는 함수  (0) 2023.11.06
mysql show 명령어 db정보 확인  (0) 2023.10.23
mysql select lock  (0) 2021.08.02
Posted by 돌고래트레이너