当前位置:网站首页>MySQL essay
MySQL essay
2022-07-28 03:02:00 【Struggling bun】
/* View all permissions of the user */
show grants for 'root'@'localhost';
/* Set to match all permissions */
grant all privileges on *.* to 'root'@'%';
/* Refresh the permissions */
flush privileges;
install mysql
bin/mysqld --defaults-file=/usr/local/mysql2/my.cnf --initialize --user=mysql
# Log in to the server after getting the password Set global access and change password , At this point the installation is complete
mysql Loading order of configuration files
| file name | Purpose |
|---|---|
| /etc/my.cnf | Global options |
| /etc/mysql/my.cnf | Global options |
| SYSCONFDIR/my.cnf | Global options |
| $MYSQL_HOME/my.cnf | Server specific options ( Server only ) |
| defaults-extra-file | use Specified file --defaults-extra-file, If any |
| ~/.my.cnf | User specific options |
| ~/.mylogin.cnf | User specific login Path Options ( Client only ) |
mysql Database summary
mysql A database is a system database , Contains storage MySQL A table of information required for the server to run .
Table functions are divided into the following categories :
- Grant system table Grant System Tables
- Object information system table Object Information System Tables
- Record system table Log System Tables
- Server side help system table Server-Side Help System Tables
- Time zone system table Time Zone System Tables
- Copy system tables Replication System Tables
- Optimizer system tables Optimizer System Tables
- Miscellaneous system table Miscellaneous System Tables
The point is Copy the tables of the system , In order to facilitate our future study Database Read / write separation .
gtid_executed: Used to store GTID A table of values , Use InnoDB Storage engine .
ndb_binlog_index: NDB Cluster Copied binary log information .
slave_master_info, slave_relay_log_info, slave_worker_info: Used to store replication information on the replica server .
mysql Server log
| Log Type | Information Written to Log |
|---|---|
| Error log | start-up 、 To run or stop mysqld Log of problems encountered during |
| General query log | Established client connections and statements received from clients |
| Binary log | A statement that changes data |
| Relay log | Data received from the replication source server |
| Slow query log | Execution time exceeded long_query_time A few seconds of inquiry |
| DDL log (metadata log) | DDL Metadata operations executed by statement |
Turn on the general log function
log_output=FILE
general_log=ON
general_log_file=general.log
Focus on binary log journal
binary log Format of log
- be based on SQL sentence binlog-format=STATEMENT
- Line based logging binlog-format=ROW
- Mixed logging binlog-format=MIXED
change bin log Format considerations
- When master-slave synchronization is enabled , If Master slave asynchronous modification , You're going to report a mistake
- Use Read submitted and Read uncommitted transaction isolation level , Only use Line based log format
Set different log formats for different storage engines
| Storage engine | ROW | STATEMENT |
|---|---|---|
| ARCHIVE | Yes | Yes |
| BLACKHOLE | Yes | Yes |
| CSV | Yes | Yes |
| EXAMPLE | Yes | No |
| FEDERATED | Yes | Yes |
| HEAP | Yes | Yes |
| InnoDB | Yes | yes , When transaction isolation level is REPEATABLE READ or when SERIALIZABLE; Otherwise no . |
| MyISAM | Yes | Yes |
| MERGE | Yes | Yes |
| NDB | Yes | No |
bin log Opportunity to generate new bin log journal , Small scale from 1 Start to grow
- The server starts or restarts
- Server refresh log
- The current log file size has reached max_binlog_size
bin log The logging action is in uncommitted transactions , All changes will be cached , until The server received a commit statement .mysqld Write the entire transaction to the binary log before execution . When the thread processing the transaction starts , It will binlog_cache_size Allocate a buffer for buffer statements . If the statement is greater than this value , Then the thread will open a temporary file to store transactions . Delete temporary files at the end of the thread .
binlog To configure
server-id=1
log-bin=/usr/local/mysql/mysql-files/binLog
log_bin_index=/usr/local/mysql/mysql-files/binLogIndex
binlog_cache_size=4096
max_binlog_cache_size=4096
sync_binlog=1
binlog_format=MIXED
/* Set the global variable on bin log*/
SET GLOBAL log_bin = ON;
Slow query log
# Slow query log
slow_query_log=ON
long_query_time=10
min_examined_row_limit=10000
slow_query_log_file=slow.log
log_output=FILE
Backup
# Back up all databases
./bin/mysqldump --all-databases -uroot -p > dump.sql
# Back up the specified database
mysqldump --databases db1 db2 db3 > dump.sql
# Refresh and back up data
mysqldump --single-transaction --flush-logs --master-data=2 --all-databases > backup_sunday_1_PM.sql
# Back up and delete Binary
mysqldump --single-transaction --flush-logs --master-data=2 --all-databases --delete-master-logs > backup_sunday_1_PM.sql
# Import sql
mysql < dump.sql
#sql If there is no statement to create a table in
mysqladmin create db1
mysql db1 < dump.sql
# or
CREATE DATABASE IF NOT EXISTS db1;
USE db1;
source dump.sql
/* Check all the logs */
SHOW BINARY LOGS;
/* View the current log */
SHOW MASTER STATUS;
flush logs;
Full recovery
/* Incremental backup recovery Mode one */
mysqlbinlog binlog.000001 binlog.000002 | mysql -u root -p
/* Incremental backup recovery Mode two */
mysqlbinlog binlog.000001 > /tmp/statements.sql
mysqlbinlog binlog.000002 >> /tmp/statements.sql
mysql -u root -p -e "source /tmp/statements.sql"
Point in time recovery using event location
mysqlbinlog --start-datetime="2020-05-27 12:59:00" --stop-datetime="2020-05-27 13:06:00" \
--verbose /var/lib/mysql/bin.123456 | grep -C 12 "DROP TABLE"
# Restore to the specified event point
mysqlbinlog --start-position=4 --stop-position=1548 binLog.000006 | mysql -u root -p
# Start from the specified event point
mysqlbinlog --start-position=3137 binLog.000006 | mysql -u root -p
Tips Try to do it manually before performing the backup flush logs; Generate a new backup file , avoid binLog A duplicate record of
Clustered index and secondary index
Every InnoDB Tables have a special index , It's called a clustered index , Used to store row data . Usually , A clustered index is synonymous with a primary key .
- Yes PRIMARY KEY,InnoDB Use it as a clustered index .
- If you don't PRIMARY KEY,InnoDB Use the first UNIQUE Indexes , All key columns are defined as NOT NULL.
- If the table has no index PRIMARY KEY Or not suitable Of UNIQUE Indexes , be InnoDB Generate a hidden clustered index , The index is in GEN_CLUST_INDEX Include lines ID Name the composite column of values .
Indexes other than clustered indexes are called secondary indexes . stay InnoDB in , Each record in the secondary index contains the primary key column of the row , And the columns specified for the secondary index . InnoDB Use this primary key value to search the clustered index for rows .
Copy
Copy based on binary log file location
- The source server Create a copy permission account and permission
CREATE USER 'repl'@'%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
- Back up the log files of the source server
./bin/mysqldump --all-databases -uroot -p > dump.sql
- Install replica server
- Configure replica server configuration
[mysqld]
port=3307
datadir=/usr/local/mysql2/mysql-files
socket=/tmp/mysql2.sock
risks
symbolic-links=0
#server id
server-id=2
[mysqld_safe]
log-error=/usr/local/mysql2/mysql-files/mariadb.log
pid-file=/usr/local/mysql2/mysql-files/mariadb.pid
!includedir /etc/my.cnf.d
- Start the slave server with the specified configuration file
- Configure the source server information on the slave server ,post And documents Can be viewed from the source server .
/* Can be viewed from the source server */ SHOW MASTER STATUS;/* Configure the source server information on the slave server ,post And documents */ CHANGE MASTER TO MASTER_HOST='localhost', MASTER_PORT=3306, MASTER_USER='repl', MASTER_PASSWORD='123456', MASTER_LOG_FILE='binLog.000012', MASTER_LOG_POS=154; - Import full data for the source server
- Start the source server SLAVE Threads
START SLAVE;
Complete master-slave configuration .
边栏推荐
- Skills in writing English IEEE papers
- Email security report in the second quarter: email attacks have soared fourfold, and well-known brands have been used to gain trust
- POC simulation attack weapon - Introduction to nucleus (I)
- Typescript (zero) -- introduction, environment construction, first instance
- Building of APP automation environment (I)
- Where do I go to open an account for stock speculation? Is it safe to open an account on my mobile phone
- Some shortest path problems solved by hierarchical graph
- Data Lake: database data migration tool sqoop
- Is it safe to buy funds on Alipay? I want to make a fixed investment in the fund
- MySQL索引学习
猜你喜欢

