MySQL. Most popular OpenSource RelationalDatabase Management system
예전에 NASA에서 그네들의 DB시스템을 Oracle에서 MySql로 바꾸었단 얘기가 있다. 10만레코드(맞나?)이하의 데이터에서 가장 빠른 속도를 낸다고 함
ApmModPythonInstallInLinux페이지에 가면, 기본적인 설치방법들이 소개되어 있다. Python으로 연동하여 쓸려면, MySQLdb모듈을 추가로 설치해야 한다. 일반적으로 3306 포트를 사용한다.
Contents
관련기사 및 정보
관련포스트
오픈소스를 장려하는 정부정책에 대한 기대가 있으며 초기에는 공공 프로젝트에 도입이 예상된다”며 “특히 공공기관은 DBMS 도입에 있어 컨설팅이나 서비스가 필요하기 때문에 책임소재가 명확해야 하는데 LDS라는 책임자가 생겼기 때문에 가능성이 있다”고 설명했다. -- MySQL의 습격「MS, 오라클 게 섯거라!」 |
New functions
mysql 5.0 version 이 나와있다. 변경 사항
Views, StoredProcedures, Cursors 기능 추가
- BIT type 추가
- VARCHAR 형이 65,632 byte 까지 지원하도록 변경.
기본 설치
shell> groupadd mysql shell> useradd -g mysql mysql shell> cd /usr/local shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf - shell> ln -s full-path-to-mysql-VERSION-OS mysql shell> cd mysql shell> scripts/mysql_install_db --user=mysql shell> chown -R root . shell> chown -R mysql data shell> chgrp -R mysql . shell> bin/mysqld_safe --user=mysql &
사용자 추가 방법
명령어를 이용해서 추가 하기
localhost 에서 사용할 수 있는 사용자 추가
mysql> GRANT ALL PRIVILEGES on dbname.* to 'ID'@localhost identified by 'PASSWORD';
외부에서 사용할 수 있는 사용자 추가
mysql> GRANT ALL PRIVILEGES on dbname.* to 'ID'@'%' identified by 'PASSWORD';
Table에 직접 넣기
- 1. root 권한으로 mysql을 실행한다.
- 2. use mysql;
- 3. update user set host='%' where user = 'destine'; ( 원래 host는 localhost로 되어 있을텐데 어느 곳에서나 접속 할 수 있게 %로 바꿔준다. )
- 4. update db set host='%' where user = 'destine'; ( 위와 마찬가지 )
- 5. flush privileges;
기본 명령어들
- show databases
- show tables
- show index from [table name]
- describe tablename
사용 팁
테이블 깨짐
가끔 테이블이 깨지는 경우가 발생할 수 있다. 약 1년에 한두번 발생한다고... 참고
Can't open file: 'xxxxxx.MYD'.(errno: 145)
# cd /var/lib/mysql/mysql # myisamchk -r xxxxxx.* # -r : recovery, -o : safe recovery, -f : force
[root@localhost]# mysql -u root -p Enter password: MySQL_ROOT_PASSWORD mysql> use DB_NAME; Database changed mysql> lock tables TABLE_NAME read; mysql> lock tables TABLE_NAME write; mysql> flush tables; mysql> exit [root@localhost]# cd /var/lib/mysql/DB_NAME [root@locahost]# myisamchk -ro TABLE_NAME [root@localhost]# mysql -u root -p Enter password: MySQL_ROOT_PASSWORD mysql> use DB_NAME; Database changed mysql> unlock tables; mysql> flush tables;
설정 변수 보기
mysql> show variables like "c%"; # c로 시작하는 환경 변수 보기
한글문제
4.1버전이후로, encoding의 설정이 약간 바뀌였다. UTF8을 기본으로 쓰고자 한다면, /etc/mysql/my.conf 에
[client] default-character-set=utf8 [mysqld] default-character-set=utf8 [mysqldump] default-character-set=utf8
DB 생성시에는 다음 명령으로
CREATE DATABASE 데이타베이스_이름 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
만일 다른 인코딩으로 이미 저장되어 있는 경우는 (특히 PHP의 경우, ) 연결후, 아래명령을 삽입한다.
@mysql_query('set names utf8', $connect_db);
euc-kr 용 db를 만들고 싶다면,
create database dbname default character set euckr;
For Python,
그외,
암호 분실시
# /etc/init.d/mysqld stop # mysqld_safe --skip-grant-tables # mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 4.1.8-standard Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> UPDATE mysql.user SET Password=PASSWORD('xxxx') where User='root'; Query OK, 5 rows affected (0.09 sec) Rows matched: 5 Changed: 5 Warnings: 0 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> Bye # /etc/init.d/mysql restart