MYSQLデータベースベース

2823 ワード

MYSQL         

#  [  ]  
mysql -hlocalhost -uroot -p;

#    
mysqladmin -uroot -pold password new;

#     
show databases;

#     
show tables;

#show       
show create database db_name;#      
show create table tb_name\G;#      
show CHARACTER SET LIKE 'latin%';#SHOW CHARACTER SET              。
SHOW ENGINES\G;           ,           ,         。

"\G"          ;

#     
use examples;

 :window        
     utf8,window       gbk,         , set names gbk;

#          utf-8    
create database `examples` default character set utf8 collate utf8_general_ci;

#     
drop database examples;

 :Mysql , /     ,database    . 
phpMyAdmin      ?     ,         ,       . 

#  
         : show tables;
create table test
(
 id int(10) unsigned zerofill not null auto_increment,
 email varchar(40) not null,
 ip varchar(15) not null,
 state int(10) not null default '-1',
 primary key (id)
)engine=InnoDB;

  :
1.         not null default ''/default 0;
 :    null 。
2.null    。
 :    ,null     ,         is null  is not null   。
         null;
select null=null;   null
select null!=null;   null
    ,         。


#   : drop table stu;

#     
describe tb_name
show [full]columns from db_name.tb_name;

#     
truncate tb_name;#     ,                  ,        
delete from tb_name where expir.. #         

#    
alter table test_old rename test_new;
#   
alter table test add birth date not null default '0000-00-00'; 
alter table test add uname varchar(30) not null default '' after id;#  id      
alter table m1 add pid int not null default 0 first; #  first           
#   
--modify     ,  :[alter table    modify           ]
alter table test modify gender char(4) not null default '';
--change       ,  :[alter table    change                ]
alter table test change id uid varchar(10) not null;

#   
alter table test drop pid;

# MySQL         
  MySQL     ,  old_table      new_table  。
1.       ,     。
CREATE TABLE new_table LIKE old_table
2.    SELECT      ,new_table       、     。
  
CREATE TABLE new_table AS
(
    SELECT *
    FROM old_table
)
3.      
CREATE TABLE new_table LIKE old_table;
INSERT INTO new_table SELECT * FROM old_table;
4.      
CREATE TABLE new_table AS
(
    SELECT field1, field2 FROM old_table
)
5.     
CREATE TABLE new_table AS
(
    SELECT * FROM old_table WHERE field1 = test'
)
mysql>tee D:test.sql tee           sql            
mysql        
mysql>use dbtest;
mysql>set names utf8;
mysql>set autocommit=0;
mysql>source D:/www/sql/back.sql;
  source        ,      test.sql  ,         
source d:/a.sql;
source d:/b.sql;
  
mysql>source D:/test.sql;
        source        sql