MySQL 5.7 使用者與日誌管理

來源:互聯網
上載者:User

標籤:解決   sql資料庫   top   ima   就是   use   where   erro   time   

說明:
資料庫是資訊系統中非常重要的一個環節,合理高效地對它進行管理是很重要的工作。通常是由總管理員建立不同的管理賬戶,然後分配不同的操作許可權,把這些賬戶交給相應的管理員使用。
由於記錄檔是掌握資料庫運行狀態的重要參考,因此記錄檔的維護也有十分重要的意義。
接下來,就做一些有關使用者與日誌的操作。

.
.

實驗環境:裝有資料庫5.7版本的虛擬機器一台
.
.

1 . 進入資料庫,查看使用者
想要查看使用者,須先進入mysql資料庫中
use mysql; #先進入
select user,authentication_string,host from user; #查看使用者


.
.
2 . create user ‘test01‘@‘localhost‘ identified by ‘123123‘; #建立使用者及密碼
grant all on . to ‘test02‘@‘localhost‘ identified by ‘123123‘; #建立使用者及密碼,如果使用者存在,則更改,若不在則建立


.
.
3 . 設定好使用者與密碼後也可以更改使用者與密碼
rename user ‘test01‘@‘localhost‘ to ‘user01‘@‘192.168.200.128‘;#重新命名使用者及主機
set password for ‘user02‘@‘localhost‘ = password(‘qwe123‘);# 更改使用者密碼


.
.
4 . 直接設定密碼或許有些不安全,這時就可以用密文設定密碼
select password(‘123123‘); #將密碼轉換成密文
create user ‘user02‘@‘localhost‘ identified by password ‘密文’; #密文設定密碼


.
.
5 . 忘記密碼也有解決的辦法
systemctl stop mysqld.service #關閉資料庫
vim /etc/my.cnf #進入設定檔
在[mysqld]最後插入
skip-grant-tables #跳過驗證 (第二張)
systemctl start mysqld.service #開啟資料庫
mysql #進入資料庫
update mysql.user set authentication_string = password
(‘123qwe‘) where user=‘root‘; #重新更改root使用者密碼
quit
然後刪除my.cof中插入語句
重啟資料庫
這時就可以用root使用者登入了


進入設定檔配置如

.
.
6 . 許可權的賦予與刪除
show grants for ‘wang‘@‘localhost‘; #查看許可權
grant select,update on . to ‘wang‘@‘localhost‘ identified by ‘123qwe‘; #賦予修改與查詢許可權


revoke update on . from ‘wang‘@‘localhost‘; #刪除許可權

.
.
7 . 下面就是相關日誌操作
記錄檔添加到相應的設定檔中
先退出資料庫,然後進入設定檔
vim /etc/my.cnf
在[mysqld]最後插入
log-error=/usr/local/mysql/data/mysql_error.log #錯誤記錄檔
general_log=NO #開啟通用日誌
general_log_file=/usr/local/mysql/data/mysql_general.log #通用日誌
log_bin=mysql-bin #二進位日誌
slow_query_log=ON #開啟慢日誌
slow_query_log_file=mysql_slow_query.log #產生慢日誌
long_query_time=1 #超出時間,1s


然後重啟資料庫,進入資料庫,休眠三秒,這樣慢日誌就會記錄。
可以到日誌存放目錄查看
cd /usr/local/mysql/data #日誌目錄


命令操作就先到這裡,不足之處還望能夠提出,我好方便改進

MySQL 5.7 使用者與日誌管理

聯繫我們

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