Last update at :2024-06-28,Edit by888u
Snail has mentioned using mysqldump to back up the website database in the article "Linux VPS using commands to quickly import/backup MYSQL database". Many friends mentioned that compared with using PHPMYADMIN to export, it is more complete. . Of course, for websites with small databases, there is basically no big difference between using PHPMYADMIN to export the database and using MYSQLDUMP. The latter may be more accurate and complete when the data structure is complex or the database is large.
I compiled this article today. Firstly, I didn’t understand it very well when I shared the article. Secondly, I wanted to organize and learn the detailed usage of the legendary mysqldump method to backup and restore the MYSQL database.
First, commonly used backup MYSQL database
mysqldump -u database username -p database password database name > database file name.sql
This is our common method for backing up the database. First edit the database connection information of the website, then enter it in SSH. After pressing Enter, the SQL database file will be backed up in our current directory.
Second, back up the database across hosts
mysqldump –host=host1 –opt sourceDb| mysql –host=host2 -C targetDb
This method can copy the sourceDb in the host1 host to the targetDb in the Host2 host, but Host2 must have created the targetDb database in advance.
Third, database recovery and restoration
mysql -u database username -p database password database name Similarly, it is similar to the first method. Edit the script link above, and then restore the database in the corresponding site directory. The premise is that we need to upload the SQL file to the current directory first. For ordinary users, these methods are enough. If you are not sure about the integrity of the backup, you can refer to "4 methods for common Linux VPS hosts to back up MYSQL databases" to use a variety of different methods to back up the website database. Backup. If our website is to be moved, it is best to delete the original data after the migration is successful and there are no problems to ensure integrity. Recommended site search: website registration and cancellation, in domain name, free domain name registration, virtual host, domain name resolution IP address query, Chinese domain name, Japanese server rental Japanese server, anti-complaint server, free domain name registration, Tencent cloud server,
发表评论