MySQL °ü·Ã

root¾ÏÈ£º¯°æ¼³Á¤
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
This is done with:
/usr/bin/mysqladmin -u root -p password 'new-password'
/usr/bin/mysqladmin -u root -h ns.dbakorea.pe.kr -p password 'new-password'

½©¿¡¼­´Â mysqlÀÌ µÇ´Âµ¥ PHP¿¡¼­ mysql.sock error¸¦ ³»¸é¼­ MySQLÀÌ ¾ÈµÇ´Â °æ¿ì
mysql.sockÀº /tmp ¾Æ´Ï¸é /var/lib/mysql¿¡ »ý±â°Ô µÈ´Ù.
³ªÀÇ °æ¿ì, /var/lib/mysql¿¡ mysql.sockÆÄÀÏÀÌ Àִµ¥ PHP¿¡¼­´Â /tmp¿¡¼­ ãÀ¸·ÁÇϸ鼭 ¿¡·¯¸¦ ¹ß»ýÇß´Ù.
/usr/bin/safe_mysqldÆÄÀÏ¿¡¼­ ´ÙÀ½°ú °°ÀÌ ¼öÁ¤ÇÑ´Ù.
ÁÖ¼®(#)ÀÌ ´Þ¸° °ÍÀÌ ¿ø·¡°ÍÀÌ°í ±× ¹Ø¿¡ Àִ°ÍÀÌ ¼öÁ¤ÇÑ °ÍÀÌ´Ù.

# MYSQL_UNIX_PORT=${MYSQL_UNIX_PORT:-/var/lib/mysql/mysql.sock}
MYSQL_UNIX_PORT=${MYSQL_UNIX_PORT:-/tmp/mysql.sock}

À§¿Í °°ÀÌ ÇÏ´Ï /usr/bin/mysqlÀÌ /var/lib/mysql/mysql.sock¿¡¼­ ¼ÒÄÏÆÄÀÏÀ» ãÀ¸·Á Çß´Ù.
socket fileÀ» ÁöÁ¤ÇÏ´Â --socketÀ̶ó´Â ¿É¼ÇÀ¸·Î ´ÙÀ½°ú °°ÀÌ ÁöÁ¤ÇÏ¸é µÈ´Ù.

mysql --socket=/tmp/mysql.sock -u dbakorea -p db_test

ÇÏÁö¸¸ mysql½ÇÇà½Ã¸¶´Ù ÀÌ·¸°Ô ½áÁà¾ßÇÑ´Ù´Â °ÍÀÌ »ó´çÈ÷ ±ÍÂú´Ù. ¿É¼ÇÀÌ ¹Ù·Î Àû¿ëµÇ°Ô ¼³Á¤ÇÏÀÚ.
mysqlÀº ¼³Á¤»çÇ×À» ´ÙÀ½ 3°¡Áö ÆÄÀÏ¿¡¼­ °Ë»öÇÑ´Ù.

/etc/my.cnf            global options(MySQL ÀüüÀûÀ¸·Î »ç¿ëµÇ´Â ¿É¼Ç Á¤ÀÇ)
mysql-data-dir/my.cnf  ƯÁ¤ DB¿¡ Àû¿ëµÇ´Â option (/var/lib/mysql/my.cnf)
~/.my.cnf              »ç¿ëÀÚ °¢°¢ÀÇ ¼³Á¤('~'¹®ÀÚ´Â »ç¿ëÀÚÀÇ È¨µð·ºÅ丮´Â ÀǹÌ)

/usr/share/mysqlµð·ºÅ丮¿¡ ¿¹Á¦°¡ ÀÖÀ¸¹Ç·Î Âü°íÇÑ´Ù.
¼ÒÄÏÆÄÀÏÀÇ ÁöÁ¤Àº ´ÙÀ½ÁÙÀ» ³Ö¾îÁÖ¸é µÈ´Ù.

socket          = /tmp/mysql.sock


== /etc/my.cnf¿¹ ==
# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock


# root¾ÏÈ£¼³Á¤
% mysqladmin -u root password 'º¯°æ¾ÏÈ£'  root·Î ·Î±×ÀÎÇÏ¿© ÇؾßÇÔ
 
DB»ý¼º
mysql> create database DB¸í
or ½©ÇÁ·ÒÇÁÆ®»ó¿¡¼­ 
% mysqladmin -u root -p create DB¸í

DB»èÁ¦
mysql> drop database DB¸í

MySQL ¿¬°á
mysql -u »ç¿ëÀÚ -p DB¸í
or ½©ÇÁ·ÒÇÁÆ®»ó¿¡¼­ 
% mysqladmin -u root -p drop DB¸í

ÁúÀÇÆÄÀÏ ½ÇÇà
mysql>load data local infile "ÁúÀÇÆÄÀÏ" into table Å×À̺í¸í ;
ÁúÀÇÆÄÀÏ¿¡¼­ Ä÷³±¸ºÐÀº Åǹ®ÀÚ, Null°ªÀº /n·Î ÀÔ·Â

or ½©ÇÁ·ÒÇÁÆ®»ó¿¡¼­ 
mysql -u »ç¿ëÀÚ -p DB¸í < ÁúÀÇÆÄÀÏ

½©ÇÁ·ÒÇÁÆ®»ó¿¡¼­ ÁúÀÇ ½ÇÇà
dbakorea@lion board]$ mysql mysql -u root -pxxxx -e \
>            "INSERT INTO db VALUES(
>            'localhost', 'aaa', 'aaa',
>            'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y')"


