日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【第九课】MriaDB密码重置和慢查询日志

發布時間:2025/3/15 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【第九课】MriaDB密码重置和慢查询日志 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

  • 1、如何進行修改MariaDB的密碼
  • 2、Mariadb的慢查詢日志

1、如何進行修改MariaDB的密碼

記得root密碼的修改方式:

[root@localhost ~]# mysqladmin -uroot -p123456 password "123123" [root@localhost ~]# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) [root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 37 Server version: 10.1.20-MariaDB MariaDB ServerCopyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> quit Bye

忘記root密碼的修改方式

[root@localhost ~]# vim /etc/my.cnf.d/mariadb-server.cnf [mysqld] #在mysqld段中增加skip-grant-tables,跳過授權表 server_id=1111 log-bin=mysql-bin skip-grant-tables datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid[root@localhost ~]# systemctl restart mariadb #重啟mariadb [root@localhost ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 10.1.20-MariaDB MariaDB ServerCopyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed MariaDB [mysql]> desc user; +------------------------+-----------------------------------+------+-----+----------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------------+-----------------------------------+------+-----+----------+-------+ | Host | char(60) | NO | PRI | | | | User | char(80) | NO | PRI | | | | Password | char(41) | NO | | | | | Select_priv | enum('N','Y') | NO | | N | | | Insert_priv | enum('N','Y') | NO | | N | | | Update_priv | enum('N','Y') | NO | | N | | | Delete_priv | enum('N','Y') | NO | | N | | | Create_priv | enum('N','Y') | NO | | N | | | Drop_priv | enum('N','Y') | NO | | N | | | Reload_priv | enum('N','Y') | NO | | N | | | Shutdown_priv | enum('N','Y') | NO | | N | | | Process_priv | enum('N','Y') | NO | | N | | | File_priv | enum('N','Y') | NO | | N | | | Grant_priv | enum('N','Y') | NO | | N | | | References_priv | enum('N','Y') | NO | | N | | | Index_priv | enum('N','Y') | NO | | N | | | Alter_priv | enum('N','Y') | NO | | N | | | Show_db_priv | enum('N','Y') | NO | | N | | | Super_priv | enum('N','Y') | NO | | N | | | Create_tmp_table_priv | enum('N','Y') | NO | | N | | | Lock_tables_priv | enum('N','Y') | NO | | N | | | Execute_priv | enum('N','Y') | NO | | N | | | Repl_slave_priv | enum('N','Y') | NO | | N | | | Repl_client_priv | enum('N','Y') | NO | | N | | | Create_view_priv | enum('N','Y') | NO | | N | | | Show_view_priv | enum('N','Y') | NO | | N | | | Create_routine_priv | enum('N','Y') | NO | | N | | | Alter_routine_priv | enum('N','Y') | NO | | N | | | Create_user_priv | enum('N','Y') | NO | | N | | | Event_priv | enum('N','Y') | NO | | N | | | Trigger_priv | enum('N','Y') | NO | | N | | | Create_tablespace_priv | enum('N','Y') | NO | | N | | | ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | | | ssl_cipher | blob | NO | | NULL | | | x509_issuer | blob | NO | | NULL | | | x509_subject | blob | NO | | NULL | | | max_questions | int(11) unsigned | NO | | 0 | | | max_updates | int(11) unsigned | NO | | 0 | | | max_connections | int(11) unsigned | NO | | 0 | | | max_user_connections | int(11) | NO | | 0 | | | plugin | char(64) | NO | | | | | authentication_string | text | NO | | NULL | | | password_expired | enum('N','Y') | NO | | N | | | is_role | enum('N','Y') | NO | | N | | | default_role | char(80) | NO | | | | | max_statement_time | decimal(12,6) | NO | | 0.000000 | | +------------------------+-----------------------------------+------+-----+----------+-------+ 46 rows in set (0.00 sec)MariaDB [mysql]> update user set password=password("123456") where user='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 3 Changed: 1 Warnings: 0MariaDB [mysql]> quit; Bye [root@localhost ~]# vim /etc/my.cnf.d/mariadb-server.cnf 刪除/etc/my.cnf里面的skip-grant, 重啟服務 [root@localhost ~]# systemctl restart mariadb [root@localhost ~]# mysql -uroot -p Enter password: 123456 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 10.1.20-MariaDB MariaDB ServerCopyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> quit; Bye

2、Mariadb的慢查詢日志

為什么要配置慢查詢日志?

