一、思维导图
二、笔记
1. 区分数据库与实例
数据库(Database)
:物理操作系统文件和其他形式的文件类型的集合。(数据库 = 文件集合)实例(Instance)
:MySQL 数据库由后台线程以及一个共享内存区组成。其中后台线程可以共享共享内存区 (实例 = 线程 + 一个共享内存区)
数据库实例才是真正用于操作数据库文件的。
正常情况下:一个数据库对应一个数据库实例
集群情况下:一个数据库对应若干个数据库实例
MySQL 是一个单进程多线程架构的数据库
2. 查看 MySQL 实例
MySQL 数据库实例在 Linux 下表现为一个
进程
下列中进程号为 21350 的进程,即是已经启动的 MySQL 数据库实例
root@gongruiyang:~# ps -ef | grep mysql
root 21193 955 0 13:59 pts/1 00:00:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql 21350 21193 0 13:59 pts/1 00:00:02 /usr/sbin/mysqld
--basedir=/usr
--datadir=/var/lib/mysql
--plugin-dir=/usr/lib/mysql/plugin
--user=mysql
--skip-grant-tables
--log-error=/var/log/mysql/error.log
--pid-file=gongruiyang.pid
root 21658 21426 0 14:17 pts/0 00:00:00 grep --color=auto mysql
basedir
:根目录地址datadir
:数据库(文件)所在路径
3. 配置文件读取顺序
当启动 MySQL 数据库实例时,MySQL会去读取配置文件,根据配置文件的参数来启动数据库实例
- Linux下读取配置文件顺序:
/etc/my.cnf
->/etc/mysql/my.cnf
->~/.my.cnf
root@gongruiyang:/etc/mysql# mysql --help | grep my.cnf
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
- Windows下读取配置文件顺序:
C:\WINDOWS\my.ini
->C:\WINDOWS\my.cnf
->C:\my.ini
->C:\my.cnf
->C:\Program Files\MySQL\MySQL Server 5.7\my.ini
->C:\Program Files\MySQL\MySQL Server 5.7\my.cnf
C:\Users\1111>mysql --help
Default options are read from the following files in the given order:
C:\WINDOWS\my.ini
C:\WINDOWS\my.cnf
C:\my.ini
C:\my.cnf
C:\Program Files\MySQL\MySQL Server 5.7\my.ini
C:\Program Files\MySQL\MySQL Server 5.7\my.cnf