mysql經常使用的命令

來源:互聯網
上載者:User

標籤:

如何登陸資料庫
    飛機著陸
    mysql -u <username> -p

    訪問本機資料庫
    mysql -u <username> -D <database_name> -p

    登陸遠程某個資料庫
    mysql -h <hostname> -u <username> -D <database_name> -p
    
    登陸遠程某個資料庫,從特定port
    mysql -h <hostname> -P <port> -u <username> -D <database_name> -p

怎樣運行sql指令碼
    mysql > source <scriptname.sql>

怎樣參看有哪些庫
    show databases
    
怎樣切換資料庫
    use <database_name>

怎樣參看庫中有哪些表
    show tables
    
怎樣查看正在使用哪個資料庫

    status

查看資料狀態,參數

show status

改動mysqlpassword
mysqladmin -u root -p password {new_password}

同意mysql遠端連線
update user set host = ‘%‘ where user = ‘root‘;

查詢表定義
show create table {table_name};

show columns from {table_name};

describe {table_name};



建立資料庫
    create database {databas_name}

刪除資料庫
    drop database {databas_name}

建立表
    create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)

    create table table1(
    -> col1 int primary key,
    -> col2 int,
    -> col3 varchar(30),
    -> )
    -> ;

    create table Teacther
    (
    tNo int primary key,
    tName varchar(50) not null,
    tSex  varchar(2) not null check (tsex in (‘男‘,‘女‘)),
    tBirthDate datetime not null,
    tSalary decimal(18,2),
    tHairDate datetime,
    depNo int
    foreign key(depNo) references Depart(depNo)
    )

依據已有的表建立新表
    create table {new_table_name} like {old_table_name}
    create table {new_table_name} as select {[col1_name],[col2_name}, …} from {old_table_name} definition only

插入資料
    insert into {table_name} (field1,field2) values(value1,value2);
    insert into table1 (col1,col2,col3) values(1,1,"aaa");

更新資料
    update {table_name} set {field1}={value1} where {condition};
    update table1 set col3="zzz" where col1=1;

查詢資料
    select {field1,field2} from {table_name} where {condition};
    select * from table1;

    select distinct {column} from {table_name} 顯示唯一值

    select {column} from {table_name} limit {num} 限制檢索的行數

    select {column} from {table_name} limit {num1, num2} 從第num1開始的num2個行

    select {column} from {table_name} order by {column} desc; 按降序排列
    select {column} from {table_name} where {column} between {num1} and {num2} 範圍尋找

    select {column} from {table_name} where {column} is null 尋找空值

    select from where group by having order by limit
刪除資料
    delete from {table_name} where {condition};
    delete from table1 where col1=2;


著作權聲明:本文部落格原創文章。部落格,未經同意,不得轉載。

mysql經常使用的命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.