mysql 5.5.39 基礎操作01

來源:互聯網
上載者:User

標籤:mysql 5.5.39 基礎操作01 create database   revoke grant set select update desc table

1.mysql版本應該怎麼選擇

由於5.5-5.6對mysql效能做了較大最佳化,所以一般選擇mysql 5.5 或者 5.6  


mysql 5.5.xx -5.6.xx 產品的特殊性,所以編譯方式也和早期的產品安裝方式不同,採用cmake或者gmake方式進行編譯安裝。即 ./cmake ; make ; make install ,生產情境的具體命令及參數為詳見mysql 一鍵安裝指令碼 

一鍵安裝指令碼下載連結 http://down.51cto.com/data/2228998 


2.設定mysql的初始密碼

mysql 安裝完畢後是沒有初始使用者名稱密碼的,所以我們要為mysql設定一個初始密碼

mysqladmin -uroot password [email protected]? --(備忘,是mysqladmin,而不是mysql)



3.查看資料庫 

show databases ;


4.使用某個庫

use 庫名 ;


5.查看當前資料庫

select database ();


6.刪除一個庫

drop database test(庫名稱為test) ;


7.使用某個庫

use 庫名 ;


8.進入庫後查看錶

show tables ;


9.查看錶結構

desc table名 ;

或者select * from table 名 



10.查看所有使用者

select host,user from mysql.user ;


11.刪除使用者

一般刪除使用者就用drop ,但是如果名字中有大寫或者特殊字元,drop可能會有問題,會用delete

drop user ‘‘@‘localhost‘;

drop user ""@"localhost.localdomain";
或者
delete from mysql.user  where host="127.0.0.1";

flush privileges;



12.建立使用者並為使用者賦權/建立管理員

grant all on *.* to ‘dailiang‘@‘%‘ identified by ‘[email protected]?‘;

flush privileges;

這樣這個使用者與管理員的差別就是沒有grant許可權 

grant all on *.* to ‘dailiang‘@‘%‘ identified by ‘[email protected]?‘ with grant option;



13.只設定查詢許可權

grant select on *.* to ‘dailiang‘@‘%‘ identified by ‘[email protected]?‘ ;

flush privileges;

grant select on *.* to ‘dailiang‘@‘10.0.0.%‘ identified by ‘[email protected]?‘ ;

表示對10.0.0.x 網段授權


13.查看使用者權限

show grants for ‘dailiang‘@‘%‘;

或者

select * from mysql.user where user=‘dailiang‘\G;



14. 收回許可權之revoke

help revoke;

REVOKE INSERT ON *.* FROM ‘jeffrey‘@‘localhost‘;


15.互動式執行sql,不用登陸資料庫

mysql -uroot [email protected]? -e "show grants for ‘dailiang‘@‘%‘;" 



16.mysql使用者一共18個許可權

Select

Insert

Update

Delete

Create

Drop         

Grant

References 

Index

Alter





17.修改使用者密碼


UPDATE mysql.user SET password=PASSWORD(‘新密碼‘) WHERE user=‘使用者名稱

update mysql.user set password=PASSWORD(‘111‘) where user=‘dailiang‘ and host=‘%‘;

flush privileges;



注意:

1.如果不加WHERE 條件,則會把所有使用者的密碼都修改為’新密碼’

密碼修改完成後,需要進行許可權重新整理操作才會生效,FLUSH PRIVILEGES;

ROOT使用者可以修改自己的密碼,也可以修改其他使用者的密碼

其他使用者只能修改自己的密碼


2.PASSWORD函數

mysql> SELECT PASSWORD(‘111‘);

用於把密碼明文進行加密,所得到的密碼為原密碼的雜湊值。


mysql> SELECT PASSWORD(‘111‘);

+-------------------------------------------+

| PASSWORD(‘111‘)                           |

+-------------------------------------------+

| *832EB84CB764129D05D498ED9CA7E5CE9B8F83EB |

+-------------------------------------------+

1 row in set (0.00 sec)



下文請看:mysql基礎操作02

本文出自 “隱漁” 部落格,請務必保留此出處http://dailiang.blog.51cto.com/9484865/1827496

mysql 5.5.39 基礎操作01

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.