MySQL - Sizuha/devdog GitHub Wiki
๋ค์ ๊ฒฝ๋ก๋ฅผ PATH์ ์ถ๊ฐ.
/usr/local/mysql/bin
์ฐ์ /etc/my.cnf๊ฐ ํ์ํ๋ค.
/usr/local/mysql/support-files/ ๊ฒฝ๋ก์์ my-huge.cnf, my-large.cnf, my-medium.cnf, my-small.cnf ํ์ผ ์ค ํ๋๋ฅผ /etc/my.cnf๋ก ๋ณต์ฌ.
sudo cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf
/etc/my.cnf ๋ด์ฉ์ ๋ค์ ํญ๋ชฉ์ ์ถ๊ฐ/์์ .
[mysqld]
character-set-server=utf8
[mysql]
default-character-set=utf8
์ค์ ์ ์ฅ ํ, MySQL ์ฌ์์. ์ค์ ํ์ธ์ ๋ค์๊ณผ ๊ฐ์ด ํ๋ค.
mysql> show variables like "%character%";
mysql> show variables like "%collation%";
sudo /usr/local/mysql/support-files/mysql.server start
$ mysql -u root -pPASSWORD
mysql> use mysql;
๋ด๋ถ์์ ์ ์ํ๋ ์ฌ์ฉ์
mysql> insert into user (host, user, password) values ('localhost', 'dbuser', password('xxxxxxxx'));
์ธ๋ถ์์ ์ ์ํ๋ ์ฌ์ฉ์
mysql> insert into user (host, user, password) values ('%', 'dbuser', password('xxxxxxxx'));
mysql> show grants for USER@'%';
mysql> grant select, insert, update, delete on DB_Name.TableName to USER@'%';
์์ผ๋ ์นด๋ ์ฌ์ฉ:
mysql> grant select, insert, update, delete on DB_Name.* to USER@'%';
$ mysqladmin -u root -p password
$ mysql -u root
mysql> update user set password = password('์๋ก์ด_์ํธ') where user = 'root';
mysql> flush privileges;
MySQL 5.7 ์ด์์ธ ๊ฒฝ์ฐ,
$ mysql -u root
mysql> UPDATE mysql.user SET authentication_string=PASSWORD('my-new-password') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> set password for root = password('์๋ก์ด_์ํธ');
$ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
์ดํ ๋ค๋ฅธ ํฐ๋ฏธ๋ ์ฐฝ์์,
$ mysql -u root
update๋ฌธ์ ์ด์ฉํ์ฌ root ์ํธ๋ฅผ ์ค์ ํ๋ค.
MySQL์ ๋ค์ ์์.
$ sudo /usr/local/mysql/support-files/mysql.server start
์ดํ์, mysql ์ฝ์์์ ๋ง์ฝ ๋ค์๊ณผ ๊ฐ์ ์๋ฌ๊ฐ ๋์จ๋ค๋ฉด...
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
๋ค์๊ณผ ๊ฐ์ด ์ํธ๋ฅผ ๋ค์ ์ค์ ํด ์ค๋ค.
mysql> SET PASSWORD = PASSWORD('your_new_password');
$ mysql -u root -p
$ mysql -u ๊ณ์ ์ด๋ฆ(ex. root) -p
๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ชฉ๋ก ํ์.
mysql> show databases;
DB ์ด๊ธฐ.
mysql> use DB์ด๋ฆ;
mysql> create database DB์ด๋ฆ;
๋ฌธ์์ด ์ธ์ฝ๋ฉ์ utf-8์ ๊ธฐ๋ณธ์ผ๋ก ํ๋ DB ์์ฑ.
mysql> CREATE DATABASE <dbname> CHARACTER SET utf8;
DB ๋ฐฑ์
$ mysqldump -u {user} -p {database-name} > {dump-output}.sql
DB ๋ณต์
$ mysql -u {user} -p {database-name} < {dump-output}.sql
ํ ์ด๋ธ ๊ตฌ์กฐ ๋ณด๊ธฐ
mysql> DESC ํ
์ด๋ธ์ด๋ฆ;
mysql> DESCRIBE ํ
์ด๋ธ์ด๋ฆ;
mysql> EXPLAIN ํ
์ด๋ธ์ด๋ฆ;
INSERT INTO ใใผใใซๅ VALUES (โๅค1โฒ [ , โๅค2โ ]ใปใปใป);
UPDATE ใใผใใซๅ SET ใใฃใซใ=ๅค[, ...] WHERE ๆกไปถ;
ํ ์ด๋ธ์์ ์กฐ๊ฑด์ ๋ง๋ ํ์ ์ญ์ ํ๋ค.
DELETE FROM ใใผใใซๅ WHERE ๆกไปถ;
WHERE์ ์ ์๋ตํ๋ฉด ํ ์ด๋ธ ์์ ๋ชจ๋ ํ์ด ์ญ์ ๋๋ค.
- now() : ํ์ฌ ๋ ์ง์ ์๊ฐ
- date() : ๋ ์ง ๋ถ๋ถ๋ง ์ถ์ถํ๋ค
Nam | Description |
---|---|
ADDDATE() | Add dates |
ADDTIME() | Add time |
CONVERT_TZ() | Convert from one timezone to another |
CURDATE() | Return the current date |
CURRENT_DATE(), CURRENT_DATE | Synonyms for CURDATE() |
CURRENT_TIME(), CURRENT_TIME | Synonyms for CURTIME() |
CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP | Synonyms for NOW() |
CURTIME() | Return the current time |
DATE_ADD() | Add two dates |
DATE_FORMAT() | Format date as specified |
DATE_SUB() | Subtract two dates |
DATE() | Extract the date part of a date or datetime expression |
DATEDIFF() | Subtract two dates |
DAY() | Synonym for DAYOFMONTH() |
DAYNAME() | Return the name of the weekday |
DAYOFMONTH() | Return the day of the month (1-31) |
DAYOFWEEK() | Return the weekday index of the argument |
DAYOFYEAR() | Return the day of the year (1-366) |
EXTRACT | Extract part of a date |
FROM_DAYS() | Convert a day number to a date |
FROM_UNIXTIME() | Format date as a UNIX timestamp |
HOUR() | Extract the hour |
LAST_DAY | Return the last day of the month for the argument |
LOCALTIME(), LOCALTIME | Synonym for NOW() |
LOCALTIMESTAMP, LOCALTIMESTAMP() | Synonym for NOW() |
MAKEDATE() | Create a date from the year and day of year |
MAKETIME | MAKETIME() |
MICROSECOND() | Return the microseconds from argument |
MINUTE() | Return the minute from the argument |
MONTH() | Return the month from the date passed |
MONTHNAME() | Return the name of the month |
NOW() | Return the current date and time |
PERIOD_ADD() | Add a period to a year-month |
PERIOD_DIFF() | Return the number of months between periods |
QUARTER() | Return the quarter from a date argument |
SEC_TO_TIME() | Converts seconds to 'HH:MM:SS' format |
SECOND() | Return the second (0-59) |
STR_TO_DATE() | Convert a string to a date |
SUBDATE() | When invoked with three arguments a synonym for DATE_SUB() |
SUBTIME() | Subtract times |
SYSDATE() | Return the time at which the function executes |
TIME_FORMAT() | Format as time |
TIME_TO_SEC() | Return the argument converted to seconds |
TIME() | Extract the time portion of the expression passed |
TIMEDIFF() | Subtract time |
TIMESTAMP() | With a single argument, this function returns the date or datetime expression. With two arguments, the sum of the arguments |
TIMESTAMPADD() | Add an interval to a datetime expression |
TIMESTAMPDIFF() | Subtract an interval from a datetime expression |
TO_DAYS() | Return the date argument converted to days |
UNIX_TIMESTAMP() | Return a UNIX timestamp |
UTC_DATE() | Return the current UTC date |
UTC_TIME() | Return the current UTC time |
UTC_TIMESTAMP() | Return the current UTC date and time |
WEEK() | Return the week number |
WEEKDAY() | Return the weekday index |
WEEKOFYEAR() | Return the calendar week of the date (1-53) |
YEAR() | Return the year |
YEARWEEK() | Return the year and week |