How to copy the database in mysql? Or, copy the database to another machine?
According to my understanding, when copying the database, if it is:
1. Directly copy the database file, you should stop the data service first, otherwise it will not be copied. However, how can the production machine stop at any time?
2. For online copying, follow the backup-restore path.
"No, mysql can copy database files directly without stopping the service. I have used it before," a colleague said.
Oh, such a good thing! mySql is indeed awesome. However, I searched online and found that mysql has two modes: innoDB and myISAM. If innoDB is copied directly online, it may cause damage to the database file! I fork.
So, to be cautious, it is better to backup and restore honestly.
1. Back up the
DOS window and type
mysqldump -u root -p test1>c:\temp\dump.txt
directly. Tip: You need to set the path to allow the system to recognize the mysql command. For example:
1) Set the system variable MYSQL_HOME=C:\Program Files\MySQL\MySQL Server 5.7
2) PATH += %MYSQL_HOME%\bin;
Then, dump Copy .txt to the target server
2. Restore
Now we want to restore the file named test1 back.
Open mysql command line client (awesome, command line). I installed mysql yesterday and I looked everywhere for a graphical interface. I thought I installed it wrong. In fact, if you want a graphical UI, you need to install something called mysql banch. East)
Create test1 first. Of course, other names are also acceptable. Then,
mysql -u root -p mysql>create database test1; mysql>use test1; mysql>source c:\temp\dump.txt #注意后面别带;号
mysql how to copy the database? Or, copy the database to another machine?
According to my understanding, when copying the database, if it is:
1. Directly copy the database file, you should stop the data service first, otherwise it will not be copied. However, how can the production machine stop at any time?
2. For online copying, follow the backup-restore path.
"No, mysql can copy database files directly without stopping the service. I have used it before," a colleague said.
Oh, such a good thing! mySql is indeed awesome. However, I searched online and found that mysql has two modes: innoDB and myISAM. If innoDB is copied directly online, it may cause damage to the database file! I fork.
So, to be cautious, it is better to backup and restore honestly.
1. Back up the
DOS window and type
mysqldump -u root -p test1>c:\temp\dump.txt
directly. Tip: You need to set the path to allow the system to recognize the mysql command. For example:
1) Set the system variable MYSQL_HOME=C:\Program Files\MySQL\MySQL Server 5.7
2) PATH += %MYSQL_HOME%\bin;
Then, dump Copy .txt to the target server
2. Restore
Now we want to restore the file named test1 back.
Open mysql command line client (awesome, command line). I installed mysql yesterday and I looked everywhere for a graphical interface. I thought I installed it wrong. In fact, if you want a graphical UI, you need to install something called mysql banch. East)
Create test1 first. Of course, other names are also acceptable. Then,
mysql -u root -p mysql>create database test1; mysql>use test1; mysql>source c:\temp\dump.txt #注意后面别带;号
The above is the content of mysql backup and restoration. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!