11/12
함께 배우는 프로그래밍 방송

오늘은 “MySQL과 MariaDB" 입니다.

12:00부터 1시간 정도 방송합니다.  



으악 DB에 한글이 안들어가요.

Exception in thread "main" java.sql.SQLException: Incorrect string value: '\xEB\xB0\xB1\xEA\xB8\xB0...' for column 'name' at row 1

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2046)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1964)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1949)

at springbook.user.dao.UserDao.add(UserDao.java:23)

at springbook.user.dao.UserDao.main(UserDao.java:60)



mysql> SHOW VARIABLES LIKE '%olla%';
+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | utf8_general_ci   |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)

mysql> 

Class.forName("com.mysql.jdbc.Driver");

Connection c = DriverManager.getConnection("jdbc:mysql://localhost/springbook?characterEncoding=UTF-8", "spring","book");


방법을 찾았습니다만, 쉽지 않은 문제였습니다. DB에 대한 이해가 필수겠지요. varchar(20)을 longtext  로 잡았습니다.

create table users (

id varchar(10) primary key,

name longtext not null,

password varchar(10) not null

) DEFAULT CHARSET=utf8;



현재 DB 설정과 내용은 다음과 같습니다.
kenuheoyimacbookpro-4:bin kenu$ ./mysql -u spring -p springbook
Enter password: 
...
Server version: 5.5.8 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
...
mysql> show variables like '%olla%';
+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | utf8_general_ci   |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)

mysql> select * from users;
+-----------+-----------+----------+
| id        | name      | password |
+-----------+-----------+----------+
| whiteship | 백기선    | married  |
+-----------+-----------+----------+
1 row in set (0.00 sec)

mysql> 



처음 맥에 MySQL을 설치해서 돌려봅니다. 2006년부터 맥을 써왔지만, 이번에 처음입니다.
http://www.mysql.com 에서 mysql-5.5.8-osx10.6-x86_64.dmg 파일을 다운로드 받아서 3가지를 설치했습니다.

./mysql-5.5.8-osx10.6-x86_64.pkg
./MySQLStartupItem.pkg
./MySQL.prefPane

MySQL.prefPane 이후에 이렇게 시스템 환경설정에 만들어집니다.

메뉴에 들어가면 Start/Stop 그리고 현재 DB 사용여부 표시 기능 밖에는 없습니다.

DB를 실행한 뒤에 다음과 같이 토비의 스프링3를 위해서 DB와 table을 만들었습니다.

kenuheoyimacbookpro-4:docs kenu$ mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6081
Server version: 5.5.8 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> grant all privileges on *.* to spring@localhost
    -> identified by 'book' with grant option;
Query OK, 0 rows affected (0.04 sec)

mysql> create database springbook;
Query OK, 1 row affected (0.02 sec)

mysql> use springbook;
Database changed

mysql> create table users (
    -> id varchar(10) primary key,
    -> name varchar(20) not null,
    -> password varchar(10) not null
    -> );
Query OK, 0 rows affected (0.46 sec)

mysql> 

spring 아이디에 book 비번으로 접속 가능하게 하고 springbook 이라는 database를 만들고, 그 안에 users라는 table을 만든 것입니다. 

계속 진도 나가야겠습니다. 갈 길이 멉니다.

오늘 확인해보니 박현준님의 글로 잘 올라갔습니다.
http://www.imaso.co.kr/?doc=bbs/gnuboard.php&wr_id=34400&bo_table=article 에서
프로덕트│CUBRID 마이그레이션 프로젝트│박현준 제목을 확인할 수 있습니다.


MySQL과 Cubrid의 경험에 비추어보면 어느 것이 더 낫다라고 딱 잘라 말하기 어렵습니다.
OKJSP DB마이그레이션 프로젝트는 잘 오픈해서 운영중입니다.

마이그레이션 하면서 사용한 커맨드나 절차 등이 담겨져 있습니다.
프로젝트와 더불어 원고 작성하느라 수고했습니다.
concat()은 oracle스럽게 변경하면 됩니다.