其目的是為了幫助我們分析MariaDB的瓶頸點,或者說是業務的瓶頸點。任何一個動態網站都會有讀取和寫入到數據庫的操作,如果其中有一個腳本或SQL語句執行特別慢,那么帶來的現象可能是用戶訪問站點時出現卡頓,或者響應較慢。那么為了去分析慢查詢,就可以啟用慢查詢日志的方式。

如何配置慢查詢??

  • (1)進入MariaDB里面進行執行:
    • show variables like "slow%";
    • show variables like "datadir";
    • show variables like "long%";
  • (2)編輯/etc/my.cnf進行配置
  • (3)重啟服務
  • (4)模擬慢查詢
  • (5)查看慢查詢日志
(1)進入MariaDB里面進行執行[root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 16 Server version: 10.1.20-MariaDB MariaDB ServerCopyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> show variables like "slow%"; #查看慢查詢相關的配置 +---------------------+--------------------+ | Variable_name | Value | +---------------------+--------------------+ | slow_launch_time | 2 | #慢查詢運行時間配置 | slow_query_log | OFF | #是否開啟慢查詢 | slow_query_log_file | localhost-slow.log | #慢查詢日志文件名稱,存在于datadir中 +---------------------+--------------------+ 3 rows in set (0.01 sec)MariaDB [(none)]> show variables like "datadir"; #查看datadir路徑 +---------------+-----------------+ | Variable_name | Value | +---------------+-----------------+ | datadir | /var/lib/mysql/ | +---------------+-----------------+ 1 row in set (0.00 sec)MariaDB [(none)]> show variables like "long%"; #查詢時間配置 +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 10.000000 | +-----------------+-----------+ 1 row in set (0.00 sec)(2)編輯/etc/my.cnf進行配置 [root@localhost ~]# vim /etc/my.cnf #修改my.cnf配置慢查詢日志 [mysqld] # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 slow_query_log = ON #開啟慢查詢記錄 slow_query_log_file = /var/lib/mysql/mysql-slow.log #配置慢查詢日志文件路徑 long_query_time = 2 #配置查詢時間超過2s進行記錄(3)重啟服務 [root@localhost ~]# systemctl restart mariadb(4)模擬慢查詢 [root@localhost ~]# mysql -uroot -p #重新登錄,運行select進行驗證記錄 Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 10.1.20-MariaDB MariaDB ServerCopyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> select sleep(5); +----------+ | sleep(5) | +----------+ | 0 | +----------+ 1 row in set (5.00 sec)(5)查看慢查詢日志 [root@localhost ~]# cat /var/lib/mysql/mysql-slow.log #查看慢查詢日志 /usr/libexec/mysqld, Version: 10.1.20-MariaDB (MariaDB Server). started with: Tcp port: 0 Unix socket: /var/lib/mysql/mysql.sock Time Id Command Argument # Time: 190218 11:43:05 # User@Host: root[root] @ localhost [] # Thread_id: 3 Schema: QC_hit: No # Query_time: 5.002032 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0 # Rows_affected: 0 SET timestamp=1550461385; select sleep(5); #提示慢查詢的運行指令

同時,還可以使用show processlist;和show full processlist;進行查看慢查詢隊列

show processlist; 查看所有的隊列;可以查看數據庫中有些什么查詢和查詢量的多少,如果查詢量超過100都會比較慢,此時就需要進行優化。

show full processlist; 和上面有什么區別呢?如果有1個語句特別長,info列,只會顯示一部分,使用這個命令時,就可以顯示完整的信息。

MariaDB [(none)]> show processlist; +----+------+-----------+------+---------+------+-------+------------------+----------+ | Id | User | Host | db | Command | Time | State | Info | Progress | +----+------+-----------+------+---------+------+-------+------------------+----------+ | 3 | root | localhost | NULL | Query | 0 | init | show processlist | 0.000 | +----+------+-----------+------+---------+------+-------+------------------+----------+ 1 row in set (0.00 sec)MariaDB [(none)]> show full processlist; +----+------+-----------+------+---------+------+-------+-----------------------+----------+ | Id | User | Host | db | Command | Time | State | Info | Progress | +----+------+-----------+------+---------+------+-------+-----------------------+----------+ | 3 | root | localhost | NULL | Query | 0 | init | show full processlist | 0.000 | +----+------+-----------+------+---------+------+-------+-----------------------+----------+ 1 row in set (0.00 sec)

轉載于:https://www.cnblogs.com/linuxk/p/10382389.html

總結

以上是生活随笔為你收集整理的【第九课】MriaDB密码重置和慢查询日志的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。