Today Lesca will describe how to back up and restore MySQL from the server, the platform is still CentOS 7.
Using mysqldump for backup and restore
Using Mysqldump for backup
Mysqladmin stop-slave-uroot-p
Mysqldump--all-databases > Fulldb.dump
Mysqladmin start-slave-uroot-p
tar-czf/tmp/dbdump.tar.gz./fulldb.dump./mysql-relay-log.info
In addition to backing up the entire dump of the database, we also need to back up the Relay-log.info file (the example Mysql-relay-log.info), which contains information similar to the following:
/var/lib/mysql/mysql-relay-bin.000002
720
mysql-bin.000002
3968
The Red highlighted section indicates the execution status of the binary log on the current MySQL master server. This data is critical when restoring from the server.
Using mysqldump to restore
Mysql-uroot-p </root/dbdump.db
Stop slave;
Change MASTER to master_host= ' 192.168.10.201 ', master_user= ' slave_user ', master_password= ' abc@def ', master_log_file= ' mysql-bin.000002 ', master_log_pos=3968;
Start slave;
Show Slave Status\g
In the state, if the following two lines are available, the server is working correctly:
Slave_io_running:yes
Slave_sql_running:yes
Backup and restore using the database file (Raw Data)
Backing Up Database files
Service MARIADB Stop
Tar--selinux--acls--xattrs-czpf/root/dbbackup.tar.gz/var/lib/mysql/
Service MARIADB Start
Note: The red parameter lets tar back up both the SELinux property and other ACL properties to prevent it from being restored to the target server.
Restore Database files
Service MARIADB Stop
Tar--selinux--acls--xattrs-xzpf/root/dbbackup.tar.gz-c/
Service MARIADB Start
Also, you need to specify these parameters when you restore the data files.
Troubleshooting
Error message
150401 9:58:06 [ERROR] mysqld:file '/var/lib/mysql/mysql-bin.index ' not Found (errcode:13)
150401 9:58:06 [ERROR] Aborting
Check SELinux settings
Ll-z Mysql-bin.index
-RW-RW----. MySQL MySQL unconfined_u:object_r:var_lib_t:s0 mysql-bin.index
Solving method
You can disable SELinux (configuration file/etc/selinux/config),
Selinux=disabled
You need to reboot after you have finished modifying it.
You can also add the following parameters to the tar command when compressing and decompressing:
Tar--selinux--acls--xattrs
Expand your knowledge
–selinux–save the SELinux context to the archive
–acls–save the ACLs to the archive
–xattrs–save the User/root xattrs to the archive. IT archives All extended attributes, including SELinux and ACLs.