'DataBase'에 해당되는 글 26건

  1. 2008.01.15 2개의 날짜차이 구하기
  2. 2007.12.13 [error code] ERROR 1114 (HY000)
  3. 2007.12.13 alter / 테이블 변경
  4. 2007.12.13 left outer join
  5. 2007.11.20 create database 와 연계된 작업
  6. 2007.11.19 mysql table스키마 보기 2
  7. 2007.02.22 [mysql] mysql backup 방법 2
  8. 2007.02.12 [Xquery] ~=’test*’ 구문처리 1
  9. 2007.02.12 [Xquery] and ,or 혼용
  10. 2007.02.12 [Xquery] or 검색
select itemid from test where  markcnt <=0 and (TO_DAYS(now())-TO_DAYS(last_modified_time)) > 10



현재시간에서 입력되어있는 시간의 day단위 시간차를 구해옵니다.
10일 이상인것만 가져오는 Query 입니다.
mysql> alter table test000 add markcnt int(10) NOT NULL default 0;
ERROR 1114 (HY000): 테이블 '#sql-6f80_940d2'가 full났습니다.


mysql>
mysql>
mysql> show table status from rssdb like 'item'\G;
*************************** 1. row ***************************
           Name: test000
         Engine: InnoDB
        Version: 9
     Row_format: Dynamic
           Rows: 179
 Avg_row_length: 8786
    Data_length: 1572864
Max_data_length: NULL
   Index_length: 49152
      Data_free: 0
 Auto_increment: 139
    Create_time: 2007-11-26 14:47:52
    Update_time: NULL
     Check_time: NULL
      Collation: latin1_swedish_ci
       Checksum: NULL
 Create_options:
        Comment: InnoDB free: 4096 kB
1 row in set (0.00 sec)


조회된 결과에서
max_rows Column과 avg_row_length Column값을 변경하면 됩니다.
[Syntax]
alter table table명 max_rows=레코드수 avg_row_length=원하는테이블용량
[예제]
레코드수-1천만건, 원하는테이블용량-6GB일 경우
alter table seoul max_rows=10000000 avg_row_length=6024000000;

*테이블 속성변경*
alter table [해당테이블명] change [해당필드] [바꿀필드명] [변경할필드속성];
예) 테이블의 속성만을 바꿔보자 varchar(50)으로
- alter table test000 change test test varchar(50);

예) 테이블의 필드명과 필드속성을 변경해보자 (필드명=age 속성=int)
- alter table test000 change test age int;


*테이블 필드 추가*

alter table [해당테이블명] add [추가할필드명] [필드속성];
예) 테이블에 name필드를 추가하다 속성은 varchar(20);
- alter table test000 add name varchar(20);


*필드 삭제*

alter table [해당테이블명] drop [삭제할필드명];
예) name 필드를 삭제해 보자
- alter table test000 drop name;

left outer join

DataBase/mysql 2007. 12. 13. 10:44
  SELECT a.fldid, a.userid, a.name, ifnull(b.count, 0) as count
 FROM test001 a left outer join
  (select fldid,  count(fldid) as count, userid from test002 where  userid='neouser'  group by fldid) b
 on a.fldid = b.fldid and a.userid=b.userid
 where a.userid='neouser'

위 쿼리의 결과는 아래와 같이 나온다.
쉽게 볼 것같지만 이것을 내가 따로 다루는 이유는 a.userid='neouser' 를
on에 두는지 where에 두는지가 차이가 많이 난다.

만일 a.userid='neouser'를 on절에 두게 되면 둘다 모두 count는 3,3 이 나온다.
이것가지고 1시간여를 시간을 보낸터라 기록에 남긴다.

+-------+--------+------------------+-------+
| fldid | userid | name             | count |
+-------+--------+------------------+-------+
|     6 | neouser   | test             |     3 |
|  1040 | neouser   | test2          |     0 |
+-------+--------+------------------+-------+


●  Database 생성

CREATE DATABASE testdb;


●  USER추가

insert into user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv)
 values ('**.**.**.**', 'testuser', password('testpwd'), 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N');

insert into user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv)
 values ('%', 'testuser', password('testpwd'), 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N');




● DB추가

insert into db (Host, Db, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Create_tmp_table_priv, Lock_tables_priv)
 values ('**.**.**.**', 'testdb', 'testuser', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'N', 'Y', 'Y', 'Y', 'Y', 'Y');

insert into db (Host, Db, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Create_tmp_table_priv, Lock_tables_priv)
 values ('localhost', 'testdb', 'testuser', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'N', 'Y', 'Y', 'Y', 'Y', 'Y');



FLUSH PRIVILEGES;

mysql> show create table TABLENAME;


찾으려 들면 꼭 애를 먹어요..

1. 우선 backup을 수행해도 되는지 확인을 해보도록 합니다.
    > 만일 DB가 InnoDB 방식이라면 아래와 같은 명령어가 통한답니다.
      mysql>show table status

    > 만일 InnoDB 가 아니라면...
      [neouser@neouserdb-1 data]$ du --max-depth=1


2. 검토해본 결과 별다른 무리가 없다면 mysql을 backup을 받습니다.
  저에 경우에는  backup후 개발 장비에 데이터를 모두 뿌려넣고 싶었기 때문에 dump를 뜨도록 했습니다.

  > BACKUP
   데이터베이스명 : neouserdb
   생성할 sql파일명 : neouserdb.sql
   shell>$ mysqldump -uroot -p neouserdb > neouserdb.sql

  > RESTORE
   데이터베이스명 : neouserdb2
   생성할 sql파일명 : neouserdb.sql
     ※ 선행작업으로 데이터베이스는 만들어 놓으셔야 합니다.
   shell>$ mysql -uroot -p neouserdb2 < neouserdb.sql


3. 추가!!
 뭐든 뭔가 또다른 방법이 있기 마련이죠.
 mysql> load data local infile 'data.txt' into table table_name;
 shell>$
mysql -e "source /path-to-backup/backup-file.sql" db_name

이런것도 역시 찾으려 들면 검색엔진들은 뭐이리 쓰레기 데이터만 토해내는지..



[query]/goods/metadata[(sellDate/fromDate <='19990706' or sellDate/toDate >='19990706') type~=’111*’]

sellDate/fromDate <='19990706' or sellDate/toDate >='19990706'로 검색된 결과에서 type 301을 포함한 모든 문자열을 검색해 준다.

혼용문 type ~=’301*’ 은 type이 문자열 301을 시작하는 모든것을 검색하는 조건에 해당한다.

[query] /goods/metadata[(sellDate/fromDate <='19990706' or sellDate/toDate >='19990706') type=’301’]


sellDate/fromDate <='19990706' or sellDate/toDate >='19990706'로 검색된 결과에서 type 301인것만 검색해준다.

혼용에 부분에서는 or절은 “( )”로 둘려쌓여있고 and절은 밖에 있음을 볼 수 있다.
[query] /goods/metadata[sellDate/fromDate <='19990706' or sellDate/toDate >='19990706']


sellDate/fromDate <='19990706' or sellDate/toDate >='19990706'로 검색된 결과를 보여준다.

sellDate/fromDate <='19990706' 는 크거나 같다라는 조건절을 만들어 준다.
해당 구문절은 or 라는 join기호를 사용하게 되고 이로써
1999년07월06일의 fromDate와 toDate일 경우를 모든 데이터가 검색이 된다.
1 2 3 

글 보관함

카운터

Total : / Today : / Yesterday :
get rsstistory!