MySQL³£ÓÃÖ¸ÁºÏ
¼ÇÁËһЩÓà Windows µÄÃüÁîÐÐÀ´²Ù×÷ MySQL µÄÖ¸Áî¡£
ÕªÒª
Á¬½á MySQL
->mysql -u username -p
username ÊÇÄãµÄÕʺÅÃû³Æ¡£
Ô¶³ÌÁ¬½á
->mysql -h hostname -u username -p
hostname ÊÇ MySQL Ö÷»úµÄÃû³Æ¡£
ÏÔʾȫ²¿µÄÊý¾Ý¿â
SHOW DATABASES;
mysql ÊÇ MySQL ÓÃÀ´´¢´æÕʺźÍȨÏÞµÄÊý¾Ý¿â£¬²»ÄÜɾ³ý¡£
Ñ¡ÔñÊý¾Ý¿â
USE database_name;
ÏÔʾÊý¾Ý¿âÀïµÄ×ÊÁϱí
SHOW TABLES;
ÏÔʾ×ÊÁϱíµÄÐÅÏ¢
DESCRIBE table_name;
×¢Ïú MySQL ÏÔʾÆ÷
\q
SQL µÄÖ´ÐÐÖ¸Áî¿ÉÒÔ´ÓÎı¾ÎļþÄÚÊäÈë¡£
SOURCE file_name
Èç¹ûûÓеÇÈë MySQL µÄÏÔʾÆ÷£¬Óãº
->mysql -u username -p < file_name
Primary key - ÓÃÀ´Ê¶±ð×Ö¶ÎµÄ key¡£
Foreign key - ´ú±íÁ¬½áµÄ×ÊÁÏ±í¡£ÔÙÁíÒ»¸ö×ÊÁϱíÀïµÄ primary key¡£
ʹÓà MySQL
½¨Á¢Êý¾Ý¿â
CREATE DATABASE employee;
Õâ»á½¨Á¢Ò»¸ö½Ð employee µÄÊý¾Ý¿â¡£
½¨Á¢×ÊÁϱí
CREATE TABLE table_name (table definition) [type=table_type];
ÍêÕû¸ñʽ£º
³ÌÐò´úÂë:
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] table_name [(create_definition, ...)]
[table_options] [select_statement];
or
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] table_name LIKE old_table_name;
create_definition:
col_name TYPE [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
[PRIMARY KEY] [reference_definition]
or PRIMARY KEY (index_col_name,...)
or KEY [index_name] (index_col_name,...)
or INDEX [index_name] (index_col_name,...)
or UNIQUE [INDEX] [index_name] (index_col_name,...)
or FULLTEXT [INDEX] [index_name] (index_col_name,...)
or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...)
[reference_definition]
or CHECK (expression)
TEMPORARY ¹Ø¼ü´ÊÊÇÓÃÀ´½¨Á¢ÔÝʱµÄ×ÊÁÏ±í£¬µ±ÄãµÄÁ¬½á½×¶Î½áÊøºó»á×Ô¶¯É¾³ý¡£
CREATE TEMPORARY TABLE table_name;
IF NOT EXISTS Ö»ÓÐÔÚ×ÊÁÏ±í²»´æÔÚʱ²Å»á½¨Á¢¡£
CREATE TABLE IF NOT EXISTS table_name;
LIKE old_table_name »áÒÀÕÕ old_table_name µÄ¹¹ÔìÀ´½¨Á¢ÐµÄ×ÊÁÏ±í¡£
×ֶζ¨Òå (column definition) ¿ÉÓõÄÑ¡Ï
NOT NULL »ò NULL À´¶¨Òå×ֶβ»ÄÜ°üÀ¨ NULL (NOT NULL) »ò¿ÉÒÔ°üÀ¨ NULL (NULL)¡£
ĬÈÏÖµÊ
Ïà¹ØÎĵµ£º
×î½üÔÚMySQLÉÏ×öÁ˵㹤×÷£¬·¢ÏֺܶàÈ˶¼ÔÚѯÎÊMySQLǶÌײéѯµÄÎÊÌ⣬Ðí¶àÈ˶¼¾õµÃMySQL²»Ö§³ÖǶÌײéѯ£¬ÆäʵMySQl´Ó4.11°æºóÒѾÍêÈ«Ö§³ÖǶÌײéѯÁË£¬ÄÇôÏÂÃæÎÒ¾ÙЩ¼òµ¥µÄǶÌײéѯµÄÀý×Ó°É£¨Ô´³ÌÐòÀ´×ÔMySQL User Manual£©£º
1. SELECTÓï¾äµÄ×Ó²éѯ:
Óï·¨: SELECT ... from (subquery) AS name ...
ÏÈ´´½¨Ò»¸ö±í:
......
ÎҵIJâÊÔ»·¾³.»ù±¾ÉÏÊý¾ÝÊÇ˲¼äͬ²½£¬Ï£Íû¶Ô´ó¼ÒÓаïÖú
redhat 9.0
mysql3.23.57
mysqlÊý¾Ýͬ²½±¸·Ý
A·þÎñÆ÷£º 192.168.1.2 Ö÷·þÎñÆ÷master
B·þÎñÆ÷£º 192.168.1.3 ¸±·þÎñÆ÷slave
A·þÎñÆ÷ÉèÖÃ
#mysql –u root –p
mysql>GRANT FILE ON *.* TO backup@192.168.1 ......
½ñÌìÕÒµ½ÁËÈ¡mysql±íºÍ×Ö¶Î×¢Ê͵ÄÓï¾ä
È¡×Ö¶Î×¢ÊÍ
SELECT COLUMN_NAME ÁÐÃû, DATA_TYPE ×Ö¶ÎÀàÐÍ, COLUMN_COMMENT ×Ö¶Î×¢ÊÍ
from INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'companies'##±íÃû
AND table_schema = 'testhuicard'##Êý¾Ý¿âÃû
AND column_name LIKE 'c_name'##×Ö¶ÎÃû
--------------------------- ......
¹«Ë¾mysqlͳһÓÃlatin1µÄ±àÂ룬ÕæÊǽÐÈ˿಻¿°ÑÔ¡£DjangoÓÃĬÈÏUTF8·ÃÎÊMYSQLÊý¾Ý¿â¡£ÔÚ²Ù×÷Êý¾Ý¿âʱ£¬²»¹ÜÄãÔõôתÂ룬×îÖÕдµ½Êý¾Ý¿âÀïµÄÖÐÎĶ¼ÊÇÂÒÂë¡£ÔÚÍøÉÏÕÒÁ˺ܾã¬Ò²Ã»½â¾öÕâ¸öÎÊÌâ¡£
ºóÀ´¿´ÁËÒ»¸öDJANGOµÄMYSQL²Ù×÷µÄÔ´Â룬·¢ÏÖÁËһЩÎÊÌâ ÏÈÊÇ/d ......