블로그 이미지
Rootrator
1개를 알면 모르는 10개가 튀어나온다..!

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

2019. 2. 20. 17:13 Mysql


[서버환경]

CentOS 6.7 64bit

Mysql 5.7.24



백업 스크립트에서 종종 mysqldump를 이용해서 백업을 받곤했는데


5.6버전 이상부터는 스크립트내에서 쓰던 로그인 방법으로는 아래와 같은 에러가 나오고 진행이 되지 않는다.


mysql : Warning: Using a password on the command line interface can be insecure.



mysql_config_editor 를 이용해서 로그인 설정을 만들어 해당 설정을 이용해야 한다.



]# mysql_config_editor set --login-path=설정명 --host=localhost --user=root --password

Enter password:



설정을 마지면 유저의 홈디렉토리에 .mylogin.cnf 파일이 생긴다.



설정을 확인하려면 아래와 같은 명령어로 확인하면 된다.


]# mysql_config_editor print --all

[설정명]

user = root

password = *****

host = localhost



이후 스크립트에는 아래와 같이 변경하면 된다.


mysqldump --login-path=설정명 DB이름 > 백업파일명.sql

반응형

'Mysql' 카테고리의 다른 글

시간 변환 함수  (0) 2015.04.15
Mysql 튜닝  (0) 2014.07.03
Mysql 5.5 한글설정  (0) 2013.11.11
Mysql에서 too many connection에러  (0) 2011.10.11
1017 : Can't find file: '테이블명.frm' (errno: 13)  (0) 2011.09.22
posted by Rootrator
2015. 4. 15. 14:55 Mysql

DB 테이블 내용에 8자리의 Date형식이 보이는데 이는 unix_timestamp를 이용해

형식을 변환한 것이다. 


2015-04-15 10:00:00


Date Time -> UnixTime

select UNIX_TIMESTAMP('2015-04-15 10:00:00');

1429059600


UnixTime -> DateTime

select FROM_UNIXTIME('1429059600');

2015-04-15 10:00:00



반응형
posted by Rootrator
2014. 7. 3. 17:48 Mysql

퍼포먼스를 올리기 위한 몇가지 튜닝법


MySQL 접속구문

메모리가 2GB이상은 pconnect

메모리가 2GB이하는 connect



인덱스추가

where 구문과 일치하는 열을 찾을때

join문 실행시 다른 테이블에서 열을 추출할때

열을 검색대상에서 빨리 제외할때


생성

create index 인덱스명 on 테이블명 (컬럼명1,컬럼명2,...);

alter table 테이블명 add index 인덱스명(컬럼명1,컬럼명2,...);


인덱스보기

show index from 테이블명;


삭제

alter table 테이블명 drop index 인덱스명;



쿼리속도

2개의 쿼리를 질의할때의 쿼리 속도는


쿼리2개 > join문 > 서브쿼리


쿼리가 많을땐 차라리 쿼리문을 나누자

반응형
posted by Rootrator
2013. 11. 11. 16:41 Mysql

mysql 5.5 이전버전에서 5.5버전으로 넘어오기 위해 dump로 옮겨올 경우 한글이 깨지거나


정렬이 틀어지는 경우가 있다.


mysql 5.5 설치후 캐릭터셋을 맞춰주지 않으면 latin1으로 자동설정이 되기 때문


mysql> show variables like 'c%';


위 명령어로 현재 서버상의 캐릭터셋을 확인 할수 있다.


캐릭터셋 설정을 위해 my.cnf 파일을 열어 아래와 같이 추가해주자. 여기서는 euckr을 기본으로 사용했다.

utf-8을 사용하려면 euckr대신 utf8을 넣어 추가.


[client]

default-character-set = euckr


[mysqld]

character-set-client-handshake=FALSE

init_connect=SET collation_connection = euckr

init_connect=SET NAMES EUCKR

character-set-server = euckr


[mysqldump]

default-character-set = euckr



UTF-8을 사용하려면 [mysqld] 섹션에 아래줄을 하나더 추가해 준다.

init_connect=SET character_set_system = utf8


마치고나서 mysql 재시작을 하면 정상적으로 반영되어 있다.


