MySQL : Project(MySQL 연동) 3 – 기초

1. MySQL 시작하기

MySQL 구동 하기.

$ /etc/init.d/mysql start

 

MySQL 접속하기

$ mysql -uroot -p1234567890

-u 다음에는 접속하고자 하는 ID, -p 다음에는 접속하고자 하는 계정의 패스워드를 입력한다.

 

MySQL에서 데이터 베이스 생성하기

mysql> create database test;

생성한 데이터 베이스 확인하기

mysql> show databases;

 

MySQL에서 데이터 베이스 선택하기

mysql> use test;

use 다음에 사용하고자 하는 데이터 베이스를 입력한다.

 

선택한 데이터베이스에서 테이블 만들기

mysql> CREATE TABLE student (
-> name varchar(10),
-> korean int,
-> math int,
-> english int
-> );

student 라는 이름의 테이블을 생성하는 쿼리이다.  테이블 생성 후, Data Directory 를 확인하면, 데이터 베이스 디렉토리 속에 student라는 이름을 가진 파일들이 생성된 것을 확인할 수 있다.

root@jonathan-laptop:/var/lib/mysql/test# pwd
/var/lib/mysql/test
root@jonathan-laptop:/var/lib/mysql/test# ls -slh|grep student
rw-rw—- 1 mysql mysql    0 2011-06-30 10:59 student.MYD
rw-rw—- 1 mysql mysql 1.0K 2011-06-30 10:59 student.MYI
rw-rw—- 1 mysql mysql 8.5K 2011-06-30 10:59 student.frm

 

생성한 테이블 확인하기

mysql> show tables;
+—————-+
| Tables_in_test |
+—————-+
| address        |
| student        |
| test           |
+—————-+

 

테이블 정보 확인하기

mysql> explain student;
+———+————-+——+—–+———+——-+
| Field   | Type        | Null | Key | Default | Extra |
+———+————-+——+—–+———+——-+
| name    | varchar(10) | YES  |     | NULL    |       |
| korean  | int(11)     | YES  |     | NULL    |       |
| math    | int(11)     | YES  |     | NULL    |       |
| english | int(11)     | YES  |     | NULL    |       |
+———+————-+——+—–+———+——-+
4 rows in set (0.00 sec)

 

2. 사용자 설정

 

2-1. 사용자 암호 바꾸기

MySQL에서 사용자의 암호를 변경하는 방법은 세가지가 있다.

– UPDATE 문을 이용
– SET PASSWORD 이용
– mysqladmin 이용

2-1-1 UPDATE 문 이용하기

jonathan@jonathan-laptop:/var/lib$ mysql -uroot -p mysql

mysql> update user set password=password(‘1234’) where user = ‘root’;
Query OK, 3 rows affected (0.09 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)

-p 다음에 mysql은 mysql이란 데이터 베이스를 사용하라는 것을 의미한다. mysql 프롬프트에서 use db_name을 이용하여 사용하고자 하는 데이터베이스를 변경할 수도 있다. UPDATE 문을 이용하여 암호를 변경할 경우에는 꼭 flush privileges; 를 실행해야 한다.

이유는 MySQL은 속도를 조금이나마 빠르게 하기 위해 mysql 데이터베이스에 있는 사용자 권한에 관련딘 내용을 처음 MySQL 시작시에 메모리로 읽어 들이는데(메모리가 하드 디스크에 비해서 속도가 빠르므로 이렇게 해서 사용자 인증 부분에 속도를 향상시킬 수 있는 것이다), UPDATE문을 사용하여 암호가 바뀌었을 때는 flush privileges; 를 이용하여 사용자 관련 테이블에 변경된 내용이 있으니 다시 읽으라고 서버에 알려야 한다.

2-1-2 SET PASSWORD 이용하기

mysql> SET PASSWORD for root=password(‘1234’);

이 방법은 flush privileges; 를 할 필요가 없음. 그러나 MySQL 5.1 버전에서는 제대로 되지 않는것을 확인했음.

2-1-3 mysqladmin 이용하기

$ mysqladmin -u root password  new-password

 

2-2 새로운 사용자 등록하기

