您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)Centos7如何安裝Mysql8.0,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
mysql官方下載地址: https://dev.mysql.com/downloads/
選擇: MySQL Community Server
如果是centos,官方?jīng)]有centos選擇,選擇redhat即可;需要查看內(nèi)核版本,這里是el7,64位;命令如下:
[root@iZ2ze8diszrt8lvjh9yr86Z mysql]# uname -a Linux iZ2ze8diszrt8lvjh9yr86Z 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux [root@iZ2ze8diszrt8lvjh9yr86Z mysql]# more /proc/version Linux version 3.10.0-957.21.3.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (G CC) ) #1 SMP Tue Jun 18 16:35:19 UTC 2019
下載安裝包(mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar);bundle是包含所有按照包的;通過(guò)tar -xvf命令解壓
[root@iZ2ze8diszrt8lvjh9yr86Z mysql]# tar -xvf mysql-8.0.18-1.el7.aarch74.rpm-bundle.tar mysql-community-embedded-compat-8.0.18-1.el7.aarch74.rpm mysql-community-libs-compat-8.0.18-1.el7.aarch74.rpm mysql-community-devel-8.0.18-1.el7.aarch74.rpm mysql-community-test-8.0.18-1.el7.aarch74.rpm mysql-community-libs-8.0.18-1.el7.aarch74.rpm mysql-community-common-8.0.18-1.el7.aarch74.rpm mysql-community-server-8.0.18-1.el7.aarch74.rpm mysql-community-client-8.0.18-1.el7.aarch74.rpm
也可以通過(guò) yum install mysql-community-server 安裝,但是包比較大;
還可以通過(guò)wget獲取,這種方式比較方便;但是需要先去官網(wǎng)登錄,找到對(duì)應(yīng)的下載url
[root@iZ2ze8diszrt8lvjh9yr86Z mysql]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar --2019-10-25 14:34:51-- https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11 Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar [following] --2019-10-25 14:34:53-- https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar Resolving cdn.mysql.com (cdn.mysql.com)... 23.56.181.34 Connecting to cdn.mysql.com (cdn.mysql.com)|23.56.181.34|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 684851200 (653M) [application/x-tar] Saving to: ‘mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar’ 100%[=====================================================================================>] 684,851,200 15.3MB/s in 56s 2019-10-25 14:35:50 (11.6 MB/s) - ‘mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar’ saved [684851200/684851200]
centos7默認(rèn)安裝了mariadb,需要先進(jìn)行卸載
[root@iZ2ze8diszrt8lvjh9yr86Z mysql]# rpm -qa | grep mariadb mariadb-libs-5.5.60-1.el7_5.x86_64 [root@iZ2ze8diszrt8lvjh9yr86Z mysql]# rpm -qa | grep mariadb-server [root@iZ2ze8diszrt8lvjh9yr86Z mysql]# yum remove mariadb-libs.x86_64
安裝順序rpm包有依賴(lài)關(guān)系,如下:
rpm -ivh …common.rpm
rpm -ivh …libs.rpm
rpm -ivh …client.rpm
rpm -ivh …server.rpm
[root@iZ2ze8diszrt8lvjh9yr86Z mysql]# ll total 1999492 -rw-r--r-- 1 root root 684851200 Sep 23 15:36 mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar -rw-r--r-- 1 7155 31415 40104640 Sep 23 15:19 mysql-community-client-8.0.18-1.el7.x86_64.rpm -rw-r--r-- 1 7155 31415 611436 Sep 23 15:20 mysql-community-common-8.0.18-1.el7.x86_64.rpm -rw-r--r-- 1 7155 31415 6915400 Sep 23 15:20 mysql-community-devel-8.0.18-1.el7.x86_64.rpm -rw-r--r-- 1 7155 31415 23683600 Sep 23 15:20 mysql-community-embedded-compat-8.0.18-1.el7.x86_64.rpm -rw-r--r-- 1 7155 31415 3877664 Sep 23 15:20 mysql-community-libs-8.0.18-1.el7.x86_64.rpm -rw-r--r-- 1 7155 31415 1363968 Sep 23 15:20 mysql-community-libs-compat-8.0.18-1.el7.x86_64.rpm -rw-r--r-- 1 7155 31415 450282440 Sep 23 15:21 mysql-community-server-8.0.18-1.el7.x86_64.rpm -rw-r--r-- 1 7155 31415 158001648 Sep 23 15:22 mysql-community-test-8.0.18-1.el7.x86_64.rpm [root@iZ2ze8diszrt8lvjh9yr86Z mysql]# rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm warning: mysql-community-common-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-common-8.0.18-1.e################################# [100%] [root@iZ2ze8diszrt8lvjh9yr86Z mysql]# rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm warning: mysql-community-libs-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-libs-8.0.18-1.el7################################# [100%] [root@iZ2ze8diszrt8lvjh9yr86Z mysql]# rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm warning: mysql-community-client-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-client-8.0.18-1.e################################# [100%] [root@iZ2ze8diszrt8lvjh9yr86Z mysql]# rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm warning: mysql-community-server-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-server-8.0.18-1.e################################# [100%] [root@iZ2ze8diszrt8lvjh9yr86Z mysql]#
mysql8默認(rèn)安裝到了/var/lib/mysql
[root@iZ2ze8diszrt8lvjh9yr86Z mysql]# ll /var/lib/mysql total 155716 -rw-r----- 1 mysql mysql 56 Oct 25 14:52 auto.cnf -rw-r----- 1 mysql mysql 178 Oct 25 14:53 binlog.000001 -rw-r----- 1 mysql mysql 16 Oct 25 14:52 binlog.index -rw------- 1 mysql mysql 1680 Oct 25 14:52 ca-key.pem -rw-r--r-- 1 mysql mysql 1112 Oct 25 14:52 ca.pem -rw-r--r-- 1 mysql mysql 1112 Oct 25 14:52 client-cert.pem -rw------- 1 mysql mysql 1680 Oct 25 14:52 client-key.pem -rw-r----- 1 mysql mysql 3449 Oct 25 14:53 ib_buffer_pool -rw-r----- 1 mysql mysql 12582912 Oct 25 14:53 ibdata1 -rw-r----- 1 mysql mysql 50331648 Oct 25 14:53 ib_logfile0 -rw-r----- 1 mysql mysql 50331648 Oct 25 14:52 ib_logfile1 drwxr-x--- 2 mysql mysql 4096 Oct 25 14:53 #innodb_temp drwxr-x--- 2 mysql mysql 4096 Oct 25 14:52 mysql -rw-r----- 1 mysql mysql 25165824 Oct 25 14:52 mysql.ibd drwxr-x--- 2 mysql mysql 4096 Oct 25 14:52 performance_schema -rw------- 1 mysql mysql 1680 Oct 25 14:52 private_key.pem -rw-r--r-- 1 mysql mysql 452 Oct 25 14:52 public_key.pem -rw-r--r-- 1 mysql mysql 1112 Oct 25 14:52 server-cert.pem -rw------- 1 mysql mysql 1680 Oct 25 14:52 server-key.pem drwxr-x--- 2 mysql mysql 4096 Oct 25 14:52 sys -rw-r----- 1 mysql mysql 10485760 Oct 25 14:53 undo_001 -rw-r----- 1 mysql mysql 10485760 Oct 25 14:53 undo_002
默認(rèn)配置文件在/etc/my.cnf
通過(guò)service mysqld服務(wù)就可以啟動(dòng)停止mysql了
[root@iZ2ze8diszrt8lvjh9yr86Z mysql]# service mysqld start Redirecting to /bin/systemctl start mysqld.service [root@iZ2ze8diszrt8lvjh9yr86Z mysql]# [root@iZ2ze8diszrt8lvjh9yr86Z mysql]# service mysqld status Redirecting to /bin/systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2019-10-25 14:52:50 CST; 2s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 12015 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 12094 (mysqld) Status: "Server is operational" CGroup: /system.slice/mysqld.service └─12094 /usr/sbin/mysqld Oct 25 14:52:42 iZ2ze8diszrt8lvjh9yr86Z systemd[1]: Starting MySQL Server... Oct 25 14:52:50 iZ2ze8diszrt8lvjh9yr86Z systemd[1]: Started MySQL Server. [root@iZ2ze8diszrt8lvjh9yr86Z mysql]# service mysqld stop Redirecting to /bin/systemctl stop mysqld.service
1. 剛剛啟動(dòng)成功之后, 用命令查看默認(rèn)密碼并且登錄
默認(rèn)密碼查看:cat /var/log/mysqld.log | grep password 登陸:mysql -u root -p 然后輸入密碼
2. 修改密碼 set global validate_password.policy=0; set global validate_password.length=1; ALTER USER "root"@"localhost" IDENTIFIED BY "1234"; // 新密碼為1234 3. exit 退出 mysql -u root -p 然后輸入密碼即可登錄
[root@iZ2ze8diszrt8lvjh9yr86Z mysql]# cat /var/log/mysqld.log | grep password 2019-10-25T06:52:47.021899Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: lV.66%i>m,7F [root@iZ2ze8diszrt8lvjh9yr86Z mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.18 Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # 修改密碼策略 mysql> set global validate_password.policy=0; Query OK, 0 rows affected (0.00 sec) # 修改密碼長(zhǎng)度校驗(yàn) mysql> set global validate_password.length=1; Query OK, 0 rows affected (0.00 sec) # 修改root密碼 mysql> ALTER USER "root"@"localhost" IDENTIFIED BY "123456"; Query OK, 0 rows affected (0.01 sec)
首先關(guān)閉防火墻
//臨時(shí)關(guān)閉 systemctl stop firewalld //禁止開(kāi)機(jī)啟動(dòng) systemctl disable firewalld
mysql8.0修改了默認(rèn)認(rèn)證規(guī)則;之前的版本中加密規(guī)則是mysql_native_password,而在mysql8之后,加密規(guī)則是caching_sha2_password, 解決此問(wèn)題方法有兩種,一種是升級(jí)客戶(hù)端驅(qū)動(dòng),一種是把mysql用戶(hù)登錄密碼加密規(guī)則還原成mysql_native_password。
但網(wǎng)上教程大多數(shù)都是修改root為遠(yuǎn)程連接,并且修改認(rèn)證模式;不建議這么操作,如果操作稍有問(wèn)題會(huì)導(dǎo)致mysql無(wú)法鏈接,解決比較麻煩;
這里創(chuàng)建新用戶(hù)admin,付給所有權(quán)限,可進(jìn)行遠(yuǎn)程維護(hù);操作如下
mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed # 創(chuàng)建admin用戶(hù) mysql> create user 'admin'@'%' identified by 'Admin123'; Query OK, 0 rows affected (0.00 sec) # 付給所有權(quán)限 mysql> grant all on *.* to 'admin'@'%' ; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) # 修改admin認(rèn)證模式及密碼 mysql> ALTER USER 'admin'@'%' IDENTIFIED WITH mysql_native_password BY 'Admin123'; Query OK, 0 rows affected (0.00 sec) # 刷新權(quán)限 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) # 退出使用新用戶(hù)驗(yàn)證登錄 [root@iZ2ze8diszrt8lvjh9yr86Z ~]# mysql -uadmin -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 22 Server version: 8.0.18 MySQL Community Server - GPL Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed # 查看用戶(hù)配置 mysql> select host,user,plugin from user; +-----------+------------------+-----------------------+ | host | user | plugin | +-----------+------------------+-----------------------+ | % | admin | mysql_native_password | | localhost | mysql.infoschema | caching_sha2_password | | localhost | mysql.session | caching_sha2_password | | localhost | mysql.sys | caching_sha2_password | | localhost | root | caching_sha2_password | +-----------+------------------+-----------------------+
之后使用遠(yuǎn)程客戶(hù)端Navicat驗(yàn)證,鏈接成功;
至此mysql全部安裝完成~!~
這里沒(méi)有進(jìn)行操作,僅作為記錄
首先 , 停止mysql service mysqld stop
總共分兩步:
1.卸載mysql組件
2.刪除相關(guān)文件夾
# 第一步卸載mysql組件 # 查看MySQL組件 [root@localhost ~]# rpm -qa | grep -i mysql mysql-community-libs-8.0.12-1.el7.x86_64 mysql-community-common-8.0.12-1.el7.x86_64 mysql-community-client-8.0.12-1.el7.x86_64 mysql-community-server-8.0.12-1.el7.x86_64 # 刪除 [root@localhost ~]# rpm -ev mysql-community-server-8.0.12-1.el7.x86_64 Preparing packages... mysql-community-server-8.0.12-1.el7.x86_64 warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave # 刪除 [root@localhost ~]# rpm -ev mysql-community-client-8.0.12-1.el7.x86_64 Preparing packages... mysql-community-client-8.0.12-1.el7.x86_64 # 刪除失敗 [root@localhost ~]# rpm -ev mysql-community-common-8.0.12-1.el7.x86_64 error: Failed dependencies: mysql-community-common(x86-64) >= 8.0.0 is needed by (installed) mysql-community-libs-8.0.12-1.el7.x86_64 # 繼續(xù)查看 [root@localhost ~]# rpm -qa | grep -i mysql mysql-community-libs-8.0.12-1.el7.x86_64 mysql-community-common-8.0.12-1.el7.x86_64 # 刪除 [root@localhost ~]# rpm -e --noscripts mysql-community-libs-8.0.12-1.el7.x86_64 # 刪除 [root@localhost ~]# rpm -e --noscripts mysql-community-common-8.0.12-1.el7.x86_64 # 查看 [root@localhost ~]# rpm -qa | grep -i mysql # 第二步:刪除相關(guān)目錄 # 查看 [root@localhost ~]# find / -name mysql /etc/mysql /etc/selinux/targeted/active/modules/100/mysql /var/lib/mysql /var/lib/mysql/mysql # 刪除 [root@localhost ~]# rm -rf /etc/mysql [root@localhost ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql [root@localhost ~]# rm -rf /var/lib/mysql [root@localhost ~]# find / -name mysql # 再次檢查,什么都沒(méi)有說(shuō)明卸載成功了 [root@localhost ~]# rpm -qa | grep -i mysql
CentOS安裝rpm安裝MySQL時(shí)爆出警告:
[root@iZ2ze8diszrt8lvjh9yr86Z mysql]# rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm warning: mysql-community-server-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
原因:這是由于yum安裝了舊版本的GPG keys造成的 解決辦法:后面加上 --force --nodeps 如:rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm --force --nodeps 好了,完美解決
只是一個(gè)警告,不處理也是可以的
提示libaio.so.1()(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64
[root@iZ2ze8diszrt8lvjh9yr86Z mysql]# rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm warning: mysql-community-server-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: libaio.so.1()(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64 libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64 libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64 [root@iZ2ze8diszrt8lvjh9yr86Z mysql]# yum install libaio
yum install libaio 這樣就ok了,就可以繼續(xù)安裝mysql了。
# 查詢(xún)mysql最大連接數(shù)設(shè)置 show global variables like 'max_conn%'; # 查看當(dāng)前用戶(hù)鏈接數(shù) show global status like 'Max_used_connections'; # 查看慢查詢(xún)?nèi)罩臼欠耖_(kāi)啟以及日志位置 show variables like 'slow_query%'; # 查看慢查詢(xún)?nèi)罩境瑫r(shí)記錄時(shí)間 show variables like 'long_query_time'; # 查看鏈接創(chuàng)建以及現(xiàn)在正在鏈接數(shù) show status like 'Threads%'; # 查看數(shù)據(jù)庫(kù)當(dāng)前鏈接 show processlist; # 查看數(shù)據(jù)庫(kù)配置 show variables like '%quer%';
參數(shù)請(qǐng)根據(jù)實(shí)際情況調(diào)整,不要無(wú)腦復(fù)制
#Mysql服務(wù)的唯一編號(hào) 每個(gè)mysql服務(wù)Id需唯一 server-id = 1 #服務(wù)端口號(hào) 默認(rèn)3306 port = 3306 #mysql安裝根目錄 basedir = /var/share/mysql-8.0 #mysql數(shù)據(jù)文件所在位置 datadir = /var/lib/mysql #pid pid-file = /var/lib/mysql/mysql.pid #設(shè)置socke文件所在目錄 socket = /tmp/mysql.sock #設(shè)置臨時(shí)目錄 tmpdir = /tmp # 用戶(hù) user = mysql # 允許訪問(wèn)的IP網(wǎng)段 bind-address = 0.0.0.0 # 跳過(guò)密碼登錄 #skip-grant-tables #主要用于MyISAM存儲(chǔ)引擎,如果多臺(tái)服務(wù)器連接一個(gè)數(shù)據(jù)庫(kù)則建議注釋下面內(nèi)容 skip-external-locking #只能用IP地址檢查客戶(hù)端的登錄,不用主機(jī)名 skip_name_resolve = 1 #事務(wù)隔離級(jí)別,默認(rèn)為可重復(fù)讀,mysql默認(rèn)可重復(fù)讀級(jí)別(此級(jí)別下可能參數(shù)很多間隙鎖,影響性能) transaction_isolation = READ-COMMITTED #數(shù)據(jù)庫(kù)默認(rèn)字符集,主流字符集支持一些特殊表情符號(hào)(特殊表情符占用4個(gè)字節(jié)) character-set-server = utf8mb4 #數(shù)據(jù)庫(kù)字符集對(duì)應(yīng)一些排序等規(guī)則,注意要和character-set-server對(duì)應(yīng) collation-server = utf8mb4_general_ci #設(shè)置client連接mysql時(shí)的字符集,防止亂碼 init_connect='SET NAMES utf8mb4' #是否對(duì)sql語(yǔ)句大小寫(xiě)敏感,1表示不敏感 lower_case_table_names = 1 #最大連接數(shù) max_connections = 400 #最大錯(cuò)誤連接數(shù) max_connect_errors = 1000 #TIMESTAMP如果沒(méi)有顯示聲明NOT NULL,允許NULL值 explicit_defaults_for_timestamp = true #SQL數(shù)據(jù)包發(fā)送的大小,如果有BLOB對(duì)象建議修改成1G max_allowed_packet = 128M #MySQL連接閑置超過(guò)一定時(shí)間后(單位:秒)將會(huì)被強(qiáng)行關(guān)閉 #MySQL默認(rèn)的wait_timeout 值為8個(gè)小時(shí), interactive_timeout參數(shù)需要同時(shí)配置才能生效 interactive_timeout = 1800 wait_timeout = 1800 #內(nèi)部?jī)?nèi)存臨時(shí)表的最大值 ,設(shè)置成128M。 #比如大數(shù)據(jù)量的group by ,order by時(shí)可能用到臨時(shí)表, #超過(guò)了這個(gè)值將寫(xiě)入磁盤(pán),系統(tǒng)IO壓力增大 tmp_table_size = 134217728 max_heap_table_size = 134217728 #禁用mysql的緩存查詢(xún)結(jié)果集功能 #后期根據(jù)業(yè)務(wù)情況測(cè)試決定是否開(kāi)啟 #大部分情況下關(guān)閉下面兩項(xiàng) query_cache_size = 0 query_cache_type = 0 #數(shù)據(jù)庫(kù)錯(cuò)誤日志文件 log_error = error.log #慢查詢(xún)sql日志設(shè)置 slow_query_log = 1 slow_query_log_file = slow.log #檢查未使用到索引的sql log_queries_not_using_indexes = 1 #針對(duì)log_queries_not_using_indexes開(kāi)啟后,記錄慢sql的頻次、每分鐘記錄的條數(shù) log_throttle_queries_not_using_indexes = 5 #作為從庫(kù)時(shí)生效,從庫(kù)復(fù)制中如何有慢sql也將被記錄 log_slow_slave_statements = 1 #慢查詢(xún)執(zhí)行的秒數(shù),必須達(dá)到此值可被記錄 long_query_time = 8 #檢索的行數(shù)必須達(dá)到此值才可被記為慢查詢(xún) min_examined_row_limit = 100 #mysql binlog日志文件保存的過(guò)期時(shí)間,過(guò)期后自動(dòng)刪除 expire_logs_days = 5
slow_query_log 慢查詢(xún)開(kāi)啟狀態(tài) slow_query_log_file 慢查詢(xún)?nèi)罩敬娣诺奈恢茫ㄟ@個(gè)目錄需要MySQL的運(yùn)行帳號(hào)的可寫(xiě)權(quán)限,一般設(shè)置為MySQL的數(shù)據(jù)存放目錄) long_query_time 查詢(xún)超過(guò)多少秒才記錄
mysql> show variables like 'slow_query%'; +---------------------------+----------------------------------+ | Variable_name | Value | +---------------------------+----------------------------------+ | slow_query_log | OFF | | slow_query_log_file | /mysql/data/localhost-slow.log | +---------------------------+----------------------------------+ mysql> show variables like 'long_query_time'; +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 10.000000 | +-----------------+-----------+
# 將slow_query_log 全局變量設(shè)置為“ON”狀態(tài) mysql> set global slow_query_log='ON'; # 設(shè)置慢查詢(xún)?nèi)罩敬娣诺奈恢? mysql> set global slow_query_log_file='/usr/local/mysql/data/slow.log'; # 查詢(xún)超過(guò)3秒就記錄 mysql> set global long_query_time=3;
修改配置文件my.cnf,在[mysqld]下的下方加入
[mysqld] slow_query_log = ON slow_query_log_file = /usr/local/mysql/data/slow.log long_query_time = 3
3.重啟MySQL服務(wù)
service mysqld restart
4.查看設(shè)置后的參數(shù)
mysql> show variables like 'slow_query%'; +---------------------+--------------------------------+ | Variable_name | Value | +---------------------+--------------------------------+ | slow_query_log | ON | | slow_query_log_file | /usr/local/mysql/data/slow.log | +---------------------+--------------------------------+ mysql> show variables like 'long_query_time'; +-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | long_query_time | 1.000000 | +-----------------+----------+
關(guān)于“Centos7如何安裝Mysql8.0”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。