Category
show
전체 (733)
웹표준, 웹접근성™ (5)
웹프로그래밍™ (343)
웹기획™ (0)
웹디자인™ (5)
서버™ (27)
데이터베이스™ (42)
개발자료 (9)
트랜드 (60)
Study English (2)
블루비 (62)
오피스 다이어리 (19)
Textcube (2)
이슈 (20)
컴퓨터 악세사리 (18)
엔터테인먼트 (24)
좋은글 (62)
재테크 (1)
이벤트 (4)
1 2 

MySQL my.conf 설정 character set

데이터베이스™/MySQL 2008/08/07 16:51 by 블루비 Total 260 : Today 1 : Yesterday 11

우분투 서버의 경우 mysql 원격 접속을 하기 위해서
/etc/mysql/my.cnf 파일의 bind-address 부분은 주석처리해준다

#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#


우분투를 설치시 mysql character set 은 latin1 으로 되어 있기 때문에 my.cnf 파일에

다음 항목을 추가 하거나 수정해준다. 빨간 부분은 추가된 부분, 파란색 부분은 수정한 부분

----------------------------------------------------------
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
default-character-set = euckr

[mysqld]
language = /usr/share/mysql/korean

character-set-client-handshake=FALSE
init_connect="SET collation_connection = euckr_korean_ci"
init_connect="SET NAMES euckr"

default-character-set = euckr
character-set-server = euckr
collation-server = euckr_korean_ci

[mysqldump]
default-character-set = euckr

[mysql]
default-character-set = euckr
-----------------------------------------------







2008/08/07 16:51 2008/08/07 16:51

TRACKBACK :: http://blueb.net/blog/trackback/1271

[MySQL] 데이터베이스, 테이블 Character 변경

데이터베이스™/MySQL 2008/03/18 10:12 by 블루비 Total 644 : Today 1 : Yesterday 2
데이터 베이스와 테이블의 Character set 이 맞지 않는 경우에도 한글이 깨짐 현상이 일어 나는데,
이문제를 위해서 데이터 베이스와 테이블의 Character set 동일하게 세트해줘야 합니다.










데이터베이스 Character 변경
mysql> ALTER DATABASE [Database] DEFAULT CHARACTER SET utf8;

테이블 Character 변경

mysql> ALTER TABLE [Table] DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;





2008/03/18 10:12 2008/03/18 10:12

TRACKBACK :: http://blueb.net/blog/trackback/1171

[MySQL] root 비밀번호 분실시 해결법

데이터베이스™/MySQL 2008/02/29 12:01 by 블루비 Total 665 : Today 0 : Yesterday 3
MySQL root 비밀번호 분실시 권한 없이 MySQlL 에 접속하여 새로운 비번을 부여후 다시 MySQL을 가동하면 해결됩니다.

# cd /usr/local/mysql/bin //mysql이 설치된 디렉토리의 bin
# killall mysqld
# ./safe_mysqld --skip-grant &
# mysql
mysql> use mysql;
mysql> update user set password=PASSWORD('패스워드') where user='root';
mysql> flush privileges;
mysql> quit;
# killall mysqld
# ./safe_mysqld -uroot &

2008/02/29 12:01 2008/02/29 12:01

TRACKBACK :: http://blueb.net/blog/trackback/1140

썬(sun.com), MySQL 인수

데이터베이스™/MySQL 2008/02/28 13:27 by 블루비 Total 509 : Today 0 : Yesterday 2
썬(sun.com) 인 MySQL을 인수 했다는 기사가 나왔군요.
갑작스런 소식인지라 향후 MySQL 행보가 어떨지.

오는 28일 http://www.sun.com/MySQL/download 에서
다운로드 서비스를 받을 수 있다고 합니다.

http://mysql.com
사이트에 들어가 보니 역시 로고가 바뀌었군요.. ㅎㅎ

사용자 삽입 이미지




2008/02/28 13:27 2008/02/28 13:27

TRACKBACK :: http://blueb.net/blog/trackback/1135

  1. sun의 mysql인수완료, MySQL.com 로고변경

    : PHP와 Web 2.0 2008/02/28 15:09 삭제하기

    Mysql 사이트가 살포시 변경되고 Sun.com 에도 new product로 mysql에추가되었습니다.http://www.sun.com/software/products/mysql/index.jspJohannes Schlüter(Johannes Schluter) 블로그에도 Mysql의 인수가 모두 종료되고 이제 Sun의 일부임이 발표되어있군요. (링크)기존신규여러가지로 긍정적인 변화만 있으면 좋겠네요...크리에이티브 커먼즈 라이센스이 저작물은 크리...