정렬이 틀어진 경우는 dump을 다시 떠서 복원을 하거나


phpmyadmin을 통해서 데이터정렬방식을 맞춰주면 정상적으로 정렬이 된다.


phpmyadmin 4.0.x 버전이상은


curl과 mysqli 라이브러리가 필요하다.


php 재컴파일시 아래 옵션을 추가

--with-openssl=/usr/local/openssl 

--with-curl=/usr/bin/curl 

--with-mysqli=/usr/local/mysql/bin/mysql_config


반응형

'Mysql' 카테고리의 다른 글

시간 변환 함수  (0) 2015.04.15
Mysql 튜닝  (0) 2014.07.03
Mysql에서 too many connection에러  (0) 2011.10.11
1017 : Can't find file: '테이블명.frm' (errno: 13)  (0) 2011.09.22
MySql 설치에러 : checking "LinuxThreads"... "Not found"  (0) 2011.07.28
posted by Rootrator
2011. 10. 11. 16:36 Mysql

위에 에러를 뱉으면서 서버가 DB가 뻗는 경우가 있다.

Mysql에 접속하여 show variables;로 환경변수를 확인할 수 있다.

mysql> show variables;
 +---------------------------------+----------------------------------------+
| Variable_name                   | Value                                  |
+---------------------------------+----------------------------------------+
| max_connections                 | 100                                    |
| table_cache                     | 64                                     |
| wait_timeout                    | 28800                                  |
+---------------------------------+----------------------------------------+

참고해야할 것만 뽑아놨다.

위의 Max_Connection값이 꽉차면 오류가 뜨게 된다.

보통 mysql_close()함수가 제대로 안먹히게 되면 프로세스가 계속 DB를 물고 늘어지는데

show processlist;로 확인이 가능하다.


환경변수 설정을 해보자.
[root@localhost ~]# vi /etc/my.cnf
 
[mysqld]
 max_connections = 
 wait_timeout =
 table_cache = 128

 
공란은 적정값을 넣으면 되겠다.

혹은 실행 명령에서

[root@localhost bin]# ./safe_mysqld -O max_connection= -O wait_timeout=  table_cache=128 &

 
  
반응형

'Mysql' 카테고리의 다른 글

Mysql 튜닝  (0) 2014.07.03
Mysql 5.5 한글설정  (0) 2013.11.11
1017 : Can't find file: '테이블명.frm' (errno: 13)  (0) 2011.09.22
MySql 설치에러 : checking "LinuxThreads"... "Not found"  (0) 2011.07.28
Got error 127 from storage engine  (0) 2011.07.06
posted by Rootrator
2011. 9. 22. 15:53 Mysql

가끔 DB복원 중에 이런 에러가 발생한다.

Mysql DB복원 방법 중에는 mysqldump도 있지만 간단히

var 디렉토리 밑의 파일을 교체하는 것으로 복원이 가능하다.

(innoDB가 기본 스토리지 일때는 서비스를 완전히 내리고 작업을 해줘야 한다)

이때 복원 할때 cp 명령어를 옵션없이 썼다면 소유자가 바뀌어 위와 같은 에러가 발생한다.

해당 디렉토리 및 db파일의 소유자를 확인해서 맞춰주면 된다. 
반응형
posted by Rootrator
2011. 7. 28. 17:06 Mysql
mysql configure시에 

checking "LinuxThreads"... "Not found"
configure: error: This is a linux system and Linuxthreads was not found. On linux Linuxthreads should be used.  Please install Linuxthreads (or a new glibc) and try again


뭐 이런 에러가 뜬다.

[root@localhost ~]# echo '/* Linuxthreads */' >> /usr/include/pthread.h 

해당 명령어 입력해 준후에 다시 시도해 보면 정상적으로 시도된다. 
반응형
posted by Rootrator
2011. 7. 6. 17:15 Mysql

느닷없이 index 페이지에서 다음 오류를 뱉었다.

"Got error 127 from storage engine" 


 테이블중 하나가 깨진건데 직접 페이지를 제작한게 아니라 어느테이블을 읽어오는 과정에서 오류 났으면..

빨리 찾았을 텐데.. 그게 아니라 일일히 모든 테이블을 select로 조회해 보니 하나의 테이블에서 오류가 났다.

