My SQL

參考: 21分鐘MySQL入門教程html

登陸MySQL
  mysql -D DATABASENAME -h HOSTNAME -P PORT -u USERNAME -p
    -D 登陸後進入數據庫,非必選
    -h 指定登陸主機名,登陸當前機器可省略
    -P 端口
    -u 登陸用戶名
    -p 使用密碼登陸,若該用戶沒有設置密碼可省略mysql

建立數據庫
  create database DATABASENAME [other options];
    other options 如character set
查看已建立的數據庫
  show databasessql

選擇所要操做的數據庫
  1、登陸時直接指定
  2、登錄後
    use DATABASENAME;數據庫

建立數據庫表
  create table TABLENAME(columns);
查看已建立的表名稱
  show tables;
查看已建立的表的詳細信息
  describe TABLENAME;post

向表中插入數據
  insert [into] TABLENAME [(COLUMNNAME1, COLUMNNAME2, ...)] values (VALUE1, VALUE2, ...);htm

查詢表中數據
  select COLUMNNAME from TABLENAME [where conditions];
    COLUMNNAME能夠用通配符 * 代替,查詢全部列
    where子句支持=、<、>、<=、>=、!=、is [not] null、in、like、or、and等等blog

更新表中數據
  update TABLENAME set COLUMNNAME = NEWVALUE [where conditions];教程

刪除表中數據
  delete from TABLENAME [where conditions];get

添加表
  alter table TABLENAME add COLUMNNAME DATATYPE [after postion];it

修改列
  alter table TABLENAME change OLDCOLUMNNAME NEWCOLUMNNAME DATATYPE;

刪除列
  alter table TABLENAME drop COLUMNNAME;

重命名錶
  alter table OLDTABLENAME rename NEWTABLENAME;

刪除整張表
  drop table TABLENAME;

刪除數據庫   drop database [if exists] DATABASENAME;

相關文章
相關標籤/搜索