MySQL Data Type 정리

데이터베이스™/MySQL 2008/01/31 20:04 by 블루비 Total 1000 : Today 1 : Yesterday 1

Integer Type

- TINYINT 128부터 127 까지의 정수형 타입, 부호가 없는 정수 0∼255까지 지원
- SMALLINT 32768부터 32767 까지의 정수형 타입, 부호가 없는 정수 0∼65535까지 지원
- MEDIUMINT 8388608부터 8388607 까지의 정수형 타입, 부호가 없는 정수 0∼16777215까지 지원
- INT 또는 INTEGER -2147483648부터 2147483647까지의 정수형 타입,
부호 없는 정수 0∼4294967295까지 지원
- BIGINT 9223372036854775808 부터 9223372036854775807 까지의 정수형 타입
부호 없는 정수 0∼18446744073709551615까지 지원
- FLOAT(M,D) 단정도 부동 소수점 실수, -3.402823466E+38 ∼ -1.175494351E-38
그리고 1.175494351E-38 ~ 3.402823466E+38까지 M은 숫자 전체의 길이, D는 소수점 자리수를 의미
- DOUBLE(M,D) 2 배 정밀도를 가진 부동 소수점 실수, -1.79769313486231517E+308 ∼ 2.22507385850720E+308


Stirng Type

-CHAR(m) 0~255까지 입력이 가능하며, 길이가 m길이만큼 고정 사이즈가 된다.
-
VARCHAR (m)0~255까지 입력은 가능하지만, 길이는 고정이 아닌 가변 사이즈이다.
-
BINARY(m) 이진 데이터를 바이트 지정한 만큼 고정 길이
-
VARBINARY(m) 이전 데이터를 바이트 지정한 만큼 넣는다. 가벼 길이
-TINYBLOB 이전 데이터를 최대 255자까지 입력이 가능하다
-
BLOB 최대 길이가 63535인 문자를 저장
-
TEXT 최대 길이가 63535인 문자를 저장
-MEDIUMBLOB 최대 길이가 16777215인 문자를 저장
-LONGBLOB 최대 입력이 4G 이진데이타, 최대 2^32 바이트
-
LONGTEXT 최대 입력이 4G 1바이트 문자열, 최대 2^32 자

/* Point */
- BLOB타입은 대소문자를 구분하고 TEXT타입은 대소문자를 구분하지 않는점이 틀림
- MySQL 3.23.2이번 버전에서는 BLOB와 TEXT컬럼에는 인덱스를 만들수 없다
- BLOB와 TEXT컬럼의 저장시에 문자열 됫부분의 공백이 제거되지 않는다.
- BLOB와 TEXT컬럼은 DEFAULT를 지정할 수 없다.


Data Type

-DATE 날짜를 표현하는 유형 [YYYY-MM-DD], 1000-01-01 ∼ 9999-12-31까지 나타낼 수 있다
-DATETIME 날짜와 시간을 표현하는 유형 [YYYY-MM-DD HH:MM:SS], 1000-01-01 00:00:00 ∼ 9999-12-31 23:59:59
-TIMESTAMP 자동변경 컬럼 타입(4 Byte ), 1970-01-01 00:00:00부터 2037년 까지 표현
-TIME 시간을 표현하는 유형 [HH:MM:SS], 839:59:59 ∼ 833:59:59 까지 표현
-
YEAR 년도를 표현하는 유형[기본적으로 4자리로 사용], 1901년 ∼ 2155년


2008/01/31 20:04 2008/01/31 20:04

TRACKBACK :: http://blueb.net/blog/trackback/1083

How to simulate FULL OUTER JOIN in MySQL

데이터베이스™/MySQL 2008/01/31 15:46 by 블루비 Total 712 : Today 3 : Yesterday 4

출처 : http://www.xaprb.com/blog/2006/05/26/how-to-write-full-outer-join-in-mysql/

In this article I’ll show several ways to emulate a FULL OUTER join on a RDBMS that doesn’t support it, as is the case with even the most recent versions of MySQL. This useful query is surprisingly tricky to get right.

Introduction