mysql> select * from tbl_log;
ERROR 1030 (HY000): Got error 127 from storage engine
 

에러가 나는 테이블을 찾았으면

mysql> Analyze table tbl_log;
+-----------------------+---------+----------+----------+
| Table                          | Op        | Msg_type | Msg_text |
+-----------------------+---------+----------+----------+
| db.tbl_log                     | analyze |   status   | OK          |
+-----------------------+---------+----------+----------+
1 row in set (1.21 sec)


 mysql> repair table tbl_log;
+-----------------------+--------+----------+------------------------------------------------------+
| Table                 | Op     | Msg_type | Msg_text                                             |
+-----------------------+--------+----------+------------------------------------------------------+
db.tbl_log           | repair | info     | Read error for block at: 9625580 (error: 5); Skipped |
db.tbl_log           | repair | info     | Read error for block at: 9625588 (error: 5); Skipped |
db.tbl_log           | repair | warning  | Number of rows changed from 74336 to 74332           |
db.tbl_log           | repair | status   | OK                                                   |
+-----------------------+--------+----------+------------------------------------------------------+
4 rows in set (16.67 sec)
반응형
posted by Rootrator
2011. 3. 30. 16:20 Mysql

요 근래 2대의 서버IP 변경 후에 게시물을 살펴보니

VOD게시판에 동영상 링크를 ip로 직접 걸어놓은 게시물이 있었다..

게다가 그 양이 어마어마해서 일일히 수정하기엔 시간도 걸리고 해서..

mysqldump로 sql파일을 추출해서 일괄 수정후 복원 해 주시로 했다.

먼저 mysqldump로 db를 백업

[root@localhost ~]# /usr/local/mysql/bin/mysqldump -uroot -p패스워드 BD명 > 파일명.sql

그런데 오류가 떳다.

mysqldump: Got error: 1017: Can't find file: './디비명/테이블명.ftm' (errno: 24) when using LOCK TABLES

테이블에 Lock가 걸려있다고 한다.

--lock-all-tables 옵션을 넣어 주면 정상적으로 백업이 진행된다.

[root@localhost ~]# /usr/local/mysql/bin/mysqldump -uroot -p패스워드 --lock-all-tables DB명 > 파일명.sql

자 이제 vi로 일괄 치환 작업을 진행한 후 저장하다.

vi편집기 일괄 치환
:%s/찾을문자열/바꿀문자열/g

이제 다시 복원을 해주도록 하자.

[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p패스워드 DB명 < 파일명.sql


정상적으로 게시물이 수정되었다.

반응형
posted by Rootrator
2011. 3. 24. 12:11 Mysql

어느날 홈페이지상에서 테이블이 깨져 복구를 해야 한다는 메세지가 뜬적이 있었다.

myisamchk로 체크 후 복구를 해보자.

[root@localhost bin]# ./myisamchk ../var/깨진DB.MYI
Checking MyISAM file: ../깨진DB.MYI
Data records:     886   Deleted blocks:       0
myisamchk: warning: Table is marked as crashed
myisamchk: warning: 27 clients are using or haven't closed the table properly
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
- check data record references index: 2
- check data record references index: 3
- check data record references index: 4
- check data record references index: 5
- check data record references index: 6
- check data record references index: 7
- check data record references index: 8
- check data record references index: 9
- check data record references index: 10
- check data record references index: 11
- check record links
myisamchk: error: Checksum for key:  8 doesn't match checksum for records
MyISAM-table '../var/깨진DB.MYI' is corrupted
Fix it using switch "-r" or "-o"

-r이나 -o 옵션을 주어 복구 하란다.

[root@localhost bin]# ./myisamchk -r ../var/깨진DB.MYI
- recovering (with sort) MyISAM-table '../var/깨진DB.MYI'
Data records: 886
- Fixing index 1
- Fixing index 2
- Fixing index 3
- Fixing index 4
- Fixing index 5
- Fixing index 6
- Fixing index 7
- Fixing index 8
- Fixing index 9
- Fixing index 10
- Fixing index 11

이제 정상적으로 복구가 되었다

반응형
posted by Rootrator
prev 1 2 next