MySQL常用操作及读书笔记

MySQL Alan 3年前 (2021-05-31) 2427次浏览 0个评论 扫描二维码

MySQL(及其同门MariaDB)无疑在开源数据库中使用量依然是最高的,仅 WordPress 就声称互联网上近一半的网站都是用的它,而 WordPress 使用的正是 MySQL。本文中不对基础的 CRUD 操作进行缀述,主要记录一些常用配置以及对 高性能MySQL第4版(Early Release,英文版尚未出版)中的一些学习笔记。

官方示例数据库,如sakila:https://dev.mysql.com/doc/index-other.html

workbench:https://dev.mysql.com/downloads/workbench/

一条语句的查询:连接器->分析器->优化器->执行器

WAL: Write-Ahead Logging

 

性能相关

操作系统查看磁盘 iops(每秒读写)

查看影响性能的锁:information_schema中的长事务表 innodb_trx, 锁:innodb_locks,阻塞事务 innodb_lock_waits

8.0新增 performance_schema 库,锁:data_locks,阻塞事务 data_lock_waits,MDL锁:metadata_locks

常用命令整理

MySQL审计

MySQL社区版虽然支持审计功能,但并没有自带 server_audit.so,需要通过 MariaDB 的安装包进行添加。下载时版本需要对应,MySQL 5.7对应:https://downloads.mariadb.org/mariadb/5.5/。bin_log 可以帮我们记录一切操作,进而做数据恢复和主从同步等操作,而审计更多地用于记录操作以及所执行的用户、IP 等信息,因而可以追踪到异常操作,或者简单说确定应该由谁来背锅,所以一般不需要全量记录,server_audit_events即可配置进行记录的事件。

快速下载地址:mariadb-5.5.68-linux-x86_64.tar.gz,获取mariadb-5.5.68-linux-x86_64/lib/plugin/server_audit.so

参数官方文档

TypeDescriptionIntroduced
CONNECTConnects, disconnects and failed connects—including the error code
QUERYQueries executed and their results in plain text, including failed queries due to syntax or permission errors
TABLETables affected by query execution
QUERY_DDLSimilar to QUERY, but filters only DDL-type queries (CREATE, ALTER, DROP, RENAME and TRUNCATE statements—except CREATE/DROP [PROCEDURE / FUNCTION / USER] and RENAME USER (they're not DDL)MariaDB 5.5.42. MariaDB 10.0.17, MariaDB 10.1.4
QUERY_DMLSimilar to QUERY, but filters only DML-type queries (DO, CALL, LOAD DATA/XML, DELETE, INSERT, SELECT, UPDATE, HANDLER and REPLACE statements)MariaDB 5.5.42, MariaDB 10.0.17, MariaDB 10.1.4
QUERY_DML_NO_SELECTSimilar to QUERY_DML, but doesn't log SELECT queries. (since version 1.4.4) (DO, CALL, LOAD DATA/XML, DELETE, INSERT, UPDATE, HANDLER and REPLACE statements)MariaDB 5.5.42, MariaDB 10.0.17, MariaDB 10.1.4
QUERY_DCLSimilar to QUERY, but filters only DCL-type queries (CREATE USER, DROP USER, RENAME USER, GRANT, REVOKE and SET PASSWORD statements)MariaDB 5.5.43, MariaDB 10.0.18, MariaDB 10.1.5

配置文件

来自网络带说明的配置

SQL

MariaDB

Docker 相关

1、[ERROR] Could not open file ‘/mysql/logs/error.log’ for error logging: Permission denied

 

高性能MySQL第4版

文件系统推荐XFS,ext4也可接受

http://collectl.sourceforge.net/

查询配置文件位置和加载顺序

MySQL最小化配置文件(MySQL 8.0)

innodb_dedicated_server通常占用50% – 75%的内存

innodb_thread_concurrency可先设置成和 CPU核数相同,然后再进行调优

MySQL常用操作及读书笔记

喜欢 (2)
[]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址