A standard SQL FULL OUTER join is like a LEFT or RIGHT join, except that it includes all rows from both tables, matching them where possible and filling in with NULLs where there is no match. I’ll illustrate that for clarity. Here are two of my favorite tables, apples and oranges:

I’ll join them on price. Here is the left join:

select * from apples as a
left outer join oranges as o on a.price = o.price

And the right join:

select * from apples as a
right outer join oranges as o on a.price = o.price

The FULL OUTER JOIN of these two tables, on price, should give the following result:

That’s the result I’ll be working toward in this article. Here is a script to create and populate the example tables, so you can follow along:

create table apples (variety char(10) not null primary key, price int not null);
create table oranges (variety char(10) not null primary key, price int not null);
insert into apples(variety, price) values('Fuji',5),('Gala',6);
insert into oranges(variety, price) values('Valencia',4),('Navel',5);

Method 1: two JOINs and a UNION

One method to simulate a full join is to take the union of two outer joins, for example,

select * from apples as a
left outer join oranges as o on a.price = o.price
union
select * from apples as a
right outer join oranges as o on a.price = o.price

This gives the desired results in this case, but it isn’t correct for all cases. Suppose there are duplicate records in the tables (remove the primary key and insert twice to create this situation). UNION eliminates duplicates, which a full join doesn’t do. UNION ALL isn’t the right answer either, because it will cause spurious duplicates. In fact, UNION generates two independent result sets and then combines them, so there is no way to get around this, because the two result sets need to “know about each other” to produce the right results.

There are legitimate cases where duplicate results are expected and correct. For instance, even when the rows are unique, selecting only certain columns, in which there are duplicates, could cause this situation. This doesn’t apply in relational theory, because a set never has duplicates no matter what, but it does in SQL.

Method 2: UNION ALL and an exclusion join

One way to make UNION include only the duplicates I want is to use an exclusion join to eliminate anything from the second result that is already included in the first, like this:

select * from apples as a
left outer join oranges as o on a.price = o.price
union all
select * from apples as a
right outer join oranges as o on a.price = o.price
where a.price is null;

This handles duplicate rows correctly and doesn’t include anything it shouldn’t. It’s necessary to use UNION ALL instead of plain UNION, which would eliminate the duplicates I want to keep. This may be significantly more efficient on large result sets, since there’s no need to sort and remove duplicates.

Method 3: use a mutex table

There’s a case where UNION won’t work: older versions of MySQL don’t support it. All is not lost, though.

I’ve written several articles explaining how to start with a set of mutually exclusive numbers (which I informally call a “mutex table“), then use the mutual exclusivity of the numbers to join things together in interesting ways. This lets me simulate subqueries and unions on earlier versions of MySQL, for example. This approach seems like it might work well here, too. For the following queries I’ll assume my mutex table has the values 0 and 1. Here’s a baseline mutex query for these two tables:

select * from mutex
left outer join apples as a on i = 0
left outer join oranges as o on i = 1;

Of course this isn’t a full join. If I want to full join on price, naturally, I need to include price in the join criteria somewhere, and the query above doesn’t even mention the price. But it’s a starting point for tinkering.

The mutex values in the leftmost column, combined with the join criteria, ensure that every row in the two tables gets included on its own row. The mutual exclusivity causes the Navel row not to be matched to the Fuji row, even though they have the same price. The correct behavior of a full join on price is to “fill in” the NULL values where the prices are equal. This modification to the join criteria will fill it in:

select * from mutex
left outer join apples as a on i = 0
left outer join oranges as o on i = 1 or a.price = o.price;

The or a.price = o.price relaxes the mutual exclusivity, telling the join to keep the rows separated unless they have the same price:

That’s getting closer. There is a spurious row, though. The Navel row at the bottom of the result set shouldn’t be there; it has already been matched to the Fuji row earlier, so there’s no need to include it with all those NULLs as though there were no matching row in apples. Can I eliminate the Navel row without eliminating the Valencia row?

That turns out to be harder to do. I stared at it for a while, thinking I could include a WHERE clause that would eliminate spurious rows based on the value of i, but after a bit I got a reality check: the row has already been included above, and WHERE clauses work a row at a time, so there’s no way to assert something about one row while applying the WHERE clause to another row. This simple fact is all I needed to realize there’s no way to eliminate the Navel row with the given information.

