当前位置:网站首页>MySQL architecture (basic)

MySQL architecture (basic)

2022-06-23 23:55:00 Xiao Wange

mysql Introduction to various connection modes

socket

Prerequisites must be created and authorized localhost user , Only when the database is started will it be generated socket file

mysql A socket file will be automatically generated when starting , This file can be accessed locally to log in mysql

The file defaults to /tmp/mysql.sock You can specify parameters in the configuration file socket= File path To specify the file location

mysql -uroot -p -S/tmp/mysql.sock #mysql  Default to /etc/ look for mysql.sock  Users can also in the configuration file [mysql] End assignment  socket= The file path is enabled by default 

How to confirm that the user is socket Login or TCP/IP The way show processlist; host Column to see how the user logs in

TCP/IP

The premise is that the remote network segment login user must be created and authorized

mysql -utest -p123456 -h10.0.0.51 -P3306
-h Designated host 
-P Designated port   It doesn't make sense to specify alone   You need to specify the  -h host 

mysql be based on ssl Secure links

Check whether the security link function is enabled

show variables like '%ssl%';
have_openssl                        YES            
have_ssl                            YES   

mysql_ssl_rsa_setup Generate by command

Under the data directory, the following... Will be generated under the directory .pem file :

ca.pem # Self signed CA certificate , Client connections also need to be provided

client-cert.pem # The certificate file that the client needs to provide to connect to the server

client-key.pem # The private key file that the client needs to provide to connect to the server

private_key.pem # Private key / Private member of the public key pair

public_key.pem # Private key / A common member of a public key pair

server-cert.pem # Server side certificate file

server-key.pem # Server side private key file

Test link ,

 mysql -ujialiye -p123 -h10.0.0.51 --ssl-cert=/data/mysql/data_3306/client-cert.pem --ssl-key=/data/mysql/data_3306/client-key.pem

mysql The configuration file

mysql Configure file startup sequence

mysqld --help --verbose |grep my.cnf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 
                      my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default

Configuration file read order The default from the /ect/my.cnf Read back There is a duplicate configuration file addition relationship If the configuration file is the same, the last configuration shall prevail

If you start multiple instances, you can add --defaults-file= Profile path To specify the startup configuration file separately

Profile description

[mysqld]  Label item  mysqld The parameters under this tag will be read when running 
[mysql]  Label item  mysql The command will read the parameters under the tag 
[mysqld_safe]  Label item  mysql Safe start is the parameter of the call 
[sever]  Label item   Will cover all server End operation is a parameter of  mysqld, mysqld_safe  Will call the parameters inside 
[client]  Label item   All client programs will be overwritten  mysql,mysqldump

mysql Start the closing process

start-up

 stay mysql There is a support-files Catalog   There's one down there mysql.server file   You can use this file 
 Back plus  start stop restart  Or join systemd management   Script call relationship 
mysql.server----> bin/mysqld_safe----->bin/mysqld
 Each method can start the database 
mysqld &  Parameters can be added for startup   The log will be printed to the screen unless the configuration file specifies that the startup function is not turned off   When debugging, I will use 
mysqld_safe &  Parameters can be added for startup     Log files , It will automatically monitor mysqld The status of the program , If something goes wrong, it will restart automatically 
systemd  start-up   No parameters can be added 

close

 Enter the database 
shutdown
 Use it outside 
mysqlamin -uroot -p123  -S/tmp/mysql.sock shutdown
 System management 
systemd stop 

ps stay 8.0 Updates can be made in mysql in restart

mysql Multiple instances

Multiple examples :

Share server resources , Start multiple instances

Generally used in distributed architecture , Choose a commonly used structure

Other nodes may be used for other replicas

If the budget is relatively small, you can 3 One server does 9 An example ,3 Lord 6 Replica

You can also install different versions on one machine mysql Used to simulate , upgrade , test Debugging and other functions

Multi version installation instructions

Different profile assignments

The data directory is different , Different ports socket Different documents

Create different data directories to grant authorization mysql User permissions

mkdir /data/mysql/data_3307

create profile

vim /data/mysql/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql/data_3307
socket=/tmp/mysql3307.sock
log_error=/data/mysql/data_3307/error.log
default_authentication_plugin=mysql_native_password
server_id=7
log_bin=/data/mysql/binlog_3307
port=3307

initialization

 mysqld --defaults-file=/data/mysql/my.cnf --initialize-insecure

Start database

mysqld_safe --defaults-file=/data/mysql/my.cnf

mysql Tool log description

error log mysql Start to close the entire lifecycle , Except for reporting errors , Warnings are also provided , Information and a series of information

genernal log General journal The whole database operation class will be recorded

bin log Binary log 1 Data recovery 2 Be the master and subordinate

slow log Slow log Record slow query statement

error log Open by default

What problems can I see in the error log Start up failure , Master slave fault , Deadlock , The database is rammed ,

By default, there is a in the data directory hostname.err

Control parameter

log_error=/ Error log location It is better to set before initialization

The log file should be separated from the data file

How to view all parameters about logs

show variables like '%log_error%';

show variables You can view all parameters

log_error_verbosity=3 # This parameter can record the log level

How to adjust online set global log_error_verbosity=3

binlog

Function data recovery

Copy

Record mysql Changes that occur ( Additions and deletions ) Class will be recorded binlog

8.0 Start by default binlog The default is in the data directory

server_id= One is greater than 0 The number of 5.7 Then force

log_bin= route / File name prefix

slowlog Slow log Record during database operation , Slow execution sql

Configuration parameters slow_query_log=on Whether to turn on slow log

long_query_time= Catch the slow execution based on time sql Slow query time The default is seconds

slow_query_log_file= route Slow log storage path

log_queries_not_using_indexe=1 Record queries without index

log_throttle_queries_not_using_indexes=1000; Only the nearest 1000 There is no index

The slow log also records lock information

general_log General journal Text format Record mysql All operation statements during the run

Can do problem diagnosis and debugging

Parameters

general_log= switch

general_log_file= Log storage location and name

mysql Upgrade process

Upgrade risk The upgrade cannot be completed , The application is not connected , There's no problem with the database , Application mismatch A lot of tests have to be done

原网站

版权声明
本文为[Xiao Wange]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/11/20211124091310864l.html