教你如何3分鐘玩轉MYSQL

來源:互聯網
上載者:User

標籤:

操作mysql

1、串連mysql

mysql -u root

2、為root使用者佈建密碼

# mysqladmin -u root -p password "www.1.com"

3、為使用者佈建密碼後,串連mysql

mysql -u root -p

 

4、串連其他伺服器的mysql

mysql -u root -p -h ip地址

5、查看資料庫

show databases;

6、切換資料庫

use 資料庫名稱;

7、查看資料表

show tables;

8、查看錶的結構

desc [表名];   

9、建立資料庫

註:此處如果加入完整性條件約束條件請參考部落格:http://www.cnblogs.com/renfanzi/p/5613235.html

create database [資料庫名稱];drop database [資料庫名稱];

10、建立資料表

create table [表名](欄位1 類型 [參數],欄位2 類型 [參數]);drop table [表名];
資料管理——增、刪、改、查

註:此處如果加入完整性條件約束條件請參考部落格:http://www.cnblogs.com/renfanzi/p/5613235.html

1)        添加資料

insert into 表名 values(值1,值2,值3);insert into 表名(欄位名,欄位名)  values (值1,值2);注意:如果欄位類型是char或者varchar,欄位值要用單引號括起來

2)        刪除資料

delete from [表名];delete from student where sex=‘W‘;

3)        修改資料

update 表名 set 欄位名=值 where 條件;

4)        查詢資料

select * from 表名;select 欄位名,欄位名 from student;select * from student where name=‘lisi‘ and sex=‘M‘;select * from student where name=‘lisi‘ or sex=‘M‘;
資料庫管理

1)        許可權管理

授權

grant 許可權 on 庫名.表名 to ‘使用者名稱‘@‘IP地址‘ identified by ‘密碼‘;       許可權:select,update,delete,insert          all代表所有許可權       IP地址:‘192.168.1.1‘                   ‘192.168.1.%‘    grant select on s284.student to ‘admin‘@‘localhost‘ identified by ‘www.1.com‘;# mysql -u admin -h 10.1.1.1 -p

查看授權

show grants for ‘tom‘@‘localhost‘;

撤銷授權

revoke 許可權 on 庫名.表名 from ‘使用者名稱‘@‘來源地址‘;

2)        Database Backup

備份庫中的表

mysqldump -u root -p 庫名 表名1 表名2 >備份路徑、名稱

備份整個庫

mysqldump -u root -p --database 庫名1 庫名2 >備份路徑、名稱

備份所有資料庫

mysqldump -u root -p --all-databases >備份路徑、名稱

3)        資料庫恢複

a)        在mysql裡建立出同名資料庫b)        恢複命令              mysql -u root -p 庫名 <備份路徑、名稱

 

教你如何3分鐘玩轉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.