What I can do, though, is stack another copy of the apples table onto the right-hand side of the results thus far, matching them to the oranges values and confining them to rows with mutex value 1 instead of 0. Now I can write a WHERE clause to see if a row in the i = 1 part of the result set matches a row in the i = 0 part. I’ll write it without the WHERE clause to start:

select * from mutex
left outer join apples as a on i = 0
left outer join oranges as o on i = 1 or a.price = o.price
left outer join apples as a2 on i = 1 and a2.price = o.price;

Now there is a way to tell between the Navel row, which I don’t want, and the Valencia, which I do: the Navel has non-NULL values in the rightmost copy of apples, but the Valencia doesn’t. All I have to do is eliminate rows that have matching values:

select * from mutex
left outer join apples as a on i = 0
left outer join oranges as o on i = 1 or a.price = o.price
left outer join apples as a2 on i = 1 and a2.price = o.price
where o.price is null or a2.price is null

If the WHERE clause is hard to understand, perhaps it’s easier to think of it this way: where not(o.price is not null and a2.price is not null). Both clauses are identical; all I did was apply some boolean identities. Here is the result:

That result has the correct rows, but it has some extra columns, which I don’t need. Here’s the final query:

select a.*, o.* from mutex
left outer join apples as a on i = 0
left outer join oranges as o on i = 1 or a.price = o.price
left outer join apples as a2 on i = 1 and a2.price = o.price
where o.price is null or a2.price is null

Remember, this can’t be done without the mutex table, because I need something to provide non-NULL values for every row; otherwise the joins would not include values where the leftmost table has no rows to contribute.

This technique works if there are duplicate rows, and works on older versions of MySQL, but is probably the least efficient of the three I’ve demonstrated here. As usual, which query is appropriate depends on circumstances.

2008/01/31 15:46 2008/01/31 15:46

TRACKBACK :: http://blueb.net/blog/trackback/1081

grant 문을 통한 mysql 사용자 추가

데이터베이스™/MySQL 2007/12/12 16:38 by 블루비 Total 854 : Today 0 : Yesterday 6
//추가
mysql>grant select, insert, delete, update, create, drop, alter on 테이타베이스명.* to 사용자아이디@localhost identified by '비밀번호';

//적용
mysql>flush privileges;



//루트 권한 부여
grant all privileges on *.* to 사용자아이디@localhost identified by '비밀번호' with grant option;
2007/12/12 16:38 2007/12/12 16:38
TAG ,

TRACKBACK :: http://blueb.net/blog/trackback/279

mysql character 확인

데이터베이스™/MySQL 2007/12/12 15:38 by 블루비 Total 539 : Today 1 : Yesterday 1
mysql> show variables like 'c%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | euckr                      |
| character_set_connection | euckr                      |
| character_set_database   | euckr                      |
| character_set_results    | euckr                      |
| character_set_server     | euckr                      |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
| collation_connection     | euckr_korean_ci            |
| collation_database       | euckr_korean_ci            |
| collation_server         | euckr_korean_ci            |
| concurrent_insert        | ON                         |
| connect_timeout          | 5                          |
+--------------------------+----------------------------+
2007/12/12 15:38 2007/12/12 15:38

TRACKBACK :: http://blueb.net/blog/trackback/992

[MySql] MERGE tables (2개 테이블 병합 테이블 만들기)

데이터베이스™/MySQL 2007/10/05 02:10 by 블루비 Total 546 : Today 1 : Yesterday 1
mysql> CREATE TABLE t1 (
->a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> message CHAR(20)) ENGINE=MyISAM;
mysql> CREATE TABLE t2 (
-> a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> message CHAR(20)) ENGINE=MyISAM;
mysql> INSERT INTO t1 (message) VALUES ('Testing'),('table'),('t1');
mysql> INSERT INTO t2 (message) VALUES ('Testing'),('table'),('t2');
mysql> CREATE TABLE total (
-> a INT NOT NULL AUTO_INCREMENT,
-> message CHAR(20), INDEX(a))
-> ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;

t1, t2 테이블의 데이터를 total 테이블에 병합된 데이터로 insert 하게 된다.

NSERT_METHOD는
total 테이블에 다이렉트로 INSERT할경우 UNION에
정의한 테이블중 어느 테이블에 INSERT를 할건지 정의하는것이다.(FISRT or LAST)


※ 주의할점은 두 테이블의 레코드 형식 및 타입까