ready
This chapter requires two linux systems, install the database in the two linux systems, the ip addresses of the two linux must be different, if they are the same, change the ip address
本章使用的数据库可视化软件是:SQLyogEnt
Modify the ip address to
install the database
Database optimization instructions
Scenes :
The records in the database should be as safe as possible. If the data is lost, it will cause irreparable losses, so we hope this happens!!!
Description:
According to the needs of users, the database files are regularly backed up/dumped to ensure data security.
Cold backup instructions:
Cold backup can meet the above requirements. However, cold backup has shortcomings and is more troublesome to operate.
Disadvantages-
-
This operation requires manual operation
-
Since cold backup is not real-time, it may cause data loss
-
If the file of the backed up database is large, the backup time is long and it is easy to make mistakes
说明: 数据的冷备份是公司恢复数据最后有效的手段.
Hot backup instructions:
Hot backup brings us a lot of convenience, and the backup steps are a bit troublesome. However, after the backup, there is no need to manually back up.
Backup steps:
-
When the user modifies the data, the modified data will be written to the binary log file
-
Read the records in the main library from the library through the IO thread. Write the data to the relay log
-
The Sql thread reads the data information. It is written to the slave library through the sql statement
The database backup function is a native service of the database. So there is no need for third-party intervention...
注意事项: 数据库中的二进制日志文件 默认的条件下是关闭的.如需备份,需要手动的开启.
Realize database hot backup operation
1) - Open the binary log of the main library
主库: 192.168.126.129
从库: 192.168.126.130
二进制文件的目录
vim /etc/my.cnf
Operation of the main library
After entering the my.cnf file, write the two configurations in the picture next
2) - Restart the database to check the binary file information
命令 : systemctl restart mariadb
After completion, restart the database and then enter the working directory of the database and check whether the configuration is correct
如果有图片中的mysql-bin前缀的文件,那就成功了
3)-Data backup
Description: In the main library of the database, dump the jtdb.sql (database) file. Then use the sql tool to import from the library.
就是主库的数据库和从库的数据库一致,所以主库的数据库复制到从库中
Main library
Slave library
4) - Open the binary file from the library
二进制文件的目录
vim /etc/my.cnf
Operation from the library
After entering the my.cnf file, write the two configurations in the picture next
Restart the mysql database to check whether there is binary file information
After the configuration is complete, restart the database. Check in the working directory of the database to see if it is successful. If there are two files with the mysql-bin prefix, then it is successful.
Realize database master-slave mount
1) - Check the status of the main library
The status of the main library
Check if there is a mapped binary file in the main library,
If you need to regenerate the binary file information, you can manually delete the file
-
1-- Delete all files prefixed by mysql-bin
-
2-- Restart the database
-
3-- Automatically regenerate files
2) - Check the status of the main library
在可视化软件中 查看状态
Execute in the main library
SHOW MASTER STATUS;
3)-Realize the master-slave construction of the database
Execute from library
/*130 数据库从库 IP地址/端口号/用户名/密码/
二进制文件名称/二进制文件的位置*/
CHANGE MASTER TO MASTER_HOST="192.168.126.129",
MASTER_PORT=3306,
MASTER_USER="root",
MASTER_PASSWORD="root",
MASTER_LOG_FILE="mysql-bin.000001",
MASTER_LOG_POS=245;
/*2.启动数据库主从服务*/
START SLAVE;
/*3.检查主从的状态*/
SHOW SLAVE STATUS;
/*4.搭建错误 1).关闭主从服务 */
/*4.1 关闭主从服务*/
STOP SLAVE;
/*4.2 检查报错信息 last_sql_error last_io_error 根据日志查询状态*/
/*4.3 重新搭建主从服务 */
这些命令在 可视化软件中执行 按步骤来执行
3) – Build verification
View command
SHOW SLAVE STATUS;