mysql database cold backup, cold backup migration of mysql database, and mysql startup can not log in, detailed articles~! ~

Environmental preparation

Two centos7, close the firewall and selinux
A ——192.168.112.153
B ——192.168.112.172

-153 A terminal operation

1. Install the database

yum -y install mariadb mariadb-server

2. Start the database

systemctl start mariadb

3. Log in to the database, build database and table

create database dyw charset utf8;   

use dyw

create table yy(id int(3), name varchar(6));

insert into yy value(7,'tom');

 select * from yy;
 

-Renderings
Insert picture description here
Insert picture description here
Insert picture description here

4. Close the database

myslqadmin -uroot shutdown

Both are wide

systemctl stop mariadb

5. Enter the catalog, package, and send to B

  cd /var/lib/
  tar zcf mysql.tar.gz mysql/
  scp mysql.tar.gz 192.168.112.172:/root/

-172 B-side operation

6. Install the database

yum -y install mariadb mariadb-server

7. Start the database and check the files

systemctl start mariadb

-Renderings
Insert picture description here

8. Close the database and prepare for cold standby

myslqadmin -uroot shutdown

Both are wide

systemctl stop mariadb

9. Unpack, copy

Insert picture description here
Insert picture description here

10. Delete the original datadir path

rm -rf /var/lib/mysql/

11. Modify the configuration file

1~3 add port and socket items
5~6 lines modify datadir directory and socket path

Insert picture description here

11. Modify the owner/group, add permissions

chown -R mysql:mysql /home/mysql
chmod 700 /home/mysql/test/

12. Start the service, login authentication

Insert picture description here
Insert picture description here

mysql startup cannot log in

Insert picture description here
Add port and socket to the configuration file to
Insert picture description here
restart, you can log in

Guess you like

Origin blog.csdn.net/qing1912/article/details/109292940