»ç¿ëÀÚ »ý¼º & »ç¿ëÀÚ¿¡°Ô DBÇÒ´ç
shell> mysql --user=root -p mysql

mysql> INSERT INTO user VALUES('localhost','»ç¿ëÀÚ',PASSWORD('ºñ¹Ð¹øÈ£'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
mysql> INSERT INTO user VALUES('%','»ç¿ëÀÚ',PASSWORD('ºñ¹Ð¹øÈ£'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

mysql> INSERT INTO db(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('localhost','DB¸í','»ç¿ëÀÚ','Y','Y','Y','Y','Y','Y');
mysql> INSERT INTO db(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES('%','DB¸í','»ç¿ëÀÚ','Y','Y','Y','Y','Y','Y');

mysql> FLUSH PRIVILEGES; (or shell prompt: mysqladmin -u root -pxxxx reload)


DB, Å×À̺í¸ñ·Ïº¸±â
mysql> show databases;
mysql> show tables;

»ç¿ë DB¼±ÅÃ
mysql> use DB¸í

Å×ÀÌºí±¸Á¶
mysql> describe Å×À̺í¸í

Á¢¼Ó
mysql {-h Á¢¼ÓÈ£½ºÆ®} -u »ç¿ëÀÚ -p »ç¿ëDB
-h·Î ´Ù¸¥ ¼­¹ö¿¡ Á¸ÀçÇÏ´Â MySQLÁ¢¼Ó½Ã ´ÙÀ½°ú °°ÀÌ MySQL DB¿¡ ¼³Á¤ÇØÁà¾ß ÇÑ´Ù.
mysql> INSERT INTO user VALUES('Á¢±ÙÀ» Çã¿ëÇÒ È£½ºÆ®ip','»ç¿ëÀÚ',PASSWORD('ºñ¹Ð¹øÈ£'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
mysql> INSERT INTO db(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES('Á¢±ÙÀ» Çã¿ëÇÒ È£½ºÆ®ip','»ç¿ëDB','»ç¿ëÀÚ','Y','Y','Y','Y','Y','Y');
mysql> FLUSH PRIVILEGES; or ½¯ÇÁ·ÒÇÁÆ®»ó¿¡¼­ % mysqladmin -u root -p flush-privileges

¹öÀüüũ
mysql> select version();

°Ë»öÁ¶°Ç(where)
regular expressionÀ» Áö¿øÇÏ´Ù´Ï ½Å±âÇϱº..
mysql> select * from work where ¿­¸í regexp "Á¤±ÔÇ¥Çö½Ä";

Ä÷³ÀÇ Ãß°¡, »èÁ¦(¿À¶óŬ°ú µ¿ÀÏ)
alter table Å×À̺í¸í add Ä÷³¸í µ¥ÀÌÅÍŸÀÔ;
alter table Å×À̺í¸í del Ä÷³¸í;


¹é¾÷ & º¹±¸
mysqldump {-h È£½ºÆ®} -u »ç¿ëÀÚ -p DB¸í > ¹é¾÷ÆÄÀÏ
mysql {-h È£½ºÆ®} -u »ç¿ëÀÚ -p DB¸í < ¹é¾÷ÆÄÀÏ

mysqldump -u root -p --opt db_dbakorea > dbakorea.sql
mysqldump -u root -p --opt db_board | mysql ---host=remote-host -C database (»óÀÌÇÑ ¸Ó½®)
mysql -u dbakorea -p db_dbakorea < dbakorea.sql       


mysqldump -u root -p --opt db_dbakorea | mysql ---host=ns.dbakorea.pe.kr -C db_dbakorea 

Å×ÀÌºí °Ë»ç
isamchk

¿À¶óŬ sysdate¿Í µ¿ÀÏ
insert into test values('12', now());

À¯´Ð½º time()ÇÔ¼ö ¸®ÅÏ°ª »ç¿ë
FROM_UNIXTIME(954788684) 
UNIX_TIMESTAMP("2001-04-04 :04:04:04") 




==============================================================================
MySQL Ư¼ºÁ¤¸®
==============================================================================
primary keyÁö¿ø
index Áö¿ø(15°³Ä÷³, 256byte±îÁö)
foreign key, check, refereces±â´É Áö¿øÇÏÁö ¾ÊÀ½(Çü½Ä»ó ÀÖÀ½)

mysql> CREATE TABLE test (
        id INT NOT NULL,
        last_name CHAR(30) NOT NULL,
        first_name CHAR(30) NOT NULL,
        PRIMARY KEY (id),
        INDEX name (last_name,first_name));
        
MySQL¿¡¼­ÀÇ Stored Script°³³ä => SQL server language
commit-rollback°³³ä => lock tables

Copyleft(C) ¸í±ÔÀÇ ¿À¶óŬOCP All rights free