mysql - RLidea/dev.docs GitHub Wiki

๊ธฐ๋ณธ ๋ช…๋ น์–ด

๊ธฐ๋ณธ: http://kwonnam.pe.kr/wiki/database/mysql/basic
๋ฐฑ์—…/๋ณต์›: http://chongmoa.com/sql/630

MySQL Dump

1. Dumping data

Dumping Database

$ mysqldump -u[์‚ฌ์šฉ์ž์•„์ด๋””] -p [๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ช…]> [์ €์žฅ๋  ํŒŒ์ผ๋ช…]
$ mysqldump -utester -p dbtest > test.sql #์˜ˆ

Dumping tables

$ mysqldump -u[์‚ฌ์šฉ์ž์•„์ด๋””] -p [๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ช…] [ํ…Œ์ด๋ธ”๋ช…] > [์ €์žฅ๋  ํŒŒ์ผ๋ช…]

2. Restore data using dump

$ mysql -u[์‚ฌ์šฉ์ž์•„์ด๋””] -p [๋””๋น„๋ช…] < [๋คํ”„ํŒŒ์ผ๋ช…]

MySQL If

  • updated at๊ณผ created at์„ ๋น„๊ตํ•ด์„œ ํฐ ์ชฝ์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.
SELECT id, label FROM labels ORDER BY IF (updated_at > created_at, updated_at, created_at) desc

MySQL ์™ธ๋ถ€ ์ ‘๊ทผ ํ—ˆ์šฉํ•˜๊ธฐ

MySQL ์™ธ๋ถ€ ์ ‘๊ทผ ํ—ˆ์šฉํ•˜๊ธฐ :

ODBC๋“ฑ ์™ธ๋ถ€์—์„œ MySQL์— ์ ‘์†์„ ํ•˜๋ ค๋ฉด, MySQL ์ ‘์†์ด ํ—ˆ์šฉ๋˜์–ด์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค

์ผ๋‹จ ์ ‘์†ํ•˜์ž

mysql -uroot -p
  1. ํ…Œ์ด๋ธ” ์‚ดํŽด๋ณด๊ธฐ ๋จผ์ €, mysql์— ๋“ค์–ด๊ฐ€์„œ ๋‹ค์Œ ๋ฐฉ๋ฒ•์„ ์ด์šฉํ•ด ์ ‘๊ทผ ์ƒํƒœ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
mysql> use mysql;
mysql> select host, user, password from user;

์ถœ๋ ฅ๋œ ์ •๋ณด๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด, localhost๋‚˜ 127.0.0.1๋งŒ ๋“ฑ๋ก์ด ๋˜์–ด์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์™ธ๋ถ€์—์„œ ์ ‘๊ทผ์ด ๋˜๊ฒŒ ํ•˜๋ ค๋ฉด, ๋”ฐ๋กœ ๋“ฑ๋ก์„ ํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  1. ๊ถŒํ•œ ์„ค์ • ํ•˜๊ธฐ ์„ค์ •์„ ํ•  ๋•Œ, ํŠน์ • IP๋‚˜ ํŠน์ • IP๋Œ€์—ญ๋งŒ ํ—ˆ์šฉ์„ ํ•˜๊ฑฐ๋‚˜, ์ „์ฒด๋ฅผ ํ—ˆ์šฉ๋˜๊ฒŒ ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค.
  1. ํŠน์ • IP ์ ‘๊ทผ ํ—ˆ์šฉ ์„ค์ •
mysql> grant all privileges on *.* to โ€˜rootโ€™@โ€˜192.168.56.101โ€™ identified by โ€˜root์˜ ํŒจ์Šค์›Œ๋“œโ€™;
  1. ํŠน์ • IP ๋Œ€์—ญ ์ ‘๊ทผ ํ—ˆ์šฉ ์„ค์ •
mysql> grant all privileges on *.* to โ€˜rootโ€™@โ€˜192.168.%โ€™ identified by โ€˜root์˜ ํŒจ์Šค์›Œ๋“œโ€™;
  1. ๋ชจ๋“  IP์˜ ์ ‘๊ทผ ํ—ˆ์šฉ ์„ค์ •
mysql> grant all privileges on *.* to โ€˜rootโ€™@โ€˜%โ€™ identified by โ€˜root์˜ ํŒจ์Šค์›Œ๋“œโ€™
  1. ๋“ฑ๋ฃฉํ™•์ธ ํ›„ ์ ์šฉ์‹œํ‚ค๊ธฐ ๋“ฑ๋ก์ด ๋๋‚ฌ์œผ๋ฉด, ๊ณ„์ •์— ์„ค์ •ํ•œ IPํ˜น์€ %๊ฐ€ ๋“ฑ๋ก ๋˜์–ด์žˆ๋Š”์ง€ ํ™•์ธ์„ํ•ฉ๋‹ˆ๋‹ค.
mysql> select host, user, password from user;
mysql> flush privileges;
  1. my.cnf์—์„œ ์™ธ๋ถ€ ์ ‘์† ๊ด€๋ จ ๋‚ด์šฉ ๋ณ€๊ฒฝํ•˜๊ธฐ my.cnf ์„ค์ •ํŒŒ์ผ์—์„œ bind-address๋ผ๋Š” ๋ถ€๋ถ„์„ ์ฃผ์„์ฒ˜๋ฆฌ ํ•ด์ค๋‹ˆ๋‹ค.
vi /etc/my.cnf
# bind-address = 127.0.0.1
  1. mysql ์žฌ์‹œ์ž‘ ์ฃผ์„์ฒ˜๋ฆฌ๊ฐ€ ๋๋‚ฌ์œผ๋ฉด, mysql์„ ์žฌ์‹œ์ž‘ ํ•ด์ค๋‹ˆ๋‹ค.
/etc/init.d/mysqld restart

Ctrl+C&V ๋กœ ํ•˜๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ :: MySQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ mysqldump ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•œ procedure, function, trigger ํฌํ•จ ๋ฐฑ์—… ๋ฐ ๋ณต๊ตฌ ๋ฐฉ๋ฒ•

Mysql Timezone ์„ค์ • ๋ฐฉ๋ฒ•

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
mysql> set time_zone = 'Asia/Seoul';
mysql> select @@time_zone;
mysql> select now();

์ดํ›„ ์žฌ์‹œ์ž‘

service mysqld restart

๊นŒ๋ฌด ๋ธ”๋กœ๊ทธ :: MYSQL Timezone ์‹œ๊ฐ„ ์„ค์ • ๋ฐฉ๋ฒ•

โš ๏ธ **GitHub.com Fallback** โš ๏ธ