linux 安裝mysql 8.0:
參考官方文檔 : https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
1.添加mysql yum 存儲庫
下載mysql yum 存儲庫 :https://dev.mysql.com/downloads/repo/yum/
選擇適合平臺的軟件發(fā)行包
安裝下載的軟件發(fā)型包 替換 platform-and-version-specific-package-name 為下載的RPM包的名稱:
sudo yum localinstall platform-and-version-specific-package-name.rpm


2.安裝mysql
通過以下命令安裝mysql :
sudo yum install mysql-community-server
必須啟動前配置:
/usr/sbin/mysqld --initialize --user=mysql --lower-case-table-names=1
3.啟動mysql
啟動 :
sudo service mysqld start
停止 :
sudo service mysqld stop
檢測mysql 服務(wù)器的狀態(tài):
sudo service mysqld status
4.重置超級管理員密碼
將'root'@'localhost創(chuàng)建一個(gè)超級用戶帳戶。設(shè)置超級用戶的密碼并將其存儲在錯(cuò)誤日志文件中。要顯示它,請使用以下命令:
sudo grep 'temporary password' /var/log/mysqld.log

用臨時(shí)密碼 登錄 :
[圖片上傳中...(image-7efeae-1631951661092-0)]
更改密碼策略 : 【生產(chǎn)環(huán)境不應(yīng)該更改密碼策略】
set global validate_password.policy=0; -- 修改密碼策略 可以使用簡單密碼
set global validate_password.length = 4; -- 修改密碼的最低長度是4
修改root密碼 : 【注意 : 密碼不能用root】
ALTER USER 'root'@'localhost' IDENTIFIED BY 'hyxxxxx';
5.安裝后設(shè)置和測試
root賬號設(shè)置遠(yuǎn)程連接可訪問:
-- 切換mysql庫
use mysql;
-- 更新域?qū)傩裕?%'表示允許外部訪問:
update user set host = "%" where user = "root";
-- 刷新權(quán)限
FLUSH PRIVILEGES;
-- 授權(quán)
GRANT ALL PRIVILEGES ON . TO 'root'@'%'WITH GRANT OPTION;
-- 解決navicat 登錄不上問題
alter user 'root' identified with mysql_native_password by 'hy19940619';
1. show status like '%conn%'
Threads_connected 當(dāng)前的連接數(shù)
max_connections MySQL設(shè)置的連接數(shù)。
Max_used_connections 服務(wù)器啟動后已經(jīng)同時(shí)使用的連接的最大數(shù)量。
Max_used_connections / max_connections * 100% = 3/512 *100% ≈ 0.0058%
服務(wù)器響應(yīng)的最大連接數(shù)值占服務(wù)器上限連接數(shù)值的比例值在10%以上,
如果在10%以下,說明mysql服務(wù)器最大連接上限值設(shè)置過高.
2.show processlist 顯示當(dāng)前正在執(zhí)行的mysql連接
show full processlist 顯示完整sql
3.tps 查詢 每秒事務(wù)數(shù)
select VARIABLE_VALUE into @num_com from GLOBAL_STATUS where VARIABLE_NAME ='COM_COMMIT';
select VARIABLE_VALUE into @num_roll from GLOBAL_STATUS
where VARIABLE_NAME ='COM_ROLLBACK';
select VARIABLE_VALUE into @uptime from GLOBAL_STATUS
where VARIABLE_NAME ='UPTIME';
select (@num_com+@num_roll)/@uptime;
4. QPS查詢 每秒查詢數(shù)
select VARIABLE_VALUE into @num_queries from GLOBAL_STATUS
where VARIABLE_NAME ='QUESTIONS';
select VARIABLE_VALUE into @uptime from GLOBAL_STATUS
where VARIABLE_NAME ='UPTIME';
select @num_queries/@uptime;