SET NAMES euckr 할지어다.


이걸로도 안되면 SET CHARSET euckr 도 해봐야..

근데 테이블이 utf8 이면 SET CHARSET utf8 이어야하나..

'DB' 카테고리의 다른 글

Mysql 대소문자 구분해서 쿼리하기  (0) 2012.03.17
Mysql MYSQLNonTransientConnectionException  (0) 2012.03.17
Mysql 한글검색  (0) 2012.03.17
Mysql 에서 foreign key 설정  (0) 2012.03.17
Posted by 휘사마
,
SELECT COUNT(*) 
  FROM user 
  WHERE userId=BINARY(#userId:VARCHAR#) and password=BINARY(#password:VARCHAR#) 


아 물론 이건 ibatis xml 파일에 넣는 것이고...

요지는 binary 로 감싸준다는 것이다.

'DB' 카테고리의 다른 글

Mysql에서 한글이 깨질 때  (0) 2012.03.17
Mysql MYSQLNonTransientConnectionException  (0) 2012.03.17
Mysql 한글검색  (0) 2012.03.17
Mysql 에서 foreign key 설정  (0) 2012.03.17
Posted by 휘사마
,
장시간(확인한 바로는 10시간 넘게..) MySQL이 idle 상태면 커넥션이 닫혀버린다.

그래서 MySQLNonTransientConnectionException 이 발생하게 되는데... (자바에서)


아래는 참고문서

http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html

autoReconnect Should the driver try to re-establish stale and/or dead connections? If enabled the driver will throw an exception for a queries issued on a stale or dead connection, which belong to the current transaction, but will attempt reconnect before the next query issued on the connection in a new transaction. The use of this feature is not recommended, because it has side effects related to session state and data consistency when applications don't handle SQLExceptions properly, and is only designed to be used when you are unable to configure your application to handle SQLExceptions resulting from dead and stale connections properly. Alternatively, investigate setting the MySQL server variable "wait_timeout" to some high value rather than the default of 8 hours.

이런 설명이 나온다... 

서버 옵션에 대한 설명은 아래에 있다.

http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html

MySQL 5.1 의 경우 설치 디렉토리 아래의 my.ini 파일을 수정해주면 된다.

#연결 시간 timeout 설정
wait_timeout=100000000
interactive_timeout=00000000


위와 같은 항목을 추가해준다.

wait_timeout 과 interactive_timeout 의 차이는 잘 모르겠다


설정 후 mysql 서비스를 재시작한다 (윈도우의 경우)

▶ 윈도우
[제어판] - [관리도구] - [서비스] - MySQL 서비스 다시 시작 ( 컨텍스트 메뉴 )
  
▶ 리눅스
$etc/initd/mysql/mysql restart 

'DB' 카테고리의 다른 글

Mysql에서 한글이 깨질 때  (0) 2012.03.17
Mysql 대소문자 구분해서 쿼리하기  (0) 2012.03.17
Mysql 한글검색  (0) 2012.03.17
Mysql 에서 foreign key 설정  (0) 2012.03.17
Posted by 휘사마
,

Mysql 한글검색

DB 2012. 3. 17. 20:29
SELECT * FROM table WHERE BINARY(text) like %한글%


column 의 type은 BINARY 또는 VARBINARY 여야 한다.

(기존에 VARCHAR 였어도 상관없다. column type을 바꾸면 아무 부작용 없이 컨버팅 된다)


ibatis 에서는 다음과 같이 쓰자.

 <select id="getArticleListWithTitle" parameterClass="HashMap" resultClass="beans.Article">
  SELECT *
  FROM board_board
  WHERE boardName = #boardName:VARCHAR# AND BINARY(title) LIKE CONCAT('%',#titleKeyword:VARCHAR#,'%') 
  ORDER BY articleIndex DESC
 </select>


**
그렇다면 '%' 는 어떻게 표현할까?

mysql 에서는 \% 로 표현한다.

인자로 넘겨주기 전에 replace 로 % 를 \\% 로 바꾸어 주도록 하자. ( titleKeyword.replace("%", "\\%") )



beans class의 member 의 type을 바꿀 필요는 없다.

다만 아래와 같은 처리가 setter 에서 필요하다.

Util.toHTML() 은 문맥과 무관하니 없다고 생각하고 보자.

 public String getTitle() {
  return title;
 }
 public void setTitle(byte[] title) {
  try {
   this.title = Util.toHtml(new String(title,"utf-8"));
  }
  catch(Exception e)
  {
   e.printStackTrace();
  }
 }

'DB' 카테고리의 다른 글

Mysql에서 한글이 깨질 때  (0) 2012.03.17
Mysql 대소문자 구분해서 쿼리하기  (0) 2012.03.17
Mysql MYSQLNonTransientConnectionException  (0) 2012.03.17
Mysql 에서 foreign key 설정  (0) 2012.03.17
Posted by 휘사마
,

Mysql 에서 foreign key 설정

DB 2012. 3. 17. 20:28

table A에 primary key인 column pk 가 있고 이를 다른 table B,C,D ... 에서 foreign key로 설정하려고 했다.

그런데 2개 이상 지정을 하려고 하니 에러가 나며 테이블이 만들어지지 않았다.

이유는 다음과 같다.

[CONSTRAINT [symbol]] FOREIGN KEY
    [index_name] (index_col_name, ...)
    REFERENCES tbl_name (index_col_name,...)
    [ON DELETE reference_option]
    [ON UPDATE reference_option]

reference_option:
    RESTRICT | CASCADE | SET NULL | NO ACTION

요기 symbol 의 이름이 database를 통틀어 unique 해야되기 때문이었다.

저게 왜 db를 통틀어 unique 해야되도록 만들어 놓은지 이유를 잘 모르겠다. -_-;


http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

http://www.lovelgw.com/Blog/207

'DB' 카테고리의 다른 글

Mysql에서 한글이 깨질 때  (0) 2012.03.17
Mysql 대소문자 구분해서 쿼리하기  (0) 2012.03.17
Mysql MYSQLNonTransientConnectionException  (0) 2012.03.17
Mysql 한글검색  (0) 2012.03.17
Posted by 휘사마
,