目录

  • 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密码重置和慢查询日志相关推荐

  1. 任意用户密码重置(四):重置凭证未校验

    在逻辑漏洞中,任意用户密码重置最为常见,可能出现在新用户注册页面,也可能是用户登录后重置密码的页面,或者用户忘记密码时的密码找回页面,其中,密码找回功能是重灾区.我把日常渗透过程中遇到的案例作了漏洞成 ...

  2. 第九课:循环链表与双向链表

    第九课 本课主题: 循环链表与双向链表 教学目的: 掌握循环链表的概念,掌握双向链表的的表示与实现 教学重点: 双向链表的表示与实现 教学难点: 双向链表的存储表示 授课内容: 一.复习线性链表的存储 ...

  3. Grafana密码重置

    前言 下面介绍的是各种情况下 Grafana忘记密码后进行的重置操作. [1]web重置 当Grafana的邮件通知配置正常时,你可以通过web界面 点击忘记密码,通过邮件中的链接重置密码 也可联系管 ...

  4. MobaXterm登录密码重置

    一.背景 早上项目日常巡检,发现登录MobaXterm提示输入密码,密码输入多次后无果,密码忘记如法使用MobaXterm软件,经过查询后可采用密码重置的方式处理. 二.解决方案 请使用浏览器打开如下 ...

  5. 【PHP MySQL】数据库专题 第九课 自连接

    [PHP & MySQL]✔️数据库专题✔️ 第九课 自连接 概述 自连接 子查询 in 子查询 EXISTS 概述 从今天开始, 小白我将带领大家一起来补充一下 数据库的知识. 自连接 自连 ...

  6. 服务器修改mysql登录密码忘了怎么办,云服务器mysql密码重置密码忘记了

    云服务器mysql密码重置密码忘记了 内容精选 换一换 弹性云服务器系统密码涉及到客户重要的私人信息,提醒您妥善保管密码.如果您忘记密码或密码过期,可以重置密码.如果弹性云服务器提前安装了密码重置插件 ...

  7. 关于调用短信接口实现手机验证码密码重置功能

    前端 <template><div class="logo"><div class="l_main"><div cla ...

  8. 华为服务器清除系统密码,重置服务器主机密码

    重置服务器主机密码 内容精选 换一换 WinSCP工具可以实现在本地与远程计算机之间安全地复制文件.与使用FTP上传代码相比,通过 WinSCP 可以直接使用服务器账户密码访问服务器,无需在服务器端做 ...

  9. 任意密码重置;越权查看他人信息及修改信息

    我挖的是edu.cn的漏洞,使用了oneforall进行子域名搜集,在看到一个标题为"某某某管理信息系统"的站点,就上手了. 1.任意密码重置 账号 admin 密码123456( ...

最新文章

  1. 前端iframe 能指定本地网页吗_微前端的技术拆分方式
  2. COLINUX的安装与网络配置
  3. mysql 安全删除_mysql的binlog安全删除的一种方法
  4. 通过Oracle VM Manager管理配置虚拟机
  5. 快手大数据架构演进实录
  6. hive hsql 漏斗模型_数据分析之SQL:常用模型
  7. Android 学习--ListView 的使用(一)
  8. 第六届蓝桥杯:三羊献瑞
  9. sourcetree合并分支_不会git命令,没关系啊,还有强大的图形界面工具SourceTree
  10. Linux打开关闭ping
  11. java选课管理_学生选课管理系统(Java语言期末前测试)
  12. 闲聊:Android 平台网络游戏加速器·一(科普文)
  13. vue开发完整企业购物商城集成支付宝和微信登陆支付3步实现登陆
  14. veu中点击商品详情打开新窗口
  15. SQL中的日期和字符串互相转换
  16. Allegro如何给铜皮导弧操作详解
  17. delete hive_hive执行更新和删除操作
  18. 从零构建通讯器--4.3日志打印实战,捋下main函数的调用顺序
  19. 路由器广域网接口简介
  20. 从零搭建飞冰微前端项目《第二篇:搭建主应用》

热门文章

  1. 二进制编译安装mysql_二进制编译安装mysql
  2. java http url 编码_Java中的HTTP URL地址编码
  3. jquery查找父窗体id_Vue父组件获取子组件中的变量
  4. Kotlin AAPT: error: resource android:attr/lStar not found.
  5. mac os11以下安装Xcode
  6. c语言数据交换的算法流程图,C语言冒泡排序算法浅析
  7. DFS实现floodfill算法
  8. 量子计算机 真假,复原乳到底有没有营养?量子计算机是否已拍死“前浪”?“科学”流言榜告诉你真假...
  9. python 模糊匹配_很冷门,但非常实用的 Python 库
  10. java在原数组中追加一个元素