概要说明
常用命令
参考
以下是MySQL 5.7.44配置体系的核心要点总结及管理建议,结合文档内容进行结构化梳理:
my.cnf
作用:全局核心配置,采用INI格式分段管理不同组件(如 [mysqld]
、[client]
)。
常见路径:
/etc/my.cnf
/etc/mysql/my.cnf
。关键特性:
/etc/my.cnf
→ /etc/mysql/my.cnf
→ ~/.my.cnf
)配置文件示例:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysqld.sock
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
MySQL是数据库管理系统(DBMS),具体是关系型数据库管理系统(RDBMS)。
MySQL 提供了几种用于查看服务器版本的方法,本文给大家做个简单的介绍。
每次通过 mysql 客户端连接服务器之后,都会显示一个欢迎信息,里面包含了服务器的版本:
mysql -uroot
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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.
SELECT
column_name AS '名',
column_comment AS '备注(中文名)',
column_default AS '默认值',
-- column_type AS '类型',
data_type AS '类型',
character_maximum_length AS '长度',
-- numeric_precision AS '精度',
numeric_scale AS '小数位数',
IF ( is_nullable = 'NO', 'N', '' ) AS '能否为空',
IF ( extra = 'auto_increment', 'Y', '' ) AS '是否自增',
IF ( column_key = 'PRI', 'Y', '' ) AS '是否主键'
FROM
information_schema.columns
WHERE
table_schema = ''
AND table_name = ''
-- 导出到桌面的Excel表格
-- INTO OUTFILE 'D:/test.xls'
Binlog(Binary Log)是 MySQL 数据库的二进制日志文件,用于记录所有修改数据库数据的操作(如 INSERT、UPDATE、DELETE),是 MySQL 实现数据复制、恢复和审计的核心机制。
主从复制(Replication):主库将 Binlog 传输到从库,从库重放这些操作实现数据同步。
数据恢复:通过 Binlog 可实现时间点恢复(PITR),精确还原到某个时间点的数据状态。
审计与追踪:记录所有变更操作,便于追踪数据变更历史。
「为什么 MySQL 采用 B+ 树作为索引?」
MySQL 的数据是持久化的,意味着数据(索引+记录)是保存到磁盘上的,因为这样即使设备断电了,数据也不会丢失。
磁盘是一个慢的离谱的存储设备,有多离谱呢?内存的访问速度是纳秒级别的,而磁盘访问的速度是毫秒级别的,也就是说读取同样大小的数据,磁盘中读取的速度比从内存中读取的速度要慢上万倍,甚至几十万倍。
磁盘读写的最小单位是扇区,扇区的大小只有 512B
大小,操作系统一次会读写多个扇区,操作系统的最小读写单位是块(Block)。Linux 中的块大小为 4KB
,也就是一次磁盘 I/O 操作会直接读写 8
个扇区。
事务:一个或一组sql语句组成的最小执行单元,它们综合在一起才是一个完整的工作单元,这些动作必须全部完成,如果有一个失败的话,那么事务就会回滚到最开始的状态,仿佛什么都没发生过一样。
数据库事务是保证在并发情况下能够正确执行的重要支撑,MySQL常见的数据库引擎中支持事务的是InnoDB。
事务要保证能够正常的执行,就必须要保持ACID特性:
1、MySQL Community Server 社区版本,开源免费,但不提供官方技术支持。
2、MySQL Enterprise Edition 企业版本,需付费,可以试用30天。
3、MySQL Cluster 集群版,开源免费。可将几个MySQL Server封装成一个Server。
4、MySQL Cluster CGE 高级集群版,需付费。
5、MySQL Workbench(GUI TOOL)一款专为MySQL设计的ER/数据库建模工具。它是著名的数据库设计工具DBDesigner4的继任者。MySQL Workbench又分为两个版本,分别是社区版(MySQL Workbench OSS)、商用版(MySQL Workbench SE)。