mysql常用語句總結

來源:互聯網
上載者:User

標籤:

1.帳號

串連資料:mysql -h host -u root -p password

修改密碼:mysqladmin -u root -p old_password password new_password

增加使用者:create user ‘user1‘@‘%‘ identified by ‘password‘  

使用者授權:grant select,update,insert,delete on database.table to ‘user1‘@‘%‘  

2.資料庫操作

查所有庫:show databases  

切換數庫:use database_name  

新資料庫:create database database_name  

刪資料庫:drop database database_name  

3.資料表操作

查所有表:show tables  

查表結構:describe table_name  

新資料表:create table (field1 not null auto_increment,field varchar(20) not null,primary key (‘id‘))

刪資料表:drop table_name

轉換儲存:alter database.table engine=‘MyISAM‘

表名修改:alter table old_name rename to new_name  

列出欄位:show field from table like ‘%word%‘  

所有表格:select * from information_schema.tables  

4.記錄操作類

增加記錄:insert into table (field1,field2,field3) values (‘value1‘,‘value2‘,‘value3‘)  

修改記錄:update table set field1=‘value1‘,field2=‘value2‘ where id=1  

刪除記錄:delete from table where id=1  

查詢記錄:select field1,field2,field3 from table where id>0 order by id asc

串連外表:select a.*,b.* from table1 as a join table2 as b on a.id=b.aid

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.