mysql:
    where email like concat('%',#value#,'%')

cubrid:
    where email like '%'||#value#||'%'

참고:
http://www.cubrid.com/zbxe/40190
3가지가 지원됩니다.
mysql에서 cubrid로 마이그레이션 하면서 old_password() 함수 이전이 이슈가 되었는데, 그것을 지원하는 방법이 있습니다.

자바 저장 함수로 MYSQL 암호화 함수 구현하기
http://www.cubrid.com/zbxe/32442

select md5('qwer1234') from db_root;

select password('qwer1234') from db_root;

select old_password('qwer1234') from db_root;


위와 같이 sql에서는 동일하게 사용할 수 있습니다.

7시 토즈강남대로점에서 5명이 모였습니다. 오리엔테이션이라고 할 수 있는 프로젝트 멤버소개, 프로젝트의 목표, OKJSP mysql 약간과 그리고 cubrid가 설치될 OS 체크시간을 가졌습니다.

오늘 상황에서는 워밍업단계라 많은 진도를 나가지 않았지만, OS 리팩토링(업그레이드나 기능추가에서는 어쩌면 필연적인 일)을 결정했고, 호스팅업체인 80port의 협조 덕분에 가서 업그레이드하는 일이 생성되었습니다.

뒷풀이 자리에서 많은 얘기를 나누지는 못했지만, DB 커리어에 대한 욕심이나 개발 외적인 업무와 작업들에 대해서는 모두 관심있어했습니다.

3주 예상했는데, OS 업그레이드 때문에 일이 좀 커지긴 했습니다만, 그래도 불가능할 것 같지는 않습니다.

관련 자료는 차차 공개하도록 하겠습니다.
OKJSP 사이트의 DB를 전환할 계획입니다. 현재 mysql 4.1에서 cubrid 2008 R2(예상)로 마이그레이션하는 프로젝트입니다.

진행 계획은 다음과 같습니다.



프로젝트 인원(3~4명) 선발 2weeks (~9/9까지 접수)

1차 offline모임 (9/11 금 19:00~21:00)

2차 offline모임 (9/18 금 19:00~21:00)

3차 offline모임 (9/24 목 19:00~21:00)

프로젝트 종료 (9/29 화 19:00~21:00)

모임 장소(예상): 강남 또는 신촌 토즈

모임시 회비 1만원 이상 있습니다.



보상 및 특전은 소스 커밋 권한 밖에 없습니다. okjsp 커밋터가 되는 것이죠.

프로젝트에 참여를 원하시는 분은 아래 링크를 통해서 신청해주세요.

온라인 신청

http://spreadsheets.google.com/viewform?formkey=dDRTbDhyY0szLTlPODFlZWFSNmN2MlE6MA..


선발결과는 9월 10일 공지사항 게시판에 게재됩니다.

많이 느려졌습니다.

사이트가 느려졌을 때 톰캣 매니저(/manager/html)에서 확인한 세션수입니다. 선방하고 있다고 말하기 힘든 응답시간입니다. 이번 스프링컨퍼런스에서 알게된 mysql 느린 쿼리 로그를 활성화 시켜야 할 것 같습니다.

•MySQL has a Slow Query Log
 --log-slow-queries and --log-queries-not-using-indexes
관련: http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html

^^; 살살 방문해주세요.

http://www.okjsp.pe.kr/okjsp

함부로 사이트를 닫아서 본의아니게 피해를 입으신 분들에게 죄송합니다. 첨부된 파일들은 용량 때문에 공유하기 힘들지만 DB만이라도 공개합니다. 위 링크에서 README.txt 를 참고해서 db를 이용하시기 바랍니다.

사이트는 여러 가지 이유들이 복합적으로 얽혀서 닫았습니다. 이기적인 이유도 있고, 환경적인 이유도 있습니다. 방통위에서 경고받은 개인정보 보호와 같은 보안에 대한 작업을 마치면 다시 열겠습니다.

개념글, 몰상식글, 낚시글 등에 대한 컨트롤은 제가 가능한 범위를 넘은 사이트입니다. 그 모든 책임에서 자유롭고 싶지만, 불가능하다고 결론 내렸습니다. 사람을 모았으면 모인 그 사람들에게 책임이 없다고 얘기할 수 없으니까요.

죄송합니다. 그리고 고맙습니다.

+ Recent posts