localhost 에서 접속 시도 하는 경우 발생 하는 에러 이다. socket 설정을 해줘야 한다.


Step 1.  mysql 설정 파일 변경 하기

/etc/my.cnf 파일에 추가 한다.


[client]

port    = 3306

socket  = /var/lib/mysql/mysql.sock


[mysqld]

port    = 3306

socket  = /var/lib/mysql/mysql.sock


Step 2.  mysql 재시작 하기

서버를 재시작 한다.


sudo service mysqld restart

Shutting down MySQL.. SUCCESS! 

Starting MySQL. SUCCESS! 


Step 3.  접속 확인 하기

mysql -u[username] -p[password] [database]

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 1

Server version: 5.6.12 Source distribution


Copyright (c) 2000, 2013, 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>


접속을 확인 할 수 있다.



Step 1.  Database 확인 하기


SELECT datname FROM pg_database;


Step 2.  Table name 확인 하기


SELECT table_name FROM information_schema.tables WHERE table_schema = 'schema name';


Step 3.  Column name 확인 하기


SELECT column_name FROM information_schema.columns WHERE table_name = 'table name';


Query 로 정보 확인이 가능 합니다.



coalesce(value, null 일 경우 value)



coalesce(value1, value2)



DB 에서 체크가 필요한 경우 유용하다.



Step 1.  설치 파일 다운 받기

http://www.postgresql.org/download/macosx/ 경로로 이동 하여 download 한다.

Step 2.  Shared Memory 설정 하기

실행 한 후 README 문서를 참고 한다.



% sudo vi /etc/sysctl.conf


On a MacBook Pro with 2GB of RAM, the author's sysctl.conf contains:


kern.sysv.shmmax=1610612736

kern.sysv.shmall=393216

kern.sysv.shmmin=1

kern.sysv.shmmni=32

kern.sysv.shmseg=8

kern.maxprocperuid=512

kern.maxproc=2048



아래와 같이 수정 한 후 재부팅을 한다.


Step 3.  설치 파일 실행 하기

Next 를 따라가다 보면 완료가 된다.




 

dump 복구

 

 

psql -U user -d db < dump.sql

 

 

해당 db에 dump 파일이 복구 된다.

 


아래의 Query를 보도록 하자.



show procedure status where db = 'db_test'



db명을 입력 하면 해당 procedure의 상태를 볼 수 있다.


'Database' 카테고리의 다른 글

OSX 에 PostgreSql 설치 하기  (1) 2013.03.02
PostgreSql dump 복구 하기  (0) 2013.03.01
Mysql procedure 에서 select, insert 하기 (into)  (0) 2012.12.13
Mysql procedure 사용하기  (0) 2012.12.12
Mysql 변수 사용하기  (0) 2012.12.11


아래의 샘플을 보도록 하자.



delimiter $$

drop procedure if exists test_procedure $$

create procedure test_procedure(p_test varchar(100), p_test_a varchar(10))
begin


-- 선언 부

declare v_test1 int default 0;

declare v_test2 int default 0;


-- 조회

select

test1,

test2

into v_test1, v_test2

from

tb_test;


-- 등록

insert tb_proc_test (test) values (v_test1);

insert tb_proc_test (test) values (v_test2);


end $$

delimiter;




조회 하는 부분을 보면 into 구문을 볼 수있다. 여러개의 값을 변수에 넣으려면 제일 하단부에 순서대로 나열 한다.

변수에 값이 들어 가는 것을 insert 구문을 통해서 확인 할 수 있다.


'Database' 카테고리의 다른 글

PostgreSql dump 복구 하기  (0) 2013.03.01
Mysql procedure 상태 확인하기  (0) 2012.12.13
Mysql procedure 사용하기  (0) 2012.12.12
Mysql 변수 사용하기  (0) 2012.12.11
Mysql sec_to_time 숫자를 시간으로 바꾸기  (0) 2012.12.11


Mysql procedure 기본 형태 이다.



delimiter $$

drop procedure if exists test_procedure $$

create procedure test_procedure(p_test varchar(100), p_test_a varchar(10))
begin

// process

end $$

delimiter;



실행은 아래와 같은 방법을 이용 한다.



call test_procedure('a', 'b');



+ Recent posts