## : mysql 3.21 Reference Manual PostScript Ŵ ### 5, 6, 9, 10, 11, 12, 13, 15, 17, 18 : (taejun@hitel.net) 18 C-API κ : ǿ (golmong@cre.co.kr) ̸ : taejun@hitel.net, taejun@taejun.pe.kr : http://taejun.pe.kr (Mysql ڷᰡ ֽϴ) - - 5. mysql ǥ ȣȯ 5.1 mysql ANSI SQL92 Ȯκ 5.2 MYSQL 5.2.1 Sub-selects 5.2.2 SELECT INTO TABLE 5.2.3 Ʈ(Transactions) 5.2.4 ν Ʈ 5.2.5 ܷŰ(Foreign Keys) 5.2.5.1 ܷŰ ʴ 5.2.6 5.2.7 `--' ּ 5.3 Mysql ִ ǥ ΰ? 5.4 BLOB TEXT Ÿ 5.5 COMMIT-ROLLBACK  ġ ? 6. Mysql ý 6.1 ý̶ ΰ? 6.2 mysql ϱ 6.2.1 йȣ 6.3 mysql ϴ 6.4 ý ۵ 6.5 , 6.6 , 2ܰ : û 6.7 6.8 ʱ mysql Ѽ 6.9 mysql ο ߰ϱ 6.10 йȣ 6.11 ź 6.12 ũĿ Ͽ mysql ϰ ϴ 7. MySQL language reference. 7.1 Literals: how to write strings and numbers 7.1.1 Strings 7.1.2 Numbers 7.1.3 Hexadecimal values 7.1.4 NULL values 7.1.5 Database, table, index, column and alias names 7.1.5.1 Case sensitivity in names 7.2 Column types 7.2.1 Column type storage requirements 7.2.2 Numeric types 7.2.3 Date and time types 7.2.4 String types 7.2.5 Numeric types 7.2.6 Date and time types 7.2.6.1 Y2K issues and date types 7.2.6.2 The DATETIME, DATE and TIMESTAMP types 7.2.6.3 The TIME type 7.2.6.4 The YEAR type 7.2.7 String types 7.2.7.1 The CHAR and VARCHAR types 7.2.7.2 The BLOB and TEXT types 7.2.7.3 The ENUM type 7.2.7.4 The SET type 7.2.8 Choosing the right type for a column 7.2.9 Column indexes 7.2.10 Multiple-column indexes 7.2.11 Using column types from other database engines 7.3 Functions for use in SELECT and WHERE clauses 7.3.1 Grouping functions 7.3.2 Normal arithmetic operations 7.3.3 Bit functions 7.3.4 Logical operations 7.3.5 Comparison operators 7.3.6 String comparison functions 7.3.7 Cast operators 7.3.8 Control flow functions 7.3.9 Mathematical functions 7.3.10 String functions 7.3.11 Date and time functions 7.3.12 Miscellaneous functions 7.3.13 Functions for use with GROUP BY clauses 7.4 CREATE DATABASE syntax 7.5 DROP DATABASE syntax 7.6 CREATE TABLE syntax 7.6.1 Silent column specification changes 7.7 ALTER TABLE syntax 7.8 OPTIMIZE TABLE syntax 7.9 DROP TABLE syntax 7.10 DELETE syntax 7.11 SELECT syntax 7.12 JOIN syntax 7.13 INSERT syntax 7.14 REPLACE syntax 7.15 LOAD DATA INFILE syntax 7.16 UPDATE syntax 7.17 USE syntax 7.18 FLUSH syntax (clearing caches) 7.19 KILL syntax 7.20 SHOW syntax (Get information about tables, columns,...) 7.21 EXPLAIN syntax (Get information about a SELECT) 7.22 DESCRIBE syntax (Get information about columns) 7.23 LOCK TABLES/UNLOCK TABLES syntax 7.24 SET OPTION syntax 7.25 GRANT and REVOKE syntax 7.26 CREATE INDEX syntax 7.27 DROP INDEX syntax 7.28 Comment syntax 7.29 CREATE FUNCTION/DROP FUNCTION syntax 7.30 Is MySQL picky about reserved words? 8 MySQL Tutorial 1. ϱ/ 2. ϱ(Entering Queries) 3. ̽ ϱ 3.1 ͺ̽ ϱ 3.2 ̺ 3.3 ̺ ڷḦ ־ . 3.4 ̺κ ˻ . 3.4.1 ͸ ˻. 3.4.2 ־ ǿ ´ Ư ุ ˻ . 3.4.3 Ư ϱ 3.4.4 ϱ 3.4.5 ¥ MySQL ¥ ٷ  Լ ش. 3.4.6 null NULL Ư ̴. 3.4.7 ġ 3.4.8 3.5 ̺ ϱ 3.6 ġ (ϰ ó ) ϱ 9. mysql (functions) 9.1 mysql ϴ 9.1.1 Ϳ ϴ 9.1.2 ο ڼ ߰ 9.1.3 ƼƮ 9.2 Ʈ α 9.3 mysql ̺ ִ ũ 10. mysql ִ 10.1 ũ 10.2 ޸ <޸ ȭ> 10.3 ӵ ġ /ũ 10.4 How MySQL uses indexes 10.5 WHERE ȭϱ 10.6 ̺ ݴ 10.6.1 ͺ̽ ̺ 鶧 10.7 ̺ 10.8 ͺ̽ ̺ ɺ ũ 10.9 ̺ Ŵ 10.10 ̺ ۰ 迭ϴ 10.11 INSERT ӵ ġ κ 10.12 DELETE ӵ ġ κ 10.13 mysql ִ ӵ 10.14 ο ˰ ٸ ΰ? 11. mysql ġũ Ʈ 12. mysql ƿƼ 12.1 پ mysql α׷ 12.2 ؽƮ Ͽ Է(?)ϱ 12.3 mysql б ̺ 13. ̺ ļ isamchk ϱ 13.1 isamchk ɾ 13.2 isamchk ޸ 13.3 ̺ 13.4 ̺ 13.5 ļ isamchk ϱ. 13.5.1 ̺ 13.5.2 ̺ 13.5.3 ̺ ȭ 14 Adding new functions 14.1 Adding a new user-definable function 14.1.1 UDF calling sequences 14.1.2 Argument processing 14.1.3 Return values and error handling 14.1.4 Compiling and installing user-definable functions 14.2 Adding a new native function 15. mysql ODBC 15.1 MyODBC ϴ ü 15.2 MyODBC ִ 15.3 MyODBC ۵ϴ α׷ 15.4 ODBC α׷ 15.5 ODBC AUTO_INCREMENT ÷ 17. Ϲ ذ 17.1. ͺ̽ (?) 17.2 ͺ̽ 17.3 ӽſ mysqld ϱ 18 MySQL client tools 18.1 MySQL C API 18.2 C API datatypes 18.3 C API function overview 18.4 C API function descriptions 18.4.1 mysql_affected_rows() 18.4.2 mysql_close() 18.4.3 mysql_connect() 18.4.4 mysql_create_db() 18.4.5 mysql_data_seek() 18.4.6 mysql_debug() 18.4.7 mysql_drop_db() 18.4.8 mysql_dump_debug_info() 18.4.9 mysql_eof() 18.4.10 mysql_errno() 18.4.11 mysql_error() 18.4.12 mysql_escape_string() 18.4.13 mysql_fetch_field() 18.4.14 mysql_fetch_fields() 18.4.15 mysql_fetch_field_direct() 18.4.16 mysql_fetch_lengths() 18.4.17 mysql_fetch_row() 18.4.18 mysql_field_seek() 18.4.19 mysql_field_tell() 18.4.20 mysql_free_result() 18.4.21 mysql_get_client_info() 18.4.22 mysql_get_host_info() 18.4.23 mysql_get_proto_info() 18.4.24 mysql_get_server_info() 18.4.25 mysql_info() 18.4.26 mysql_init() 18.4.27 mysql_insert_id() 18.4.28 mysql_kill() 18.4.29 mysql_list_dbs() 18.4.30 mysql_list_fields() 18.4.31 mysql_list_processes() 18.4.32 mysql_list_tables() 18.4.33 mysql_num_fields() 18.4.34 mysql_num_rows() 18.4.35 mysql_ping() 18.4.36 mysql_query() 18.4.37 mysql_real_connect() 18.4.38 mysql_real_query() 18.4.39 mysql_reload() 18.4.40 mysql_row_seek() 18.4.41 mysql_row_tell() 18.4.42 mysql_select_db() 18.4.43 mysql_shutdown() 18.4.44 mysql_stat() 18.4.45 mysql_store_result() 18.4.46 mysql_thread_id() 18.4.47 mysql_use_result() 18.4.49 What results can I get from a query? 18.4.50 How can I get the unique ID for the last inserted row? 18.4.51 Problems linking with the C API 18.4.52 How to make a thread-safe client 19. Ÿ DB 19.1 Mysql/mSQL 19.1.1 mSQL Mysql ٲٱ 19.1.2 mSQL Mysql Ŭ̾Ʈ/ 19.1.3 How mSQL 2.0 SQL syntax differs from Mysql 19.2 PostgreSQL Mysql ======================================================================= - - 5. mysql ǥ ȣȯ 5.1 mysql ANSI SQL92 Ȯκ mysql ٸ sql ͺ̽ ã Ȯ κ ִ. ̷ κ ϴ ؾ Ѵ. ֳĸ mysql 尡 ٸ SQL ֱ ̴.  쿡 /*! ... */ ּ MYSQL Ȯ ̿ ð ڵ带 ִ. : SELECT /*! STRAIGHT_JOIN */ col_name from table1,table2 WHERE ... MYSQL Ȯ κ : - ʵŸ MEDIUMINT, SET, ENUM , ׸ ٸ BLOB TEXT Ÿ. - ʵӼ AUTO_INCREMENT, BINARY, UNSIGNED and ZEROFILL. - ڿ 񱳴 ⺻ ҹڸ ڼ(⺻ ISO-8859-1 Latin1) ȴ. ̰ ÷ BINARY Ӽ ؾ ϸ ̷ 쿡 mysql ȣƮ ϴ ASCII ڿ Ѵ. - MYSQL ͺ̽ 丮 ̺ ̸ . ̰ ΰ ϰ ִ: ̸ ҹڸ ϴ (κ н ý. ~) ýۿ MYSQL ͺ ̸ ̺ ̸ ҹڸ Ѵ. ̺ ̸ µ ٸ ҹڷ . ̺ , ̸ٲٱ, ű, , 縦 ǥ ý ִ. ̺ ̸ ٲٷ ϴ ̺ `.ISD', `.ISM' and `.frm' ̸ ٲٸ ȴ. - SQL db_name.tbl_name ̿Ͽ ٸ ͺ̽ ̺ ִ. Ϻ SQL ̰ User space θ. MYSQL TABLESPACES ʴ´ : create table ralph.my_table...IN my_tablespace. - ġ() ÷ LIKE ִ. - SELECT INTO OUTFILE STRAIGHT_JOIN ִ. 7.11 [SELECT] . -EXPLIAN SELECT ̺  Ǿ ش. - Use of index names, indexes on a subpart of a field, and use of INDEX or KEY in a CREATE TABLE statement. 7.6 [CREATE TABLE] . - ALTER TABLE CHANGE col_name, DROP col_name Ǵ DROP INDEX Ѵ. 7.7 [ALTER TABLE] . - ALTER TABLE IGNORE . - ALTER TABLE ADD, ALTER, DROP or CHANGE - IF EXISTS Ű带 ̿ DROP TABLE . - ̺ ̻󿡼 DROP TABLE . - LOAD DATA INFILE . κ Ŭ LOAD DATA INFILE ȣȯȴ. 7.15 [LOAD DATA INFILE] . (** ͸ Ѳ Է INSERT ϴ ӵ . **) - OPTIMIZE TABLE . - ڿ ''' ƴ϶ '"' Ǵ ''' ִ. - escape `\' . - SET OPTION . 7.24 [SET OPTION] . - GROUP BY κп ÷ ʿ䰡 . ̷ ǰ ƴ Ư ǿ Ų. 7.3.12 [GROUP BY Functions] . (** ANSI SQL Թ ̿Ͽ GROUP BY ϰ ϴ ÷ GROUP BY ־ Ѵ. ̷ Ǵ ʿ ִµ MYSQL ̷ . 7.3.12 Ѵ **) - ٸ SQL ȯ ߴ ڸ MYSQL ɿ ˸ ƽ Ѵ. ANSI SQL ODBC Ѵ. - MYSQL C α׷ OR AND ǹϴ || && νѴ. MYSQL || OR ̸ && AND ̴. ̷ ̹ MYSQL string concatenation (ڿ , ?) ANSI SQL ۷ || ʴ . CONCAT() Ѵ. CONCAT() ڰ ־ MYSQL || ۷ ȯϱ . MySQL understands the || and && operators to mean logical OR and AND, as in the C programming language. In MySQL, || and OR are synonyms, as are && and AND. Because of this nice syntax, MySQL doesn't support the ANSI SQL operator || for string concatenation; use CONCAT() instead. Since CONCAT() takes any number of arguments, it's easy to convert use of the || operator to MySQL. - ϵ SQL CODE STRAIGHT_JOIN MYSQL Ű ϱ ̷ Ű带 /* */ ּȿ ִ. '!' Ѵ. ̷ MYSQL ּ ٸ MYSQL ؼ ٸ SQL ̷ Ȯ ʰ dzʶ ִ. : SELECT /*! STRAIGHT_JOIN */ * from table1,table2 WHERE ... - ̳ : CREATE DATABASE or DROP DATABASE. 7.4 [CREATE DATABASE] . MOD() ſ % . % C α׷Ӹ ϸ PostgresSQL ȣȯ Ѵ. ÷ =, <>, <= ,<, >=,>, <<, >>, AND, OR, LIKE . LAST_INSERT_ID(). 18.4.49 [mysql_insert_id()] . REGEXP or NOT REGEXP. ϳ ϳ ̻ ڸ CONCAT() CHAR(). MYSQL ̷ ڸ ִ. BIT_COUNT(), ELT(), FROM_DAYS(), FORMAT(), IF(), PASSWORD(), ENCRYPT(), PERIOD_ADD(), PERIOD_DIFF(), TO_DAYS(), or WEE-DEC-OSF1, KDAY(). 꽺Ʈ ִ TRIM() .(Use of TRIM() to trim substrings) ANSI SQL Ÿ Ѵ. ׷ ǿ STD(), BIT_OR() and BIT_AND() DELET + INSERT REPLACE . 7.14 [REPLACE] . FLUSH flush_option . 5.2 MYSQL ɵ MYSQL ִ. 켱 Ȯ϶ MYSQL TODO . (http://www.mysql.com/Manual_split/manual_Todo.html). ̰ ֽ TODO ̴. η F [TODO] . 5.2.1 Sub-selects Mysql ۵ ʴ´: SELECT * FROM table1 WHERE id IN (SELECT id FROM table2); Mysql INSERT ... SELECT ... and REPLACE ... SELECT ... Ѵ. -select 3.23.0 Ƹ ̴. ״ IN() ִ. 5.2.2 SELECT INTO TABLE Mysql SELECT ... INTO TABLE .... ʴ´. , Mysql SELECT ... INTO OUTFILE ..., ϸ ⺻δ ϴ. 5.2.3 Ʈ(Transactions) Ʈ ʴ´. Mysql atomic(ڼ?) ۷̼ ̸ atomic ۷̼ rollback Ʈǰ . atomic ۷̼ ϸ insert/select/ ׷  嵵 浹 ֵ ش. ƿ Ϲ ѹ(rollback) ʿ. LOCK TABLES UNLOCK TABLES ̿Ͽ ٸ 尡 浹ϴ ִ. 7.23 [Lock Tables] . 5.2.4 ν Ʈ ν ϵǰ ִ SQL Ʈ̴. ̷ Ǹ Ŭ̾Ʈ ü Ǹ ٽ ʿ䰡 ν ִ. ̷ Ǵ ѹ ؼǰ Ŭ̾Ʈ ְ޾ƾ ϴ Ͱ پǷ ȴ. ̺귯 μ 踦 ų ִ. (??? You can also raise the conceptual level by having libraries of functions in the server.) ƮŴ Ư ̺Ʈ ߻ ν̴. Ʈ ̺ ڵ尡 ǰ Ʈ ϴ ̺ ִ ν ġ ִ. δ ν ƮŴ ƴϴ. ƮŴ ʿ 쿡 ־ Ϲ ӵ . ν ϰ Mysql ߰ η F .(The TODO) (** Ʈ ó Ʈ ͺ̽ ӵ ŵϴ. Mysql ̷ ӵ ĥ ִ κ Ͽ ӵ . ̷ κ ڱⰡ ϴ ͺ̽ 󸶳 ߿Ѱ Ǵ ƾ Դϴ. DBMS ȸ ʴ 찡 . ߻ , ȸ Ѵ. ׷Ƿ ڰ ̽ 纻 غϸ, ߻ϸ ۾ ٽ ؾ . ƮŰ ڷ Ἲ ϱ ʿ ̴. **) 5.2.5 ܷŰ(Foreign Keys) SQL ܷŰ ̺ κ Ἲ Ȯ Ѵ. SELECT ̺ ڷḦ ϸ ̺ ؼ ó ִ. SELECT * from table1,table2 where table1.id = table2.id 7.12 [JOIN] . Mysql ܷŰ(FOREIGN KEY) ٸ SQL ǰ CREATE TABLE ȣȯ Ѵ: ܷŰ ƹ͵ ʴ´. ON DELETE ... FOREIGN KEY κ Ѵ. ODBC ø̼ ̰ ڵ WHERE ̴. ׷ ̰ κ ()ϰ Ѿ . ܷŰ δ üũ(constraint check) ̷ üũ Ͱ ̺ Ȯ  ʿϴ. Mysql Ϻ ø̼ǿ ܷŰ ϴ ʿ ϱ ( ϵ ϵ ) ϴ ̴. Mysql ܷŰ ̺ ڵ带 ø̼ǿ DELETE ߰Ͽ ON DELETE ... Ǵ ν ذ ִ. ̷ ϴ ܷŰ ϴ Ͱ ( 쿡 ) ϱⰡ . Ͼȿ 츮 ܷŰ Ȯ ̴. ׷ ּ mysqldump ODBC ǰ ˻ ֵ ̴. 5.2.5.1 ܷŰ ʴ ܷŰ 𿡼 ؾ 𸣴 ִ: - Foreign key Ȳ ſ ϰ . ֳϸ, foreing key ǰ databaseܾ ϰ, foreign key ϴ "ڿ " File (data file ű, ϰ, ϴ ...) Ѵ. (** ش : ̻ѵ ܷŰ Ἲ Ģ ϰ ȴ. ̰ ϰ ִ ϴ. **) - INSERT UPDATE ӵ ģ. ׸ ̷ ùٸ ùٸ ̺ ڵ带 ϱ κ ܷŰ üũ ʿ . - ü ͺ̽ ۿ ϱ ̺ Ʈ ſ ̺ ؾ Ѵ. ڵ带 ϰ Ŀ ٸ ̺ ڵ带 ξ . - Table , (backup̳ ο sourceκ) record ٽ ϴ Table . - Foreign key Ѵٸ, table dump(backup)ϰ ( dump ڷ ) restoreϴ ־ Ϸ ϰ Ѿ Ѵ. - table ǰ ְ ϴ, ( Table ȣ ϰ ȴٸ) ܼ createδ Ұ circular definition(ȯ) ߻Ѵ. (: A Table B ڷḦ ϴ foreign key ְ, B C foreign key, C A foreign key 㵵 table ȴٸ ѹ A,B,C table . A,B,C foreign key ִ ȴ.) ܷŰ . ODBC Ư ٸ Ŭ̾Ʈ α׷  ̺ Ǿ ִ ְ ̾ µ ϸ ø̼ µ ̴. (: foreign key ؼ ſ ̴. , ̰ foreign key Ϻ ϻ̴. ٵ client Table DATA 迡 ؼ Ծ ؼ Ű澲 ʰ ϰ, ׻ ڷ Ἲ(ռ[?]) Ѵٴ ſ ߿ϴ. Ư, Table 1~20 ƴ 100 Ѿٸ, client Ű澲 programingϴ ͵ , debugging 󺸴 . table 踦 ȭѴٸ programmer foreign key ޱ ٴ Table checkؾ Ǵ Եȴ. foreign key ǵǴ ֵ table Data ϴ ʱ ̴. ǹ ߳ û óϴ ־ foreign keyŭ 彺 . ) Mysql ܷŰ Ǹ ֵ ؼ Ŭ̾Ʈ  ؼ ϰ ֵ ̴. '.frm' ̰ ϰ . 5.2.6 Mysql 並 ʴ´. ׷ TODO( ) ִ. MySQL doesn't support views, but this is on the TODO. 5.2.7 `--' ּ Ϻ ٸ SQL ͺ̽ '--' ּ Ѵ. mysql '--' ϴ Mysql '#' ּ Ѵ. ڴ C Ÿ /* this is a comment */ mysql ִ. 7.28 [Comment] . Mysql '--' ̴; '--' ּ · ڵ Ǵ SQL ǿ ߻Ų. . 츮 ڵ payment !payment! Էϵ ϰ ִ : UPDATE tbl_name SET credit=credit-!payment! payment  ̶ ϴ°? 1--1 մ SQḺ '--' ּ ǹϴ ̴. '--' ּ ϴ ؽƮ SQL α׷ ٸ ؾ Ѵ: shell> replace " --" " #" < text-file-with-funny-comments.sql \ | mysql database instead of the normal( ???): shell> mysql database < text-file-with-funny-comments.sql Ϸ '--' ּ '#' ּ ٲ ִ: shell> replace " --" " #" -- text-file-with-funny-comments.sql : shell> replace " #" " --" -- text-file-with-funny-comments.sql (** Ϻ SQL ϴ -- ּ Ƿ MYSQL # ּ Ѵٴ ̴ **) 5.3 Mysql ִ ǥ ΰ? Entry level SQL92. ODBC level 0-2. 5.4 BLOB TEXT Ÿ BLOB TEXT ʵ忡 GROUP BY ORDER BY ϱ ϸ ʵ ü Ѵ. ̷ ϴ ǥ SUBSTRING ϴ ̴. : mysql> select comment from tbl_name order by SUBSTRING(comment,20); ̷ ù ° max_sort_lengths (⺻ =1024) ȴ. BLOB TEXT ⺻ NULL ÷ . BLOB and TEXT cannot have DEFAULT values and will also always be NULL columns. 5.5 COMMIT-ROLLBACK  ġ ? Mysql COMMIT-ROLLBACK ʴ´. COMMIT-ROLLBACK ȿ ٷ ؼ Mysql ϴ Ͱ ٸ ̺ 谡 ʿϴٴ ̴. Mysql ̺ ڵ Ŭ ߰ ũ ִ ʿϴ. ̷ 纸 mysql 2-4 . Mysql κ ٸ SQL ͺ̽ ξ . ( ּ 2-3 ) ̷ Mysql COMMIT-ROLLBACK ̴. а 츮 SQL ۵ ַ ̴. κ COMMIT-ROLLBACK ʿ 幰. ̷ ϴ ִ. Ϲ Ʈ ʿ Ʈ LOCK TABLES ڵ带 © ִ. ڵ带 Ʈ Ŀ ʿ䰡 . 츮 Ʈǰ Ŀ TODO ־ 켱 ƴϴ. ̷ Ѵٸ CREATE TABLE ɼ ̴. ̰ ɼ ̺ ۵ϸ ̺ ̶ ǹѴ. 츮 100% ͺٴ ͺ̽ ʿ . COMMIT-ROLLBACK ϴ ӵ ջ ٸ 츮 װ ̴. а ߿ϰ ؾ ϵ ִ. 츮  Ϳ 켱 ΰ ִ TODO . ܰ ޴ ̰ ٲ 켱 ִ. ROLLBACK ̴. ѹ LOCK TABLES ̿Ͽ COMMIT ִ. ѹ ϱ Mysql Ʈ ڵ带 ϰ ѹ ̳ ư ֵ ٲپ Ѵ. ̷ ʴ.( isamlog ̷ 츦 ִ) ׷ ALTER/DROP/CREATE TABLE ѹ ϴ ô ƴ. ѹ ϱ ִ: 1. ϱ ϴ ̺ . LOCK TABLES ... 2. ׽Ʈ(Test conditions) 3. ȴٸ Ʈ Ѵ. 4. UNLOCK TABLES Ϲ ѹ ̿ Ʈ ϴ ͺٴ ̷ ξ . ׷ ׻ 밡 ƴϴ. ̷ ذ Ȳ Ʈ 带 ̴. ̷ ȴ. ׷ Ʈ δ ̴. ۷̼ǿ ڵ带 Ʈϴ ִ. ũ ϸ ſ ȿ ø̼ ִ: - õǾ ִ ʵ带 - ȭ ʵ带 Ʈ ,  Ʈ ٲ ͸ Ʈ Ѵ. ׸ For example, when we are doing updates on some customer information, we update only the customer data that have changed and test only that none of the changed data, or data that depend on the changed data, have changed compared to the original row. ȭ ׽Ʈ UPDATE WHRE Ͽ ִ. ڵ尡 Ʈ ʾҴٸ Ŭ̾Ʈ ޽ : " ٲ Ϻΰ ٸ ڿ ٲϴ". ׷ 츮 쿡 ڵ ڵ带 Ͽ . ׷ ڴ  ڵ带 ִ. ̷ ϸ "÷ ŷ" ϴ. ׷ δ . ֳ ϸ õǾ ִ ÷ Ʈϱ ̴. Ʈ ̴: UPDATE tablename SET pay_back=pay_back+'relative change'; UPDATE customer SET customer_date='current_date', address='new address', phone='new phone', money_he_owes_us=money_he_owes_us+'new_money' WHERE customer_id=id AND address='old address' AND phone='old phone'; ̷ ϸ ſ ȿ̸ ٸ Ŭ̾Ʈ pay_back ̳ money_he_owes_us ÷ ٲپ ۵Ѵ. κ , ڴ ̺ (identifiers) ϱ ѹ ̺ ϰ ;Ѵ. ̰ AUTO_INCREMENT ÷ SQL LAST_INSERT_ID() , Ǵ mysql_insert_id() C API Ͽ ȿ ִ. 18.4.49 [mysql_insert_id()] . TcX ̷ ذ ֱ low-level ʿ ʴ´.  쿡 ο- ʿϴ. ׷ ̷ ؼҼ̴. ο- ϸ ̺ ÷ ÷ ִ. : UPDATE tbl_name SET row_flag=1 WHERE id=ID; row ߰ߵǰ row_flag row ̹ 1 ƴ϶ row ڷμ 1 ȯѴ. MySQL returns 1 fro the number of affected rows if the row was found and row_flag wasn't already 1 in the original row. 6. Mysql ý mysql ǥ / ý ִ. ̹ 忡 ̰  ۵ϴ ϰ ִ. 6.1 ý̶ ΰ? Mysql ý ֿ ͺ̽ select, insert, update, delete ȣƮ ̸ ̴. ߰ ɿ ͸ ɰ LOAD DATA INFILE ̼ǰ mysql Ư ϴ κ ԵǾ ִ. Mysql ϴ ̸ н ̸ (α ̸)̳ ̸ 谡 ٴ ! . κ mysql Ŭ̾Ʈ mysql ̸ н ̸ Ͽ Ϸ ̴. ׷ ̰ Ǹ ؼ̴. Ŭ̾Ʈ α׷ -u --user ɼ ٸ ̸ Ѵ. ̰ mysql ̸ йȣ ͺ̽ ȿ ִٴ ǹѴ.  Ͽ Ϸ ϴ ̸ йȣ Ǿ ʴٸ ӿ ̴. н ̸ Ϲ 8ڷ ѵǾ ִ Ͱ ٸ mysql ̸ 16ڱ ִ. mysql йȣ н йȣ ƹ . н ӽſ α ϴ йȣ ͺ̽ ϴ йȣ . mysql н α μ ϴ Ͱ ٸ ˰ йȣ ȣȭѴ. 6.2 mysql ϱ mysql Ŭ̾Ʈ α׷ Ϲ з(Ű ) ϴ.: ȣƮ, ̸, йȣ. mysql Ŭ Ʈ ִ. ( ڴ [ ] ݴ´) shell>; mysql [-h host_name] [-u user_name] [-pyour_pass] -p ڿ йȣ ̿ ٴ . -h, -u, -p ü ִ δ --host=host_name, --user=user_name and --password=your_pass ִ. mysql Ŀǵ ο Ű ⺻ Ѵ. ⺻ ȣƮ ̸ localhost ̰ ⺻ ̸ н ̸̴.(-p йȣ ʴ´) ׷ н ̸ joe ϴ.: shell> mysql -h localhost -u joe shell> mysql -h localhost shell> mysql -u joe shell> mysql ٸ mysql Ŭ̾Ʈ ϰ ۵Ѵ. н ýۿ ִ ⺻ ־ Ŭ Ʈ α׷ ࿡ ɼ ʾƵ ȴ: Ȩ 丮 '.my.cnf' [client] ǿ ִ. Ͽ ̿ : [client] host=host_name user=user_name password=your_pass 4.14.4 [option files] . ȯ Ͽ ִ. ȣƮ MYSQL_HOST ִ. Mysql ̸ USER, LOGNAME, LOGIN ִ. (̷ ̹ н α ̸ Ǿ ̴. ׷Ƿ ٲ ʴ° ) йȣ MYSQL_PWD ִ.(׷ ̰ ʴ; ) Ǿٸ ࿡ ϰ ȯ ͺ 켱 . ȯ 켱 . 6. 2. 1 йȣ ٸ ڰ ߰ ְ йȣ ϴ ʴ . Ŭ̾Ʈ α׷ йȣ ϴ Ʒ 赵 Ͽ: ࿡ -pyour_pass Ǵ --password=your_pass ɼ . ̴. йȣ ý Ȳ α׷(ps ) ֱ ٸ ڰ .(mysql Ŭ̾Ʈ Ϲ ʱȭǴ ڸ 0 . ׷ ִ ª ƴ ִ) -p Ǵ --password ɼ (йȣ ). ̷ Ŭ̾Ʈ α׷ ͹̳ο йȣ : shell> mysql -u user_name -p Enter password: ******** Ŭ̾Ʈ йȣ ĥ ͹̳ο '*' ڸ ش. ׷ ٸ ڰ йȣ . ٸ ڰ Ƿ ࿡ йȣ Էϴ ξ ϴ. ׷ ȭ ũƮ Ŭ̾Ʈ α׷ ϸ ʴ. Ͽ йȣ . Ȩ 丮 '.my.cnf' [client] ǿ йȣ ִ. [client] password=your_pass йȣ '.my.cnf' Ͽ Ѵٸ ׷̳ ٸ б/⸦ ؾ Ѵ. ۹̼ 400 ̳ 600 Ȯ. 4.14.4 [ɼ ] . йȣ MYSQL_PWD ȯ ִ. ׷ ϸ ؼ ȵȴ. Ϻ ps α׷ μ ȯ溯 ִ ɼ ִ; MYSQL_PWD ϸ ٸ йȣ ִ. ̷ ps ý μ ȯ溯 ˻ ִ ٰ ϴ ϴ. ߿ Ŭ̾Ʈ α׷ йȣ 䱸ϰ ϰ '.my.cnf' Ͽ йȣ ϴ ̴. 6.3 mysql ϴ Ѱ õ mysql ͺ̽(ͺ̽ ̸ mysql ) user, db, host, table_priv, columns_priv ̺ ȴ. mysql , ׸ ȯ (6.7 [ ] ) ̺ оδ. mysql ϴ ϴ ̸ Ʒ . ÷ ̸ grant tables Ǵ context Ǿ ִ. +-------------------+----------------+------------------------------+ | Privilege () | Column (÷) | Context (ȯ) | +-------------------+----------------+------------------------------+ | select | Select_priv | tables | +-------------------+----------------+------------------------------+ | insert | Insert_priv | tables | +-------------------+----------------+------------------------------+ | update | Update_priv | tables | +-------------------+----------------+------------------------------+ | delete | Delete_priv | tables | +-------------------+----------------+------------------------------+ | index | Index_priv | tables | +-------------------+----------------+------------------------------+ | alter | Alter_priv | tables | +-------------------+----------------+------------------------------+ | create | Create_priv | databases, table or indexs | +-------------------+----------------+------------------------------+ | drop | Drop_priv | databases or tables | +-------------------+----------------+------------------------------+ | grant | Grant_priv | databases or tables | +-------------------+----------------+------------------------------+ | reload | Reload_priv | server administration | +-------------------+----------------+------------------------------+ | shutdown | Shutdown_priv | server administration | +-------------------+----------------+------------------------------+ | process | Process_priv | server administration | +-------------------+----------------+------------------------------+ | file | File_priv | file access on server | +-------------------+----------------+------------------------------+ select, insert, update, delete ͺ̽ ̺ 忡 ۷̼ ֵ Ѵ. SELECT ̺ (ڵ) select ʿϴ. ͺ̽ ϴ Ư SELECT ִ. mysql Ŭ̾Ʈ ִ: mysql> SELECT 1+1; mysql> SELECT PI()*2; index(ε) ε ϰų ִ. alter ALTER TABLE ֵ Ѵ. create drop ο ͺ̽ ̺ ϰų ϴ ͺ̽ ̺ ֵ Ѵ. ڿ mysql ͺ̽ drop ϸ, ڴ mysql ٱ ͺ̽ ִٴ°! . grant ڰ ִ ٸ ڰ ֵ Ѵ. file LOAD DATA INFILE and SELECT ... INTO OUTFILE ̿ ϰ ִ Ѵ. ̷ ڴ mysql а ִ а ִ ȴ. ѵ ۷̼ǿ Ǹ mysqladmin α׷ Ѵ. Ʒ ̺ ѿ ִ mysqladmin ش: +--------------------+----------------------------------------------+ | Privilege () | Command permitted to privilege holders | | | (ѿ Ǵ ) | +--------------------+----------------------------------------------+ | reload | reload, refresh, flush-privileges | | | , flush-hosts, flush-logs, flush-tables | +--------------------+----------------------------------------------+ | shutdown | shutdown | +--------------------+----------------------------------------------+ | process | processlist, kill | +--------------------+----------------------------------------------+ reload grant ̺ ٽ о δ. refresh ̺ α ݴ´. flush-privileges reload ɰ Ǿ̴. ٸ flush-* refresh Ѵ. ׷  쿡 ϴ. α ϸ ݰ ٽ Ѵٸ flush-logs refresh ̴. (** flush ɼδ ȣƮ, α , , ̺, status variables ִ. SQL Ǵ mysqladmin ƿƼ ϸ ȴ. **) shutdown ˴ٿѴ. (** ̰ ¾~~?? **) processlist ǰ ִ 忡 . kill 带 δ. ڽ ų ٸ ڿ ۵ μ ų ִ.  ɽ ؾ Ѵ:y: grant() ڰ ٸ ֵ Ѵ. ٸ Ѱ grant ڴ ִ. file б дµ .... SELECT ̿ ִ ... The file privilege can be abused to read any world-readable file on the server into a database table, the contents of which can then be accessed using SELECT. (** ʾƵ ̿ ִ ʴ° ٴ ̰ **) shutdown ٸ ڿ 񽺸 ϵ ִ. process йȣ ϰ ٲٴ Ǹ ϰ ִ Ǹ µ ִ. mysql ͺ̽ йȣ ٸ ٲٴ ִ. (йȣ ȣȭǾ Ǿٰ ϴ , ִ ڴ ٸ йȣ ٲ ) mysql ý ٷ  ִ: ź ڸ ϰ . ֳϸ ڿ źϴ ϰ ų ̴. ڰ ͺ̽ ̺ ִ ͺ̽ ü . (** ׷ϱ create drop ָ ͺ̽ ü . ׾ ̺ ֵ Ѵٴ **) 6.4 ý ۵ mysql ý ڰ ͸ŭ ֵ . mysql , Ȯ ȣƮ ڰ ̸ ȴ. ý Ȯΰ Ѵ. mysql ڸ Ȯϴµ ȣƮ̸ ̸ Ѵ Ѵ. ֳĸ ͳݿ ̸ ٰ ڶ ̴. whitehouse.gov ϴ bill microsoft.com ϴ bill ʿ . mysql ̸ ִ ȣƮ ̿ ڸ Ѵ : whitehouse.gov ϴ bill Ư ְ microsoft.com ϴ bill ٸ ִ. mysql ΰ ܰ谡 ִ: ܰ 1: ڰ ִ Ǵ ܰ 2 ( ڰ Ǿ ) : ڰ Ϸ ɿ ִ û Ǵ. , ͺ̽ ̺ select rows Ҷ, Ǵ ͺ̽ ̺ ̺ select ִ ̽ ִ Ȯ Ѵ. ܰ迡 mysql ͺ̽ user, db, host ̺ ̿Ѵ.grant ̺ ʵ Ʒ : +----------------+-----------------+---------------+---------------+ | Table name | user | db | host | +----------------+-----------------+---------------+---------------+ | Scope fields | Host | Host | Host | | (ʵ ) +-----------------+---------------+---------------+ | | User | Db | Db | | +-----------------+---------------+---------------+ | | Password | User | | +----------------+-----------------+---------------+---------------+ | | Select_priv | Select_priv | Select_priv | | +-----------------+---------------+---------------+ | | Insert_priv | Insert_priv | Insert_priv | | +-----------------+---------------+---------------+ | | Update_priv | Update_priv | Update_priv | | +-----------------+---------------+---------------+ | Privilege | Delete_priv | Delete_priv | Delete_priv | | filelds +-----------------+---------------+---------------+ | ( ʵ) | Index_priv | Index_priv | Index_priv | | +-----------------+---------------+---------------+ | | Alter_priv | Alter_priv | Alter_priv | | +-----------------+---------------+---------------+ | | Create_priv | Create_priv | Create_priv | | +-----------------+---------------+---------------+ | | Drop_priv | Drop_priv | Drop_priv | | +-----------------+---------------+---------------+ | | Grant_priv | Grant_priv | Grant_priv | | +-----------------+---------------+---------------+ | | Reload_priv | | | | +-----------------+---------------+---------------+ | | Shutdown_priv | | | | +-----------------+---------------+---------------+ | | Process_priv | | | | +-----------------+---------------+---------------+ | | File_priv | | | +----------------+-----------------+---------------+---------------+ ι° ܰ踦 (û ), û ̺ ̶ ߰ tables_priv columns_priv ̺ Ѵ. ̺ ʵ : +-------------------+---------------+----------------+ | Table name | tables_priv | columns_priv | +-------------------+---------------+----------------+ | Scope fields | Host | Host | | +---------------+----------------+ | | Db | Db | | +---------------+----------------+ | | User | User | | +---------------+----------------+ | | Table_name | Table_name | | +---------------+----------------+ | | | Column_name | +-------------------+---------------+----------------+ | Privilege field | Table_priv | Type | | +---------------+----------------+ | | Column_priv | | +-------------------+---------------+----------------+ | Other fields | Timestamp | Timestamp | | +---------------+----------------+ | | Gran | | +-------------------+---------------+----------------+ (grant) ̺ ʵ ʵ Ǿ ִ. ʵ ̺ Ʈ Ѵ. ٽ ϸ Ʈ Ǵ context(ȯ, )̴. , Host User 'thomas.loc.gov' 'bob' user ̺ Ʈ thomas.loc.gov ȣ Ʈ bob Ҷ ϴµ ȴ.ϰ Host, User, db ʵ尪 'thomas.loc.gov', 'bob', 'reports' db ̺ Ʈ thomas.loc.gov ȣƮ bob reports ͺ̽ ȴ. tables_priv columns_priv ̺ ̺̳ Ʈ ִ ̺/÷ Ű ʵ带 ϰ ִ. üũ ϱ , HOst 񱳴 ҹڸ ʴ´. User, Password, Db, Table_name ҹڸ Ѵ. mysql 3.22.12 Column_name ҹڸ ʴ´. (3.22.11 ҹ ) ʵ ̺ Ʈ εǴ Ű ̴ ִ ䷹̴̼. Ϻϰ ϱ (grant) ̺ Ѵ. ⿡ ϴ Ģ 6.6 [Request access] . ʵ ڿ̸ ǵǾ; ⺻ ڿ : +--------------+------------+-------------------------------------+ | Field name | Type | | +--------------+------------| | | Host | CHAR(60) | | +--------------+------------| | | User | CHAR(16) | | +--------------+------------| | | Password | CHAR(16) | | +--------------+------------+-------------------------------------+ | Db | CHAR(64) | (CHAR(60) for the tables_priv and | | | | columns_priv tables) | +--------------+------------+-------------------------------------+ user, db, host ̺ ʵ ENUM('N','Y') ǵǾ ִ. -- 'N' 'Y' ⺻ 'N' ̴. (** ENUM Ÿ ϳ .ʵ Ÿ **) tables_priv columns_priv ̺ ʵ SET ʵ ǵ : (** SET Ÿ ߿ 0̳ 1 ̻ **) +--------------+-------------+--------------------------------------+ | Table name | Field name | Possible set elements | +--------------+-------------+--------------------------------------+ | tables_priv | Table_priv | 'Select', 'Insert', 'Update', | | | | 'Delete', 'Create', 'Drop', 'Grant', | | | | 'References', 'Index', 'Alter' | +--------------+-------------+--------------------------------------+ | tables_priv | Column_priv | 'Select', 'Insert', 'Update', | | | | 'References' | +--------------+-------------+--------------------------------------+ | columns_priv | Type | 'Select', 'Insert', 'Update', | | | | 'References' | +--------------+-------------+--------------------------------------+ ϰ ؼ (grant) ̺ Ѵ: user ̺ scope() ʵ ῡ ź Ѵ. ῡ Ͽ, ʵ ü (superuser) Ų. db host ̺ Բ ȴ: - db ̺ ʵ  ȣƮ  ͺ̽  ڰ ִ Ѵ. ʵ  ۷̼ Ǿ Ѵ. - host ̺ db ̺ Ʈ ȣƮ db ̺ Ȯ Ѵ. , ڰ Ʈ ȣƮ ͺ̽ ֵ Ϸ, "db" ̺ Ʈ Host ΰ, "host" ȣƮ Ʈ ȴ.̷ 6,6 [Request access] ڼ ϰ ִ. tables_priv columns_priv ̺ db ̺ ϴ. ׷ ִ: ̺ ͺ̽ ܰ迡 ư ̺ ÷ ܰ迡 ִ. (reload, shutdown,Ÿ..) user ̺ ִٴ ! ֳĸ ۷̼ ü ۷̸̼ Ư ͺ̽ ϴ ƴϴ. ׷Ƿ ̷ ٸ (grant) ̺ ʿ䰡 ., user ̺ ۷̼ ִ ȴ. (file) ѵ user ̺ Ѵ. ƴϴ. ׷ ȣƮ аų ִ ϰ ִ ͺ̽ ̴. mysqld (grant) ̺ ѹ д´. ̺ ϰ ȿ Ϸ 6.7 [Privilege changes] . ̺ ϴ´ Ǿ Ȯ ϴ ̴. α׷ mysqlaccess ũƮ μ Yves CArlier mysql distribution ϰ ִ.  ϰ ִ Ȯϱ mysqlaccess --help ɼ ־ . 6.11 [Access denied] 6.12 [Security] . mysqlaccess user, db, host ̺ Ѵ. ̺̳ ÷ ܰ ѱ ʴ´ٴ . 6.5 , ܰ 1 : Ȯ() mysql Ϸ Ȯΰ йȣ ϰų źѴ. Ȯ ȵǸ źѴ. Ȯ Ǹ ޾Ƶ̰ 2° ܰ  û ٸ. Ȯ ΰ ϰ ִ: ϴ ȣƮ mysql ̸ Ȯ user ̺ ʵ(Host, User, Password) Ͽ ȴ. user ̺ Ʈ ȣƮ̸ , йȣ Ȯ ޾Ƶδ. Ʒ user ̺ ʵ尪 ִ: Host ȣƮ ̸̳ IP Ǵ ȣƮ Ű 'localhost' ̴. Host ʵ忡 '%' '_' ϵī ڸ ִ. '%' Host ȣƮ ̸ Ÿ. ȣƮ '%' . Ư ȣƮ ̷ ִٴ . ϵī ڴ User ʵ忡 ʴ´. ׷ شϴ ִ. Ϸ Ͽ ̸ ִٸ Ŭ̾Ʈ ̸ ſ ڴ , ̸ ڷμ ֵȴ. Password ʵ ִ.̰ ƹ йȣ ִٴ ǹϴ ƴϸ ڴ йȣ ʰ ؾ Ѵٴ ǹ̴. Ʒ ̺ û ϴ "user" ̺ Host, User  յǴ ִ ̴: +--------------------------+---------------------------------------+ | ȣƮ/ | Ͽ شϴ | +--------------------------+---------------------------------------+ | 'thomas.loc.gov'/'fred' | thomas.loc.gov ϴ fred | +--------------------------+---------------------------------------+ | 'thomas.loc.gov'/'' | thomas.loc.gov ϴ | | | | +--------------------------+---------------------------------------+ | '%'/'fred' | ȣƮ ϴ fred | +--------------------------+---------------------------------------+ | '%'/'' | ȣƮ ϴ | +--------------------------+---------------------------------------+ | '%.loc.gov'/'fred' | loc.gov ȣƮ | | | ϴ fred | +--------------------------+---------------------------------------+ | 'x.y.%'/'fred' | x.y.net, x.y.com, x.y.edu  | | | ϴ fred (̰ Ƹ | | | ̴) | +--------------------------+---------------------------------------+ | '144.155.166.177'/'fred' | 144.155.166.177 IP ּҿ | | | ϴ fred | +--------------------------+---------------------------------------+ | '144.155.166.%'/'fred' | 144.155.166 Ŭ C | | | ȣƮ ϴ fred | +--------------------------+---------------------------------------+ Host ʵ忡 IP ϵ ī带 ֱ ( '144.155.166.%' ȣƮ ȴ) 144.155.166.somewhere ȣƮ ̸ ̿Ͽ δϰ ̿ ɼ ִ. ̷ mysql ڿ Ʈ(.) ϴ ȣƮ̸ ʴ´. 1.2.foo.com ȣƮ ̷ ȣƮ̸ (grant) ̺ Host ÷ ġ ´. IP ڸ IP ϵ ī ġų ִ. Ѱ ̻ user table ִٸ  user table ұ? ̷ 쿡 user table ذ ϸ , Ҷ ȴ. user table ٰ : +---------------------+-------------+-------------+ | Host | User | ... | +---------------------+-------------+-------------+ | % | root | ... | +---------------------+-------------+-------------+ | % | jeffrey | ... | +---------------------+-------------+-------------+ | localhost | root | ... | +---------------------+-------------+-------------+ | localhost | | ... | +---------------------+-------------+-------------+ ̺ , Ưϰ ִ ȣƮ Ѵ. (Host ÷ '%' " ȣƮ" ǹϿ ּѵ ϴ ̴) Ͽ ȣƮ Ưϰ ڰ ִ ͺ Ѵ.( Ǿ ִ User " " ǹϿ ּѵ ϴ ̴.) ̷ ϸ user ̺ : +---------------------+-------------+-------------+ | Host | User | ... | +---------------------+-------------+-------------+ | localhost | root | ... | +---------------------+-------------+-------------+ | localhost | | ... | +---------------------+-------------+-------------+ | % | jeffrey | ... | +---------------------+-------------+-------------+ | % | root | ... | +---------------------+-------------+-------------+ Ī ˰ Ǹ ĪǴ . localhost jeffrey ϷҶ, Host ÷ 'localhost' Īȴ. ̸ ϴ ȣƮӰ ̸ Īȴ. ('%'/'jeffrey' Ī ȴ. ׷ ̺ ó ĪǴ ƴϴ.) ٸ ִ. user ̺ ٰ غ: +---------------------+-------------+-------------+ | Host | User | ... | +---------------------+-------------+-------------+ | % | jeffrey | ... | +---------------------+-------------+-------------+ | thom | as.loc.gov | ... | +---------------------+-------------+-------------+ ̺ : +---------------------+-------------+-------------+ | Host | User | ... | +---------------------+-------------+-------------+ | thom as.loc.gov | | ... | +---------------------+-------------+-------------+ | % | jeffrey | ... | +---------------------+-------------+-------------+ ù° thomas.loc.gov jeffrey ϴ ĪǸ, whitehouse.gov jeffrey ϴ ι° Ī ȴ. , user ̺ Ͽ  ĪǴ ϸ ȴ. 6.6 , 2ܰ : û Ǿٸ 2ܰ . Ǿ 䱸 ڰ Ϸ Ͽ ڰ ִ Ѵ. ⼭ ̺ ʵ尡 ۵Ѵ. user, db, host, table_priv, columns_priv ̺ Ѵ. GRANT REVOKE ̿Ͽ ̺ ٷ ִ. 7.25 [GRANT] . ( Ҵ ̺ ʵ ϴ ̴; 6.4[Privilege] .) user ̺ ڿ ü ϸ Ͱ  ʹ . , user ̺ ڿ delete ߴٸ ȣƮ  ͺ̽ ڵ ִ! ٸ ؼ user ̺ ̸, ( ͺ̽ )Ը user ̺ ϴ . ٸ ڿԴ user ̺ 'N' ϰ, db host ̺ Ͽ Ư ͺ̽ ѽ ϴ° . db host ̺ Ư ͺ̽ Ѵ. ̺ Host Db ʵ忡 ϵī '%' '_' ̸ ʵ (scope fields) Ѵ. '%' Host " ȣƮ" ǹѴ. db ̺ Host ̸ "host ̺ ڼ ϶" ǹ̴. A '%' or blank Db value in the host table means or "any database." (** or 𸣰ڳ׿. host ̺ Db '%' Ǵ ̸ " ͺ̽" ǹѴٴ **) User ̸ ͸ ڷ ֵȴ. db host ̺ а Ѵ.(ÿ user ̺ д´.) db ̺ Host, Db, User ʵ host ̺ Host, Db ʵ Ѵ. user ̺ Ưϰ Ǿ ִ ǰ ּѵ ߿ ȴ. ĪǴ ã, ߰ Ѵ. tables_priv columns_priv ̺ Ư ̺ ÷ õ Ѵ.db host ̺ Host ʵ ϵī带 Host ʵ忡 ִ. ׷ Db, Table_name, Column_name ʵ忡 ϵī峪 鰪 . Host ̺ ϵī带 tables_priv columns_priv ̺ db ̺ ϰ Ǹ . û Ʒ Ѵ. - ҽ ڵ忡 ģϴٸ, ⼭ ϴ ڵ忡 ˰ ణ ٸٴ ִ.⼭ ڵ尡 ۵ϴ İ ϴ. ϰ ϴµ ̰ ִ ̴. û ؼ(shutdown, reload ) user ̺ üũ Ѵ. ֳĸ user ̺ ϱ . Ͽ û ϸ Ǹ ƴ 쿡 źεȴ. , mysqladmin shutdown ϰ ϴµ user ̺ Ͽ ڿ shutdown , db host ̺ üũ ʴ źεȴ. (̷ ̺ Shutdown_priv ÷ ̷ ʿ䵵 ) ͺ̽ õ û (insert, update ) user ̺ Ͽ ü() Ѵ. Ͽ û ϸ εȴ. user ̺ ü ϸ, db host ̺ Ͽ ͺ̽ õ Ѵ: 1. db ̺ ĪǴ Host, Db, User ʵ带 ã´. ȣƮ ̸ Mysql ̸ Host User Ī . ڰ ϱ ϴ ͺ̽ Db ʵ忡 Īȴ. Host User źεȴ. 2. ĪǴ db ̺ ְ Host ʵ尡 ƴϸ, ͺ̽ Ѵ. 3. ĪǴ db ̺ Host ʵ尡 ̸, host ̺ ȣƮ ͺ̽ ִ ǴѴٴ ǹѴ. ̷ , ڼ host ̺ ĪǴ Host Db ʵ带 ã´. host ̺ ĪǴ źεȴ. ĪǴ ͺ̽ db host ̺ Ͽ intersection Ͽ ȴ. (** insertection ϸ . and **) ٽ , db host ̺ 'Y' Ǿ ȴ.̷ db ̺ Ϲ , ׷ host ̺ host Ͽ ִ.) db host ̺ ̿ ͺ̽ õ , ̷ user ̺ ü ѿ ߰Ѵ. û ϸ ȴ. ٸ , tables_priv columns_priv ̺ ̺ ÷ ϰ ѿ ߰Ѵ. ǰų źεȴ. ü Ʈ ѿ ͺ̽, ̺, ÷ õ ߰ϴ Ȯ ʴ.... ̷ ʱ⿡ û 꿡 Ͽ ϴ... (It may not be apparent why the server adds the database-, table- and column-specific privileges to the global user entry privileges for those cases in which the user privileges are initially found to be insufficient for the requested operation.) û Ѱ ̻ ʿϱ ̴. , INSERT ... SELECT insert select ʿϴ. user ̺ Ѱ ϰ db ̺ Ʈ ٸ ̴. ̷ , ڴ ̷ û ϱ ʿ ִ. ׷ ü ٸ ̺ ؼ ..... (In this case, you have the necessary privileges to perform the request, but the server cannot tell that from either table by itself;) ; Ʈ ε յǾ Ѵ. host ̺ "" ϴµ ִ. TcX , host ̺ Ʈ ý ԵǾ ִ. ⼭ ȴ. ʴ ȣƮ Ű host ̺ ִ. ϴٰ ʴ ġ public.your.domain ý ִٰ غ. ڴ Ʈ ȣƮ , host ̺ Ʈ ý۸ Ѵ : +----------------------+------+-----------------------------------+ | Host | Db | ... | +----------------------+------+-----------------------------------+ | public.your.domain | % | ... (all privileges set to 'N') | +----------------------+------+-----------------------------------+ | %.your.domain | % | ... (all privileges set to 'Y') | +----------------------+------+-----------------------------------+ 翬 ϴ´ Ǿ ִ ̺ ׽ؾ Ѵ. ( mysqlaccess ) 6.7 mysqld , ̺ ޸𸮷 ö󰡰 ̶ ȿϰ ȴ. GRANT, REVOKE, SET PASSWORD ̿ ̺ ϸ ٷ ν Ѵ. ̺ ߴٸ(INSERT, UPDATE Ͽ), ̺ 簡ϵ ϱ FLUSH PRIVIEGES ̳ mysqladmin flush-privileges ؾ Ѵ.׷ ٽ ϱ ʴ´. ̺ Ǿٴ , ̹ ϴ Ŭ̾Ʈ ޴´: 1. ̺ ÷ Ŭ̾Ʈ û ȴ. 2. ͺ̽ USE db_name ɺ ȴ. 3. ü Ѱ йȣ Ŭ̾Ʈ ȴ. 6.8 ʱ mysql Ѽ mysql ġϰ , mysql_install_db ũƮ ؼ ʱ ؾ Ѵ. 4.7.1 [Quick install] . mysql_install_db ũƮ mysqld ϰ, ̺ ȭѴ: - mysql root ڴ ̸ ִ. ȣƮ ִ. : ó root йȣ ִ. ׷ йȣ root ְ ι޴´. - ͸ ڴ 'test' 'test_' ϴ ͺ̽ ι޴´. ڰ ȣƮ ͸ ڷ ֵȴ. - ٸ źεȴ. Ϲ ڴ mysqladmin shutdown ̳ mysqladmin processlist . ġ ʱ а Ǿ ֱ mysql root йȣ ؾ Ѵ. ϸ ȴ. (PASSWORD() Լ ̿ йȣ ؾ Ѵ!): shell> mysql -u root mysql mysql> UPDATE user SET Password=PASSWORD('new_password') WHERE user='root'; mysql> FLUSH PRIVILEGES; or shell> mysqladmin -u root password new_password (** PASSWORD() Լ ʾƵ ǹǷ . SQL grant ̿ **) ù° ϸ user ̺ йȣ ƮѴ. ٽ ̺ е ؾ Ѵ.(FLUSH PRIVILEGES ). ֳϸ ٸ δ ˸ ̴. (** ̺ ٽ ʾƼ ߴ йȣ ȵǴ 찡 Դϴ. ϰ ־ؿ **) root йȣ Ǿ root Ҷ йȣ ؾ Ѵ. ߰ ¾ ϰų ׽Ʈ йȣ ʿ䰡 root йȣ ܵΰ ̴. ׷ ۾ ϱ ݵ йȣ ߴ Ȯؾ Ѵ. ⺻  ϴ mysql_install_db ũƮ 캸. ڿ  ̰ ⺻ ִ. Ͱ ٸ ʱ ϱ ϸ, mysql_install_db ũƮ ϱ ϸ ȴ. ϰ ̺ ٽ mysql ͺ̽ ϴ 丮 '*ISM' '*.ISD' ؾ Ѵ. ( 丮 database 丮 'mysq''̶ ̸ پִ. mysqld --help database 丮 ִ.) ϴ´ mysql_install_db ũƮ . 6.9 mysql ο ߰ϱ ΰ ڸ ߰ ִ : GRANT Ǵ mysql ̺ . GRANT ϴ ȣǴ ̴. Ʒ ο ڸ ϱ  mysql Ŭ̾Ʈ ϴ ش. ߴͰ ⺻ ϴ Ѵ. ̰ ٲٱ mysqld ǰ ִ ýۿ ־ Ѵٴ Ѵ. (**ʱⰪ localhost ϹǷ**) mysql root ڷ ؾ ϰ root ڴ mysql ͺ̽ insert Ѱ reload ־ Ѵ. root йȣ ٲپ, Ʒ mysql ¿ йȣ ؾ Ѵ. GRANT ̿ ο ڸ ߰ ִ: shell> mysql --user=root mysql mysql> GRANT ALL PRIVILEGES ON *.* TO monty@localhost IDENTIFIED BY 'something' WITH GRANT OPTION; mysql> GRANT ALL PRIVILEGES ON *.* TO monty@"%" IDENTIFIED BY 'something' WITH GRANT OPTION; mysql> GRANT RELOAD,PROCESS ON *.* TO admin@localhost; mysql> GRANT USAGE ON *.* TO dummy@localhost; GRANT ڸ Ѵ: monty : ִ йȣ ؾ Ѵ. 츮 monty@localhost monty@"%" GRANT ؼ ݵ Ǹ ؾ Ѵ. localhost ߰ , mysql_install_db localhost ͸ (?) ȣƮ Ҷ 켱 ´. ֳϸ Host ʵ ̴. (** Ư Host ͺ ϴ . admin : йȣ localhost reload process ι . ̰ ڰ mysqladmin processlist Ӹ ƴ϶ mysqladmin reload, mysqladmin refresh, mysqladmin flush-* ִ.ͺ̽ õ ε ʾҴ. ̰ ߰ GRANT ߿ ִ. dummy : йȣ localhost . (privilege type) USAGE ̱ ü 'N' Ǿ ִ. USAGE ƹ ѵ ʴ´. ߿ ͺ̽ õ ִ. INSERT ߰ ̰쿡 ̺ ٽ е ˷־ Ѵ.(**FLUSH PRIVILEGES **) shell> mysql --user=root mysql mysql> INSERT INTO user VALUES('localhost','monty',PASSWORD('something'), 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y') mysql> INSERT INTO user VALUES('%','monty',PASSWORD('something'), 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y') mysql> INSERT INTO user SET Host='localhost',User='admin', Reload_priv='Y', Process_priv='Y'; mysql> INSERT INTO user (Host,User,Password) VALUES('localhost','dummy',"); mysql> FLUSH PRIVILEGES; mysql 'Y' ٸ ִٴ . 3.22.11 Ŀ ִ Ȯ INSERT ⼭ admin ڿ Ǿ. ϱ ʵ带 'Y' user ̺ ϸ ȴٴ . db host ̺ ʿ. (** db host ̺ . db ִ ͺ̽ ϰ ϰ host ̺ db̺ ϰ ϱ ʿ ̴. user ̺ õǾִ **) INSERT (dummy ) user ̺ ÷ Ȯ ʾҴ. ֳĸ ÷ ⺻ 'N' Ǿ ֱ . custom ̶ ڸ ߰Ѵ. custom localhost, server.domain, whitehouse.gov ִ. localhost bankaccount ͺ̽ whitehouse.gov expenses ͺ̽, ȣƮ󿡼 customer ͺ̽ ϱ Ѵ. ȣƮ󿡼 stupid йȣ ϱ Ѵ. GRANT ̿ ̷ ϱ : shell> mysql --user=root mysql mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON bankaccount.* TO custom@localhost IDENTIFIED BY 'stupid'; mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON expenses.* TO custom@whitehouse.gov IDENTIFIED BY 'stupid'; mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON customer.* TO custom@'%' IDENTIFIED BY 'stupid'; ̺ Ϸ . ( FLUSH PRIVILEGES ؾ Ѵٴ ): shell> mysql --user=root mysql mysql> INSERT INTO user (Host,User,Password) VALUES('localhost','custom',PASSWORD('stupid')); mysql> INSERT INTO user (Host,User,Password) VALUES('server.domain','custom',PASSWORD('stupid')); mysql> INSERT INTO user (Host,User,Password) VALUES('whitehouse.gov','custom',PASSWORD('stupid')); mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv, Create_priv,Drop_priv) VALUES ('localhost','bankaccount','custom','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 ('whitehouse.gov','expenses','custom','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('%','customer','custom','Y','Y','Y','Y','Y','Y'); mysql> FLUSH PRIVILEGES; ó INSERT custom ڰ йȣ Ͽ پ ȣƮ ֵ user ̺ ߰Ѵ. ׷  ۹̼ǵ ʴ´. ( ⺻ 'N' ) INSERT ȣƮ , custom bankaccount, expenses, customer ͺ̽ ϴ db ̺ ߰Ѵ. Ϲ ̺ , ϱ ̺ ٽ е ־ Ѵ. Ư ڰ Ư ýۿ ֵ ϰ Ѵٸ, GRANT ִ: mysql> GRANT ... ON *.* TO myusername@"%.mydomainname.com" IDENTIFIED BY 'mypassword'; ̺ Ϸ Ѵ: mysql> INSERT INTO user VALUES ('%.mydomainname.com', 'myusername', PASSWORD('mypassword'),...); mysql> FLUSH PRIVILEGES; ~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ ̺ ٷ xmysqladmin, mysql_webadmin, xmysql α ִ. http://www.mysql.com/Contrib ̷ ƿ Ƽ ã ִ. 6.10 йȣ ߿ Ģ ش : INSERT UPDATE ƴ йȣ ݵ ȣȭϱ PASSWORD() Լ ؾ Ѵ!! user ̺ йȣ ÷ؽƮ(**Ϲ ؽƮ **) ƴ϶ ȣȭ · ϱ ̴. ̷ ؾ йȣ Ϸ ̴: shell> mysql -u root mysql mysql> INSERT INTO user (Host,User,Password) VALUES('%','jeffrey','bLa81m0'); mysql> FLUSH PRIVILEGES; ÷ؽƮ 'bLa81m0' user ̺ йȣ .jeffrey ڰ йȣ Ϸ mysql Ŭ̾Ʈ йȣ ȣȭؼ . ȣȭ йȣ('bLa81m0' ƴϴ) user ̺ йȣ (÷ؽƮ 'bLa81m0' ̴) Ѵ. 񱳴 ϰ źѴ: shell> mysql -u jeffrey -pbLa81m0 test Access denied йȣ user ̺ Էµ ݵ ȣȭǾ ϱ , INSERT ؾ Ѵ: mysql> INSERT INTO user (Host,User,Password) VALUES('%','jeffrey',PASSWORD('bLa81m0')); SET PASSWORD PASSWORD() Լ ؾ Ѵ: mysql> SET PASSWORD FOR jeffrey@"%" = PASSWORD('bLa81m0'); : PASSWORD() Լ йȣ ȣȭ Ѵ. ׷ н йȣ ȣȭϴ ٸ. н йȣ mysql йȣ PASSWORD() н йȣ (** /etc/passwd **) ȣȭǾ ٰ ϸ ȴ. GRANT ... IDENTIFIED BY ̳ mysqladmin password ȣ ϸ PASSWORD() Լ ʿ. Ѵ йȣ ȣȭ Ѵ: mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'bLa81m0'; shell> mysqladmin -u jeffrey password bLa81m0 (** , GRANT ̳ mysqladmin password ϴ° ϰ ? mysql ȣȭ ˰ н ٸ н mysql ڴ ٸٴ ͵ ٽ ѹ ϰ ־ մϴ.**) 6.11 ź mysql Ϸ ź , Ʒ ϴ Ϳ ذ ã ִ: - ʱ ̺ ϱ mysql ġ mysql_install_db ũƮ Ͽ°? ʾҴٸ ũƮ . 6.8 [Default privileges] . ̿ ʱ ִ: shell> mysql -u root test ̴. mysql ͺ̽ 丮 'user.ISD' ִ Ȯغƾ Ѵ. (Ϲ 'mysql ġ 丮/var/mysql/user.IDS' ̴) - ġ ϰ , ϰ ڿ Ѵ: shell> mysql -u root mysql ʱ⿡ mysql root ڸ йȣ . ȹ ֱ , ٸ mysql ڸ ϱ root йȣ ؾ Ѵ. root Ϸϴµ ٰ : Access denied for user: '@unknown' to database mysql ̰ user ̺ User ÷ = root , mysqld Ŭ̾Ʈ ȣƮ̸ ؼ ٴ ǹѴ. ̷ --skip-grant-tables ɼ ̿ ٽ ؾ ϰ '/etc/hosts' ϰų '\windows\hosts' Ͽ ȣƮ ߰ؾ Ѵ. - 3.22.11 3.22.11̳ Ʈߴٸ, mysql_fix_privilege_tables ũƮ ߴ°? ʾҴٸ . mysql 3.22.11 GRANT 鼭 ̺ ٲ. - (INSERT UPDATE ) ̺ ư ȭ ݿ ̸, FLUSH PRIVILEGES ϰų mysqladmin flush-privileges ̺ ٽ е ؾ Ѵٴ .׷ ϱ ȭ ݿ ʴ´. root йȣ ϰ flush ϱ йȣ ʿ䰡 . ֳĸ йȣ ٲپ 𸣱 ̴. - ߰ ̸ ٲپ ̴. ̺ ϴ ο Ŭ̾Ʈ ӿ ġ ̹ ϰ ִ 6.7 [Privileges changes] Ѵ ģ. - ϱ , mysqld --skip-grant-tables ɼ ־ . ׷ mysql ̺ ְ Ȱ ϴ ۵ϴ üũϴ mysqlaccess ũƮ ִ. ϴ´ Ǿ mysqld ο ̺ mysq1admin flush-priveleges Ѵ. : ̺ εϴ --skip-grant-tables ɼ ȿȭ Ѵ. ̸ ٿŰ ٽ ʰ ̺ ִ. - , Python, ODBC α׷ ϴµ ִٸ, mysql -u user_name db_name Ǵ mysql -u user_name -pyour_pass db_name õغ. (-p йȣ̿ ٴ . --password=your_pass ·ε ִ) mysql Ŭ ̾Ʈ Ǹ α׷ ִ ̸ ѿ . - йȣ ۵ , INSERT, UPDATE, SET PASSWORD йȣ ϸ鼭 PASSWORD() Լ ݵ ؾ Ѵٴ . PASSWORD() Լ GRANT ... INDENTIFIED BY ̳ mysqladmin password ߴٸ ʿϴ. 6.10 [Passwords] . - localhost ȣƮ ̸ ̴. ȣƮ ϰ Ŭ̾Ʈ Ϸ ȣƮ ⺻̴. MIT-pthreads ϴ ýۿ localhost ۵ ʴ´. (localhost н . MIT-pthreads н ʴ´.) ̿ ýۿ Ϸ, ȣƮ ̸ Ȯϰ ֱ --host ɼ ؾ Ѵ. ׷ mysqld TCP/IP . ̰, ȣƮ user ̺ Ͽ ȣƮ̸ ־ Ѵ. ( ȣƮ Ŭ̾Ʈ α׷ Ѵٰ ϴ ̴.) - mysql -u user_name db_name ͺ̽ Ϸ ź , user ̺ ̴. mysql -u root mysql Ͽ ϰ SQL : mysql> SELECT * FROM user; ⼭ ȣƮ̸ mysql ̸ ´ Host User ԵǾ ־ Ѵ. - Access denied ޽ Ϸ ڿ ȣƮ ̸, ׸ йȣ ߴ θ ̴. Ϲ user ̺ ޽ ȣƮ ̸ ̸ Ȯϰ ´ ־ Ѵ. - ٸ ýۿ mysql ޽ , user ̺ Ϸ ϴ ȣƮ ̸ ٴ Ѵ: Host ... is not allowed to connect to this MySQL server ( ȣƮ!) ƿƼ mysql Ͽ user ̺ ϰ ϴ /ȣƮ ̸ ߰Ͽ ذ ִ. mysql 3.22 ϰ ʰ ϰ ϴ ý IP ڳ ȣƮ ̸ 𸥴ٸ, user ̺ Host ÷ '%' Էϰ ýۿ --log ɼ mysqld . Ŭ̾Ʈ ýۿ õ mysql α׿  ߴ ִ. (׷ '%' α׿ ȣƮ ̸ ٲ۴. ׷ ȿ ִ.) - mysql -u root test ۵ ϴµ mysql -h your_hostname -u root test ٿ , user ̺ Ȯ ȣƮ ̸ ̴. Ϲ user ̺ Host ȣ Ʈ ̸(** ȣƮ ̸ **)  ִµ ý ؼ ƾ FQDN(fully-qualified domain name - ** ̸ ȣƮ ̸ **) óϴ ̴(Ǵ ٷ ؼ). , user ̺ ȣƮ ̸ 'taejun' Ǿ ִµ, DNS mysql ȣƮ ̸ 'taejun.subnet.se' ˷ ̰ ۵ ̴. user ̺ Host ÷ μ شϴ IP ڳ ȣƮ ̸ . (, user ̺ Host ϵī ڸ ִ. , 'taejun.%'. ׷ ȣƮ̸ '%' ϴ ʴ´!) - mysql -u user_name test ۵ϴµ mysql -u user_name other_db_name ۵ ʴ´ٸ db ̺ other_db_name ̴. - ýۿ mysql -u user_name db_name ۵ ϴµ, ٸ Ŭ̾Ʈ ýۿ mysql -u user_name db_name ۵ ʴ ٸ, user ̺̳ db ̺ Ŭ̾Ʈ ý ̴. - Access denied ذ ϸ, user ̺ ϵ ī('%' Ǵ '_') ϰ ִ Host . ſ Ϲ Host='%' ׸ User='some user' Է , ̷ ϸ ýۿ localhost ֵ Ѵٰ ϴ ̴. ̰ ۵ ʴ ⺻ ѿ Host='localhost' User='' ԵǾ ֱ . Host '%' и 'localhost' ֱ , localhost ο Ϻ ȴ. Ȯ ι° ׸ Host='localhost' User='some_user' Էϰų Host='localhost' User='' ϴ ̴. - : Access to database denied db host ̺ ̴. db ̺ Ͽ Host ÷ ִٸ, host ̺ db ̺ Ͽ Ǵ ȣ Ʈ ̸ ִ Ȯؾ Ѵ. (** Ϲ db ̺ host δ , host ̺ ϴ ȣƮ ִ **) - : Access to database denied SELECT ... INTO OUTFILE Ǵ LOAD DATA INFILE SQL ϴ , user ̺ Ͽ file Ǿ ʾ ̴. - ٸ Ͽ , mysqld ɼ . ( , --debug=d,general,query) ׷ ɿ Բ, õϴ ȣƮ ڿ ̴. G.1 [Debugging] . - mysql ̺ ٸ εư ϸƮ ˷߰ڴٰ , mysql ̺ Ͽ ؾ Ѵ. mysqldump mysql ̺ ִ. mysqlbug ƮƮ Ͽ ø. - , mysqld ʰų ߸ ̳ Ʈ Ϸ õϴ : Can't connect to local MySQL server Can't connect to MySQL server on some_hostname mysqld ۵ϴ ps ̿ ȮѴ. ִ Ȯϰ ƾ Ѵ.(Ϲ `/tmp/mysql.sock' ) Ǵ telnet host_name 3306 õغ . ڼ mysqladmin version mysqladmin -h host_name version ִ. ִ mysql Ÿ 丮 α غ. Ŭ̾Ʈ α׷ ̳ ȯ з ͸ ִٴ . ࿡ ʾҴµ Ŭ ̾Ʈ ߸ ⺻ з͸ Ǹ, Ȩ 丮 ȯ溯 '.my.cnf' غ. ⼭ зͿʹ 谡 ý mysql ִ. 4.14.4 [Option files] . Ŭ̾Ʈ ƹ ɼǵ ʾҴµ Access denied ޽ , ɼ ߿ йȣ ʾҴ Ȯ . 4.14.4 [Option files] . 6.12 ũĿ Ͽ mysql ϰ ϴ mysql Ϲ йȣ ؾ Ѵ. йȣ ܼ ؽƮ ۵ ʴ´. /Ŭ̾Ʈ ȣȭ ʴ´; ִ ؽƮ ۵ȴ. ư ϱ (mysql 3.22 ̻ ) ִ. Ȯϰ ϱ ssh ġ ִ. (http://www.cs.hut.fi/ssh ) ̰ ̿ mysql Ŭ̾Ʈ ̿ ȣȭ TCP/IP ִ. mysql ý ϰ ϰ : - mysql ڰ йȣ .  ڰ йȣ 'mysql - u ̸' ̿ ϰ ڷ α ִٴ . ̰ Ŭ̾Ʈ/ ø̼ Ϲ ۵̴. mysql_install_db ũƮ ϱ ũƮ Ͽ йȣ ٲ ִ. Ǵ mysql root йȣ ٲ ϸ ȴ: shell> mysql -u root mysql mysql> UPDATE user SET Password=PASSWORD('new_password') WHERE user='root'; mysql> FLUSH PRIVILEGES; - mysql н root ڷ . mysqld ٸ ڰ ִ. ϰ ϱ mysql̶ н ڸ ִ. ٸ н ڷ mysqld ϸ user ̺ root ̸ ٲ ʿ䰡 . mysqld ٸ н ڰ ϱ mysql.server ũƮ ϸ ȴ. su Ѵ. ڼ 16.7 [Changing mysql user] . - mysqld ִ ڸ ͺ̽ 丮 б/ ִ Ȯ. - ڿ process . mysqladmin processlist ϸ ϴ ִ. ׷Ƿ ̷ ִ ڴ ٸ UPDATE user SET password=PASSWORD(_'no_secure') Ǹ ִ.mysql process ڸ ߰(extra) Ѵ.׷ mysql root ڴ Ϲ Ǿ αϰ ִ. - ڿ file . ̷ ִ ڴ mysqld ִ ý ִ. ϰ ϱ SELECT ... INTO OUTFILE Ǵ ڰ б⸸ ̹ ϴ  . (** file LOAD DATA INFILE , SELECT .. INTO OUTFILE ̿ ϰ ִ Ѵ. ̷ ڴ mysql а ִ а ִ ȴ. Ϲ ڿ ̷ ʿ . ʿ и ִ . 븻. **) - DNS ŷ Ѵٸ Ը ȣƮ̸ IP . ⺻ mysqld --secure ɼ ȣƮ̸ ϰ .  ϵī ڰ Ե ȣƮ̸ Ҷ ؾ Ѵ. - mysql.server ũƮ н root йȣ ִ´ٸ, ũƮ root ֵ ؾ Ѵ. mysqld ɼ Ȱ õǾ ִ: --secure : gethostbyname() ý ݿ ϵ IP ڰ ȣƮ̸ resolve Ͱ Ѵ. ̰  ȣƮ ̸ ķؼ ϴ ư . ɼ ȣƮ̸ ߰Ѵ. ؼϴµ ð ɷ mysql 3.21 ⺻ Ǿ . mysql 3.22 ȣƮ̸ ijϰ ɼ ⺻ Ǿ ִ. (** Լ gethostbyname() ȣƮ ̸ ڷ ޾ ׿ شϴ IP ּ Ÿ شϴ ü ü ͸ ϴ ԼԴϴ. ؼ ȣƮ ̸ ش IP ּҸ ã .**) --skip-grant-tables : ɼ ϸ ý ʴ´. ׷ ڰ ͺ̽ ! (mysqladmin reload Ͽ ̺ ϵ ִ.) --skip-name-resolve : ȣƮ̸ ؼ ʴ´. ̺ Host ÷ ݵ IP ̰ų ȣƮ̾ Ѵ. --skip-networking : Ʈ TCP/IP . mysqld н . ɼ MIT-pthreads ϴ ýۿ ۵ ʴ´. ֳ MIT-pthreads Ű н ʱ ̴. (** ϴ 鿡Դ ? н ϴϱ. ̿ ϰ postgres 6.3 ĺΰ? ⺻ н ٲ. **) 7. MySQL language reference. 7.1 Literals: how to write strings and numbers 7.1.1 Strings A string is a sequence of characters, surrounded by either single quote (`'') or double quote (`"') characters. Examples: 'a string' "another string" Within a string, certain sequences have special meaning. Each of these sequences begins with a backslash (`\'), known as the escape character. MySQL recognizes the following escape sequences: \0 An ASCII 0 (NUL) character. \n A newline character. \t A tab character. \r A carriage return character. \b A backspace character. \' A single quote (`'') character. \" A double quote (`"') character. \\ A backslash (`\') character. \% A `%' character. This is used to search for literal instances of `%' in contexts where `%' would otherwise be interpreted as a wildcard character. \_ A `_' character. This is used to search for literal instances of `_' in contexts where `_' would otherwise be interpreted as a wildcard character. There are several ways to include quotes within a string: A `'' inside a string quoted with `'' may be written as `'''. A `"' inside a string quoted with `"' may be written as `""'. You can precede the quote character with an escape character (`\'). A `'' inside a string quoted with `"' needs no special treatment and need not be doubled or escaped. In the same way, `"' inside a string quoted with `'' needs no special treatment. The SELECT statements shown below demonstrate how quoting and escaping work: mysq> SELECT 'hello', '"hello"', '""hello""', 'hel''lo', '\'hello'; +-------+---------+-----------+--------+--------+ | hello | "hello" | ""hello"" | hel'lo | 'hello | +-------+---------+-----------+--------+--------+ mysql> SELECT "hello", "'hello'", "''hello''", "hel""lo", "\"hello"; +-------+---------+-----------+--------+--------+ | hello | 'hello' | ''hello'' | hel"lo | "hello | +-------+---------+-----------+--------+--------+ mysql> SELECT "This\nIs\nFour\nlines"; +--------------------+ | This Is Four lines | +--------------------+ If you want to insert binary data into a BLOB column, the following characters must be represented by escape sequences: NUL ASCII 0. You should represent this by `\0' (a backslash and an ASCII `0' character). \ ASCII 92, backslash. Represent this by `\\'. ' ASCII 39, single quote. Represent this by `\''. " ASCII 34, double quote. Represent this by `\"'. If you write C code, you can use the C API function mysql_escape_string() to escape characters for the INSERT statement. See section . In Perl, you can use the quote method of the DBI package to convert special characters to the proper escape sequences. See section . You should use an escape function on any string that might contain any of the special characters listed above! 7.1.2 Numbers Integers are represented as a sequence of digits. Floats use `.' as a decimal separator. Either type of number may be preceded by `-' to indicate a negative value. Examples of valid integers: 1221 0 -32 Examples of valid floating-point numbers: 294.42 -32032.6809e+10 148.00 An integer may be used in a floating-point context; it is interpreted as the equivalent floating-point number. 7.1.3 Hexadecimal values MySQL supports hexadecimal values. In number context these acts like an integer (64 bit precision). In string context these acts like a binary string where each pair of hex digits is converted to a character. mysql> SELECT 0xa+0 -> 10 mysql> select 0x5061756c; -> Paul Hexadecimal strings is often used by ODBC to give values for BLOB columns. 7.1.4 NULL values The NULL value means ``no data'' and is different from values such as 0 for numeric types or the empty string for string types. See section 18.15 Problems whit NULL values. NULL may be represented by \N when using the text file import or export formats (LOAD DATA INFILE, SELECT ... INTO OUTFILE). See section 7.15 LOAD DATA INFILE syntax. 7.1.5 Database, table, index, column and alias names Database, table, index, column and alias names all follow the same rules in MySQL: A name may consist of alphanumeric characters from the current character set and also `_' and `$'. The default character set is ISO-8859-1 Latin1; this may be changed by recompiling MySQL. See section 9.1.1 The charater set used for data and sorting. A database, table, index or column name can be up to 64 characters long. An alias name can be up to 256 characters long. A name may start with any character that is legal in a name. In particular, a name may start with a number (this differs from many other database systems!). However, a name cannot consist{{ }} only{{ }} o f numbers. It is recommended that you do not use names like 1e, because an expression like 1e+1 is ambiguous. It may be interpreted as the expression 1e + 1 or as the number 1e+1. You cannot use the `.' character in names because it is used to extend the format by which you can refer to columns (see immediately below). In MySQL you can refer to a column using any of the following forms: +--------------------+---------------------------------------------+ | Column reference | Meaning | +--------------------+---------------------------------------------+ | col_name | Column col_name from whichever table used | | | in the query contains a column of that name | +--------------------+---------------------------------------------+ | tbl_name.col_name | Column col_name from table tbl_name | | | of the current database | +--------------------+---------------------------------------------+ | db_name.tbl | Column col_name from table tbl_name | | _name.col_name | of the database db_name. This form is | | | available in MySQL 3.22 or later. | +--------------------+---------------------------------------------+ You need not specify a tbl_name or db_name.tbl_name prefix for a column reference in a statement unless the reference would be ambiguous. For example, suppose tables t1 and t2 each contain a column c, and you retrieve c in a SELECT statement that uses both t1 and t2. In this case, c is ambiguous because it is not unique among the tables used in the statement, so you must indicate which table you mean by writing t1.c or t2.c. Similarly, if you are retrieving from a table t in database db1 and from a table t in database db2, you must refer to columns in those tables as db1.t.col_name and db2.t.col_name. The syntax .tbl_name means the table tbl_name in the current database. This syntax is accepted for ODBC compatibility, because some ODBC programs prefix table names with a `.' character. 7.1.5.1 Case sensitivity in names In MySQL, databases and tables correspond to directories and files within those directories. Consequently, the case sensitivity of the underlying operating system determines the case sensitivity of database and table names. This means database and table names are case sensitive in Unix and case insensitive in Win32. Note: Although database and table names are case insensitive for Win32, you should not refer to a given database or table using different cases within the same query. The following query would not work because it refers to a table both as my_table and as MY_TABLE: SELECT * FROM my_table WHERE MY_TABLE.col=1; Column names are case insensitive in all cases. Aliases on tables are case sensitive. The following query would not work because it refers to the alias both as a and as A: mysql> SELECT col_name FROM tbl_name AS a WHERE a.col_name = 1 OR A.col_name = 2; Aliases on columns are case insensitive. 7.2 Column types MySQL supports a number of column types, which may be grouped into three categories: numeric types, date and time types, and string (character) types. This section first gives an overview of the types available and summarizes the storage requirements for each column type, then provides a more detailed description of the properties of the types in each category. The overview is intentionally brief. The more detailed descriptions should be consulted for additional information about particular column types, such as the allowable formats in which you can specify values. The column types supported by MySQL are listed below. The following code letters are used in the descriptions: M Indicates the maximum display size. The maximum legal display size is 255. D Applies to floating-point types and indicates the number of digits following the decimal point. Square brackets (`[' and `]') indicate parts of type specifiers that are optional. Note that if you specify ZEROFILL for a column, MySQL will automatically add the UNSIGNED attribute to the column. TINYINT[(M)] [UNSIGNED] [ZEROFILL] A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255. SMALLINT[(M)] [UNSIGNED] [ZEROFILL] A small integer. The signed range is -32768 to 32767. The unsigned range is 0 to 65535. MEDIUMINT[(M)] [UNSIGNED] [ZEROFILL] A medium-size integer. The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215. NT[(M)] [UNSIGNED] [ZEROFILL] A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295. NTEGER[(M)] [UNSIGNED] [ZEROFILL] This is a synonym for INT. BIGINT[(M)] [UNSIGNED] [ZEROFILL] A large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615. Note that all arithmetic is done using signed BIGINT or DOUBLE values, so you shouldn't use unsigned big integers larger than 9223372036854775807 (63 bits) except with bit functions! Note that -, + and * will use BIGINT arithmetic when both arguments are INTEGER values! This means that if you multiply two big integers (or results from functions that return integers) you may get unexpected results if the result is larger than 9223372036854775807. FLOAT(precision) [ZEROFILL] A floating-point number. Cannot be unsigned. precision can be 4 or 8. FLOAT(4) is a single-precision number and FLOAT(8) is a double-precision number. These types are like the FLOAT and DOUBLE types described immediately below. FLOAT(4) and FLOAT(8) have the same ranges as the corresponding FLOAT and DOUBLE types, but their display size and number of decimals is undefined. In MySQL 3.23, this is a true floating point value. In earlier MySQL versions, FLOAT(precision) always has 2 decimals. This syntax is provided for ODBC compatibility. FLOAT[(M,D)] [ZEROFILL] A small (single-precision) floating-point number. Cannot be unsigned. Allowable values are -3.402823466E+38 to -1.175494351E-38, 0 and 1.175494351E-38 to 3.402823466E+38. DOUBLE[(M,D)] [ZEROFILL] A normal-size (double-precision) floating-point number. Cannot be unsigned. Allowable values are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0 and 2.2250738585072014E-308 to 1.7976931348623157E+308. DOUBLE PRECISION[(M,D)] [ZEROFILL] REAL[(M,D)] [ZEROFILL] These are synonyms for DOUBLE. DECIMAL(M,D) [ZEROFILL] An unpacked floating-point number. Cannot be unsigned. Behaves like a CHAR column: ``unpacked'' means the number is stored as a string, using one character for each digit of the value, the decimal point, and, for negative numbers, the `-' sign. If D is 0, values will have no decimal point or fractional part. The maximum range of DECIMAL values is the same as for DOUBLE, but the actual range for a given DECIMAL column may be constrained by the choice of M and D. In MySQL 3.23 the M argument no longer includes the sign or the decimal point. (This is according to ANSI SQL.) NUMERIC(M,D) [ZEROFILL] This is a synonym for DECIMAL. DATE A date. The supported range is '1000-01-01' to '9999-12-31'. MySQL displays DATE values in 'YYYY-MM-DD' format, but allows you to assign values to DATE columns using either strings or numbers. DATETIME A date and time combination. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. MySQL displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format, but allows you to assign values to DATETIME columns using either strings or numbers. TIMESTAMP[(M)] A timestamp. The range is '1970-01-01 00:00:00' to sometime in the year 2037. MySQL displays TIMESTAMP values in YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD or YYMMDD format, depending on whether M is 14 (or missing), 12, 8 or 6, but allows you to assign values to TIMESTAMP columns using either strings or numbers. A TIMESTAMP column is useful for recording the date and time of an INSERT or UPDATE operation because it is automatically set to the date and time of the most recent operation if you don't give it a value yourself. You can also set it to the current date and time by assigning it a NULL value. See section 7.2.6 Date and time types TIME A time. The range is '-838:59:59' to '838:59:59'. MySQL displays TIME values in 'HH:MM:SS' format, but allows you to assign values to TIME columns using either strings or numbers. YEAR A year. The allowable values are 1901 to 2155, and 0000. MySQL displays YEAR values in YYYY format, but allows you to assign values to YEAR columns using either strings or numbers. (The YEAR type is new in MySQL 3.22.) CHAR(M) [BINARY] A fixed-length string that is always right-padded with spaces to the specified length when stored. The range of M is 1 to 255 characters. Trailing spaces are removed when the value is retrieved. CHAR values are sorted and compared in case-insensitive fashion unless the BINARY keyword is given. VARCHAR(M) [BINARY] A variable-length string. Note: Trailing spaces are removed when the value is stored (this differs from the ANSI SQL specification). The range of M is 1 to 255 characters. VARCHAR values are sorted and compared in case-insensitive fashion unless the BINARY keyword is given. See section 7.6.1 Silent column specification changes. TINYBLOB TINYTEXT A BLOB or TEXT column with a maximum length of 255 (2^8 - 1) characters. See section 7.6.1 Silent column specification changes. BLOB TEXT A BLOB or TEXT column with a maximum length of 65535 (2^16 - 1) characters. See section 7.6.1 Silent column specification changes. MEDIUMBLOB MEDIUMTEXT A BLOB or TEXT column with a maximum length of 16777215 (2^24 - 1) characters. See section 7.6.1 Silent column specification changes. LONGBLOB LONGTEXT A BLOB or TEXT column with a maximum length of 4294967295 (2^32 - 1) characters. See section 7.6.1 Silent column specification changes. ENUM('value1','value2',...) An enumeration. A string object that can have only one value, chosen from the list of values 'value1', 'value2', ..., or NULL. An ENUM can have a maximum of 65535 distinct values. SET('value1','value2',...) A set. A string object that can have zero or more values, each of which must be chosen from the list of values 'value1', 'value2', ... A SET can have a maximum of 64 members. 7.2.1 Column type storage requirements The storage requirements for each of the column types supported by MySQL are listed below by category. 7.2.2 Numeric types +--------------------+---------------------------+ | Column type | Storage required | +--------------------+---------------------------+ | TINYINT | 1 byte | +--------------------+---------------------------+ | SMALLINT | 2 bytes | +--------------------+---------------------------+ | MEDIUMINT | 3 bytes | +--------------------+---------------------------+ | INT | 4 bytes | +--------------------+---------------------------+ | INTEGER | 4 bytes | +--------------------+---------------------------+ | BIGINT | 8 bytes | +--------------------+---------------------------+ | FLOAT(4) | 4 bytes | +--------------------+---------------------------+ | FLOAT(8) | 8 bytes | +--------------------+---------------------------+ | FLOAT | 4 bytes | +--------------------+---------------------------+ | DOUBLE | 8 bytes | +--------------------+---------------------------+ | DOUBLE PRECISION | 8 bytes | +--------------------+---------------------------+ | REAL | 8 bytes | +--------------------+---------------------------+ | DECIMAL(M,D) | M bytes (D+2, if M < D) | +--------------------+---------------------------+ | NUMERIC(M,D) | M bytes (D+2, if M < D) | +--------------------+---------------------------+ 7.2.3 Date and time types +--------------------+---------------------------+ | Column type | Storage required | +--------------------+---------------------------+ | DATETIME | 8 bytes | +--------------------+---------------------------+ | DATE | 3 bytes | +--------------------+---------------------------+ | TIMESTAMP | 4 bytes | +--------------------+---------------------------+ | TIME | 3 bytes | +--------------------+---------------------------+ | YEAR | 1 byte | +--------------------+---------------------------+ +--------------------------+--------------------------------------+ | Column type | Storage required | +--------------------------+--------------------------------------+ | CHAR(M) | M bytes, 1 <= M <= 255 | +--------------------------+--------------------------------------+ | VARCHAR(M) | L+1 bytes, where L <= M and | | | 1 <= M <= 255 | +--------------------------+--------------------------------------+ | TINYBLOB, TINYTEXT | L+1 bytes, where L < 2^8 | +--------------------------+--------------------------------------+ | BLOB, TEXT | L+2 bytes, where L < 2^16 | +--------------------------+--------------------------------------+ | MEDIUMBLOB, MEDIUMTEXT | L+3 bytes, where L < 2^24 | +--------------------------+--------------------------------------+ | LONGBLOB, LONGTEXT | L+4 bytes, where L < 2^32 | +--------------------------+--------------------------------------+ | ENUM('value1', | 1 or 2 bytes, depending | | 'value2',...) | on the number of enumeration values | | | (65535 values maximum) | +--------------------------+--------------------------------------+ | SET('value1', | 1, 2, 3, 4 or 8 bytes, depending | | 'value2',...) | on the number of set members | | | (64 members maximum) | +--------------------------+--------------------------------------+ VARCHAR and the BLOB and TEXT types are variable-length types, for which the storage requirements depend on the actual length of column values (represented by L in the preceding table), rather than on the type's maximum possible size. For example, a VARCHAR(10) column can hold a string with a maximum length of 10 characters. The actual storage required is the length of the string (L), plus 1 byte to record the length of the string. For the string 'abcd', L is 4 and the storage requirement is 5 bytes. The BLOB and TEXT types require 1, 2, 3 or 4 bytes to record the length of the column value, depending on the maximum possible length of the type. If a table includes any variable-length column types, the record format will also be variable-length. Note that when a table is created, MySQL may under certain conditions change a column from a variable-length type to a fixed-length type, or vice-versa. See section 7.6.1 Silent column specification changes. The size of an ENUM object is determined by the number of different enumeration values. 1 byte is used for enumerations with up to 255 possible values. 2 bytes are used for enumerations with up to 65535 values. The size of a SET object is determined by the number of different set members. If the set size is N, the object occupies (N+7)/8 bytes, rounded up to 1, 2, 3, 4 or 8 bytes. A SET can have a maximum of 64 members. 7.2.5 Numeric types All integer types can have an optional attribute UNSIGNED. Unsigned values can be used when you want to allow only positive numbers in a column and you need a little bigger numeric range for the column. All numeric types can have an optional attribute ZEROFILL. Values for ZEROFILL columns are left-padded with zeroes up to the maximum display length when they are displayed. For example, for a column declared as INT(5) ZEROFILL, a value of 4 is retrieved as 00004. When asked to store a value in a numeric column that is outside the column type's allowable range, MySQL clips the value to the appropriate endpoint of the range and stores the resulting value instead. For example, the range of an INT column is -2147483648 to 2147483647. If you try to insert -9999999999 into an INT column, the value is clipped to the lower endpoint of the range, and -2147483648 is stored instead. Similarly, if you try to insert 9999999999, 2147483647 is stored instead. If the INT column is UNSIGNED, the size of the column's range is the same but its endpoints shift up to 0 and 4294967295. If you try to store -9999999999 and 9999999999, the values stored in the column become 0 and 4294967296. Conversions that occur due to clipping are reported as ``warnings'' for ALTER TABLE, LOAD DATA INFILE, UPDATE and multi-row INSERT statements. The maximum display size (M) and number of decimals (D) are used for formatting and calculation of maximum column width. MySQL will store any value that fits a column's storage type even if the value exceeds the display size. For example, an INT(4) column has a display size of 4. Suppose you insert a value which has more than 4 digits into the column, such as 12345. The display size is exceeded, but the allowable range of the INT type is not, so MySQL stores the actual value, 12345. When retrieving the value from the column, MySQL returns the actual value stored in the column. The DECIMAL type is considered a numeric type (as is its synonym, NUMERIC), but such values are stored as strings. One character is used for each digit of the value, the decimal point (if D > 0) and the `-' sign (for negative numbers). If D is 0, DECIMAL and NUMERIC values contain no decimal point or fractional part. The maximum range of DECIMAL values is the same as for DOUBLE, but the actual range for a given DECIMAL column may be constrained by the choice of M and D. For example, a type specification such as DECIMAL(4,2) indicates a maximum length of four characters with two digits after the decimal point. Due to the way the DECIMAL type is stored, this specification results in an allowable range of -.99 to 9.99, much less than the range of a DOUBLE. To avoid some rounding problems, MySQL always rounds everything that it stores in any floating-point column to the number of decimals indicated by the column specification. Suppose you have a column type of FLOAT(8,2). The number of decimals is 2, so a value such as 2.333 is rounded to two decimals and stored as 2.33. 7.2.6 Date and time types The date and time types are DATETIME, DATE, TIMESTAMP, TIME and YEAR. Each of these has a range of legal values, as well as a ``zero'' value that is used when you specify an illegal value. Here are some general considerations to keep in mind when working with date and time types: MySQL retrieves values for a given date or time type in a standard format, but it attempts to interpret a variety of formats for values that you supply (e.g., when you specify a value to be assigned to or compared to a date or time type). Nevertheless, only the formats described in the following sections are supported. It is expected that you will supply legal values, and unpredictable results may occur if you use values in other formats. Although MySQL tries to interpret values in several formats, it always expects the year part of date values to be leftmost. Dates must be given in year-month-day order (e.g., '98-09-04'), rather than in the month-day-year or day-month-year orders commonly used elsewhere (e.g., '09-04-98', '04-09-98'). MySQL automatically converts a date or time type value to a number if the value is used in a numeric context, and vice versa. When MySQL encounters a value for a date or time type that is out of range or otherwise illegal for the type, it converts the value to the ``zero'' value for that type. (The exception is that out-of-range TIME values are clipped to the appropriate endpoint of the TIME range.) The table below shows the format of the ``zero'' value for each type: +---------------+------------------------------------+ | Column type | ``Zero'' value | +---------------+------------------------------------+ | DATETIME | '0000-00-00 00:00:00' | +---------------+------------------------------------+ | DATE | '0000-00-00' | +---------------+------------------------------------+ | TIMESTAMP | 00000000000000 | | | (length depends on display size) | +---------------+------------------------------------+ | TIME | '00:00:00' | +---------------+------------------------------------+ | YEAR | 0000 | +---------------+------------------------------------+ The ``zero'' values are special, but you can store or refer to them explicitly using the values shown in the table. You can also do this using the values '0' or 0, which are easier to write. ``Zero'' date or time values used through MyODBC are converted automatically to NULL in MyODBC 2.50.12 and above, because ODBC can't handle such values. 7.2.6.1 Y2K issues and date types MySQL itself is Y2K-safe (see section 1.6 Year 2000 compliance), but input values presented to MySQL may not be. Any input containing 2-digit year values is ambiguous, since the century is unknown. Such values must be interpreted into 4-digit form since MySQL stores years internally using four digits. For DATETIME, DATE, TIMESTAMP and YEAR types, MySQL interprets dates with ambiguous year values using the following rules: Year values in the range 00-69 are converted to 2000-2069. Year values in the range 70-99 are converted to 1970-1999. Remember that these rules provide only reasonable guesses as to what your data mean. If the heuristics used by MySQL don't produce the correct values, you should provide unambiguous input containing 4-digit year values. 7.2.6.2 The DATETIME, DATE and TIMESTAMP types The DATETIME, DATE and TIMESTAMP types are related. This section describes their characteristics, how they are similar and how they differ. The DATETIME type is used when you need values that contain both date and time information. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. (``Supported'' means that although earlier values might work, there is no guarantee that they will.) The DATE type is used when you need only a date value, without a time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'. The TIMESTAMP column type provides a type that you can use to automatically mark INSERT or UPDATE operations with the current date and time. If you have multiple TIMESTAMP columns, only the first one is updated automatically. Automatic updating of the first TIMESTAMP column occurs under any of the following conditions: The column is not specified explicitly in an INSERT or LOAD DATA INFILE statement. The column is not specified explicitly in an UPDATE statement and some other column changes value. (Note that an UPDATE that sets a column to the value it already has will not cause the TIMESTAMP column to be updated, because if you set a column to its current value, MySQL ignores the update for efficiency.) You explicitly set the TIMESTAMP column to NULL. TIMESTAMP columns other than the first may also be set to the current date and time. Just set the column to NULL, or to NOW(). You can set any TIMESTAMP column to a value different than the current date and time by setting it explicitly to the desired value. This is true even for the first TIMESTAMP column. You can use this property if, for example, you want a TIMESTAMP to be set to the current date and time when you create a row, but not to be changed whenever the row is updated later: Let MySQL set the column when the row is created. This will initialize it to the current date and time. When you perform subsequent updates to other columns in the row, set the TIMESTAMP column explicitly to its current value. On the other hand, you may find it just as easy to use a DATETIME column that you initialize to NOW() when the row is created and leave alone for subsequent updates. TIMESTAMP values may range from the beginning of 1970 to sometime in the year 2037, with a resolution of one second. Values are displayed as numbers. The format in which MySQL retrieves and displays TIMESTAMP values depends on the display size, as illustrated by the table below. The `full' TIMESTAMP format is 14 digits, but TIMESTAMP columns may be created with shorter display sizes: +-----------------+------------------+ | Column type | Display format | +-----------------+------------------+ | TIMESTAMP(14) | YYYYMMDDHHMMSS | +-----------------+------------------+ | TIMESTAMP(12) | YYMMDDHHMMSS | +-----------------+------------------+ | TIMESTAMP(10) | YYMMDDHHMM | +-----------------+------------------+ | TIMESTAMP(8) | YYYYMMDD | +-----------------+------------------+ | TIMESTAMP(6) | YYMMDD | +-----------------+------------------+ | TIMESTAMP(4) | YYMM | +-----------------+------------------+ | TIMESTAMP(2) | YY | +-----------------+------------------+ All TIMESTAMP columns have the same storage size, regardless of display size. The most common display sizes are 6, 8, 12, and 14. You can specify an arbitrary display size at table creation time, but values of 0 or greater than 14 are coerced to 14. Odd-valued sizes in the range from 1 to 13 are coerced to the next higher even number. You can specify DATETIME, DATE and TIMESTAMP values using any of a common set of formats: As a string in either 'YYYY-MM-DD HH:MM:SS' or 'YY-MM-DD HH:MM:SS' format. A ``relaxed'' syntax is allowed--any non-numeric character may be used as the delimiter between date parts or time parts. For example, '98-12-31 11:30:45', '98.12.31 11+30+45', '98/12/31 11*30*45' and '98@12@31 11^30^45' are equivalent. As a string in either 'YYYY-MM-DD' or 'YY-MM-DD' format. A ``relaxed'' syntax is allowed here, too. For example, '98-12-31', '98.12.31', '98/12/31' and '98@12@31' are equivalent. As a string with no delimiters in either 'YYYYMMDDHHMMSS' or 'YYMMDDHHMMSS' format, provided that the string makes sense as a date. For example, '19970523091528' and '970523091528' are interpreted as '1997-05-23 09:15:28', but '971122459015' is illegal (it has a nonsensical minute part) and becomes '0000-00-00 00:00:00'. As a string with no delimiters in either 'YYYYMMDD' or 'YYMMDD' format, provided that the string makes sense as a date. For example, '19970523' and '970523' are interpreted as '1997-05-23', but '971332' is illegal (it has nonsensical month and day parts) and becomes '0000-00-00'. As a number in either YYYYMMDDHHMMSS or YYMMDDHHMMSS format, provided that the number makes sense as a date. For example, 19830905132800 and 830905132800 are interpreted as '1983-09-05 13:28:00'. As a number in either YYYYMMDD or YYMMDD format, provided that the number makes sense as a date. For example, 19830905 and