MySQL에서 새로운 사용자를 추가하는 방법은 GRANT를 이용하는 방법과 직접 mysql의 user 테이블에 INSERT 하는 방법 두가지가 있다.

2-2-1 GRANT문 이용

mysql> grant all privileges on *.* to pchero@localhost identified by ‘1234’ with grant option;
Query OK, 0 rows affected (0.04 sec)

localhost의 pchero에게 (to pchero@localhost) 1234라는 암호로(identified by ‘1234’) MySQL의 모든 데이터베이스에 있는 모든 테이블에(on *.*) 모든 권한 (all privileges)을 부여하는 것을 의미한다.

위의 쿼리문은 모든 데이터베이스를 사용할 수 있도록 하는 쿼리인데, 이를 특정 데이터베이스에 한정하기 위해서는 다음의 쿼리문을 사용하도록 한다.

mysql> grant all privileges on test.* to pchero@localhost identified by ‘1234’;

위의 쿼리문은 localhost의 pchero에게 test 데이터베이스의 모든 테이블에 모든 권한을 부여하는 것을 나타낸다. 특정 데이터베이스에 특정 권한만을 부여하기 위해서는 다음의 쿼리문을 수행한다.

mysql> grant select, insert on test.* to pchero@localhost identified by ‘1234’;

이 외에도 특정 테이블이나 특정 컬럼에만 권한을 주는 방법도 있다.

2-2-2 INSERT문 이용하기

insert into user values(‘localhost’, ‘pchero’, password(‘1234’), ‘N’, ‘N’, ‘N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’);

 

 

 

MySQL : Project(MySQL 연동) 2 – 환경 구성

 

1.  MySQL 설치

작업의 대부분은 Ubuntu – 10.04 버전에서 진행하였다.

Ubuntu Linux의 경우 MySQL 은 기본적으로 설치가 되어있으나, 다른 Linux 배포판의 경우, 설치가 안되어 있거나 따로 설치를 해야할 경우가 있다.

이럴 경우, 대부분의 최신의 배포판들은 다음의 명령어를 사용하여 간단하게 설치를 진행할 수 있다.

apt-get 을 이용할 경우

# apt-get install mysql

yum 을 이용할 경우

# yum install mysql

이번 프로젝트에서 사용한 MySQL의 버전은 5.1.41 버전이다.

MySQL 버전 확인하기

# mysql –version

 

2. MySQL Options

ubuntu 환경에서 apt-get 으로 MySQL을 설치 했을 경우, 기본적으로 설정되는 database directory는 다음과 같다.

/var/lib/mysql

만약 위의 디렉토리에 존재하지 않는다면, /etc/mysql/my.cnf 파일을 통해서 database directory 의 위치를 확인할 수 있다.

아래는 필자의 my.cnf 파일의 내용이다.

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# – “/etc/mysql/my.cnf” to set global options,
# – “~/.my.cnf” to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with –help to get a list of available options and with
# –print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain “#” chars…
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port        = 3306
socket        = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket        = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
#
# * Basic Settings
#

#
# * IMPORTANT
#   If you make changes to these settings and your system uses apparmor, you may
#   also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#

user        = mysql
socket        = /var/run/mysqld/mysqld.sock
port        = 3306
basedir        = /usr
datadir        = /var/lib/mysql
tmpdir        = /tmp
skip-external-locking
#
# 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
#
# * Fine Tuning
#
key_buffer        = 16M
max_allowed_packet    = 16M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit    = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1

log_error                = /var/log/mysql/error.log

# Here you can see queries with especially long duration
#log_slow_queries    = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id        = 1
#log_bin            = /var/log/mysql/mysql-bin.log
expire_logs_days    = 10
max_binlog_size         = 100M
#binlog_do_db        = include_database_name
#binlog_ignore_db    = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI “tinyca”.
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

[mysqldump]
quick
quote-names
max_allowed_packet    = 16M

[mysql]
#no-auto-rehash    # faster start of mysql but no tab completition

[isamchk]
key_buffer        = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with ‘.cnf’, otherwise they’ll be ignored.
#
!includedir /etc/mysql/conf.d/

각각의 옵션들의 정확한 의미와 사용법을 알고 싶다면 아래의 링크를 참조한다.

http://dev.mysql.com/doc/refman/5.1/en/program-options.html