Data Lake: database data migration tool sqoop

MySQL索引学习

Chapter III queue
![[software testing] - unittest framework for automated testing](/img/7a/29b222cb0b6a5953b98f8d797cd106.png)
[software testing] - unittest framework for automated testing

Center-based 3D Object Detection and Tracking(基于中心的3D目标检测和跟踪 / CenterPoint)论文笔记

为什么登录时,明明使用的是数据库里已经有的账号信息,但依旧显示“用户不存在”?

LoRaWAN中的网关和chirpstack到底如何通信的?UDP?GRPC?MQTT?

JS中的reduce()函数介绍

Retainface use error: modulenotfounderror: no module named'rcnn.cyton.bbox'

智能工业设计软件公司天洑C轮数亿元融资
随机推荐
On the problem that sqli labs single quotation marks do not report errors
一次跨域问题的记录
CNN循环训练的解释 | PyTorch系列(二十二)
Some shortest path problems solved by hierarchical graph
[acnoi2022] one step short
【ELM分类】基于核极限学习机和极限学习机实现UCI数据集分类附matlab代码
【微信小程序开发(五)】接口按照根据开发版体验版正式版智能配置
Welcome to CSDN markdown editor Assad
Canonical Address
小程序已获取数据库合集中的总记录、用户位置,怎么用Aggregate.geoNear将经纬度由近到远排列?
openGauss源代码,用什么IDE工具管理、编辑、调试?
How do you use the jar package sent by others (how to use the jar package sent by others)
LoRaWAN中的网关和chirpstack到底如何通信的?UDP?GRPC?MQTT?
Consolidate the data foundation in the data center
Pychart shortcut key for quickly modifying all the same names on the whole page
MySQL索引学习
windbg
Digital twin agriculture - Smart agriculture rice processing plant has changed from "watching the sky to eat" to "knowing the sky to work"
数据中台建设(三):数据中台架构介绍
How to authenticate Youxuan database client