mysql常用命令

來源:互聯網
上載者:User

標籤:

一、串連mysql

本地主機:mysql -h主機地址 -u使用者名稱 -p使用者密碼

遠程主機:mysql -h主機IP -u 使用者名稱 -p 使用者密碼

二、修改密碼

mysqladmin -u使用者名稱 -p舊密碼 password 新密碼

三、建立資料庫

create database <資料庫名>

四、顯示資料庫

show databases

五、刪除資料庫

drop database <資料庫名>

六、串連資料庫

use <資料庫名>

七、選擇當前資料庫

  1、顯示mysql的版本:select version();

  2、顯示目前時間:select now();

  3、顯示年月日:SELECT DAYOFMONTH(CURRENT_DATE);

  4、顯示字串:SELECT "welecome to my blog!";

  5、當計算機用select ((4 * 4) / 10 ) + 25;

  6、串接字串:select CONCAT(f_name, " ", l_name) 
          AS Name 
          from employee_data 
          where title = ‘Marketing Executive‘;

八、建立資料庫

create table <表名> ( <欄位名1> <類型1> [,..<欄位名n> <類型n>]);

例:mysql> create table MyClass(
  > id int(4) not null primary key auto_increment,
  > name char(20) not null,
  > sex int(4) not null default ‘0‘,
  > degree double(16,2));

九、刪除資料庫

drop table <表名>

十、表插入資料

insert into <表名> [( <欄位名1>[,..<欄位名n > ])] values ( 值1 )[, ( 值n )]

十一、查詢表中的資料

select <欄位1,欄位2,...> from < 表名 > where < 運算式 >

分頁如下:select * from MyClass order by id limit 0,2;

十二:刪除表中的資料

delete from 表名 where 運算式

十三:修改表中資料

update 表名 set 欄位=新值,… where 條件

十四:增加欄位

alter table 表名 add欄位 類型 其他;

例:alter table MyClass add passtest int(4) default ‘0‘

十五、修改表名

rename table 原表名 to 新表名;

十六、查詢資料庫中所有的表

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ‘資料庫名

轉載自:http://www.cnblogs.com/zhangzhu/archive/2013/07/04/3172486.html

  

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.