Installing tora with Oracle support in the Ubuntu 10.04

 우분투에서 Tora를 설치란 간단한 일이다.

 하지만 Tora에 Oracle 접속기를 덧붙이기란 그리 쉽지 않다.

 Tora에 오라클 접속기를 덧붙여서 설치하기는 아래의 링크를 참조하기 바란다.

 https://help.ubuntu.com/community/HowToBuildToraWithOracle

 필자도 어느정도는 맞아떨어졌으나, 설치도중 역시나 이상한 에러가 발생하였다.

dpkg-shlibdeps: error: no dependency information found for /oracle/11g/lib/libclntsh.so.11.1 (used by debian/tora/usr/bin/tora).
dh_shlibdeps: dpkg-shlibdeps -Tdebian/tora.substvars debian/tora/usr/bin/tora returned exit code 2
make: *** [binary-predeb-IMPL/tora] 오류 9

 이게 무슨 에러일까..
 에러의 내용은 dh_shlibdeps 를 실행하던 도중, libclntsh.so.11.1의 의존성 정보를 찾을 수 없었다…라는 내용인데, 아마도 dh_shlibdpes 프로세스가 하는 일은 설치된 라이브러리의 의존성 정보를 파악하여 패키지를 만드는데 그 정보를 포함시키는 역할을 하는 프로세스 같았다.

 하지만 문제는 libclntsh.so.11.1 라이브러리…

 왜냐하면 오라클 11g 버전 설치시, XE 패키지로 설치한 것이 아니라, 수동으로 직접 설치했기 때문에 발생하는 문제같았다.

 패키지로 설치하지 않았으니, 당연히 lib 의존성 정보가 없는 것이고, 그로 인해 발생되는 문제 같았다.(어디까지나 추측)

 해결법을 찾아 보던 중 다음의 글을 찾을 수 있었다.

http://ubuntuforums.org/showthread.php?t=753877

하지만.. 위 글에서 이야기하는 방법은 이상하게 tora-2.1.1 버전에서는 되지 않는 듯 했다. 이리저리 debian/rules 파일을 고쳐보고 몇번씩 실행해 보았지만… 이상했다.

 그래서 다시 다른 방법을 찾아 보던 중 아래의 글을 찾을 수 있었다.

http://www.pythian.com/news/4747/installing-tora-with-oracle-support-on-ubuntu-9-10-karmic-koala/

 글 본문이 아닌 댓글에서 해답을 찾을 수 있었다.

 내용의 요지는

 /etc/dpkg/shlibs.override

 파일에 의존성 검사에 걸리는 라이브러리의 내용을 넣는 것이었다.

 아마도 저 파일의 역할이 의존성 검사 예의 내용을 입력하는 파일 같았다.

 필자의 경우, libclntsh 11.1 라이브러리에 이어 libocci 11.1 라이브러리의 의존성 에러도 발생하여서 이 두가지 사항에 대한 내용을 파일에 추가하였더니 아무 무리없이 패키지 파일을 만들 수 있었다.

/etc/dpkg/shlibs.override 파일내용

# dpkg shlibs override file
#
# Entries in this file will override all others, only use if you
# are really sure that is what you want!
#
# For more information see the dpkg-shlibdeps(1) manual page.
#
# <library name>        <version/soname>        <dependencies>
libclntsh 11.1
libocci 11.1

SYBASE 사용자 추가하기

 SYBASE 에서의 사용자 추가 방법

sp_addlogin ‘아이디’,’패스워드’

 

 

 sp_adduser ‘아이디’

 sp_dropuser ‘아이디’

 

 

 % isql -Usa -Ppassword -Sservername
1> use master
2> go
1> sp_addlogin scott, tiger, test
2> go
1> use test
2> go
1> sp_adduser scott
2> go

 

 

 

 

exec  sp_addlogin  ‘homeusr’, ‘password’, @defdb=’ebaihome’, @auth_mech = ‘ASE’
exec sp_locklogin  ‘homeusr’, ‘unlock’

 go

 

use ebaihome
go

exec sp_adduser ‘homeusr’ ,’homeusr’ ,’public’
go 

——————————————————————————————————————————————————
출처 : http://benelog.springnote.com/pages/349014