One way to maintain data is to routinely backup the database and store it in two different places, on the server and on the personal computer.
Both websites that use VPS or Shared Hosting still have to make backups.
How to backup MySQL database with Command Line / Terminal
This first method is usually needed if you have a website that is placed on a VPS (Virtual Private Server). Because unmanaged VPS types usually do not have a control panel like cPanel or Plesk, it must be done manually.
Get to know the mysqldump command in Command Line / Terminal
It is very important to know the mysqldump command if you manage your own website using a VPS service. The syntax used is as follows.
mysqldump -u [username] -p [password] [database_name]> [file_name_backup.sql]
The code above is the mysqldump writing format, then how about the example, on this occasion punyaakil.xyz will demonstrate several types of ways to backup mysql with various purposes.
In this example all use the MySQL root username and are done on a Linux-based VPS shell / terminal.
Backup sata database with Command Line Terminal
Fill in the file there will be a DROP command to delete all tables, then create a table and the data will be entered again. All of these things are useful in the data recovery process (restore backup) so that there are no conflicts or duplicate data.
mysqldump -u root -p while jurnalwebcom> punyaakilxyz.sql
Backup more than one database with Command Line Terminal
In this example the --databases parameter is added to instruct the program that there is more than one database that you want to back up. Database names to be backed up are separated by spaces.
mysqldump -u root -p while --databases punyaakilxyz mantul> punyaakilxyz_mantul.sql
Backup all MySQL databases with Command Line Terminal
If you forget, are lazy or feel troubled to choose a database that you want to backup one by one, then the choice is of course to backup all the MySQL databases that exist on the server by adding the --all-databases parameter. The writing example is as follows.
mysqldump -u root -p while --all-databases> all. sql
If the important data that you want to back up is only found in one particular table, then of course it will be redundant if it is backed up entirely, so just backup one table, this is how:
mysqldump -u root -p temporary punyaakilxyz blog> punyaakilxyz_blog.sql
The above command will do a backup of the blog table in the punyaakilxyz database into a file called punyaakilxyz_blog.sql.
How to restore the mysql database in the Command Line Terminal
After you have a backup file, it is sometimes necessary to restore the database using the backup file, for example if an error occurs afterwards. The way to restore mysql database is as follows:
mysql -u root -p while punyaakilxyz < punyaakilxyz.sql
Keep in mind that in the restore process we use the mysql command (not using a dump), and the direction of the arrow is slightly different from the backup process, the restore process is reversed (<).
This method applies to all types of restore, either restore the database or restore only one table. The command will return data from the punyaakilxyz.sql file to the database with the name punyaakilxyz.
You can use the method above also on databases that use MariaDB or Percona Server because they are from the same family, is a fork from MySQL and is still compatible so it is safe to try.


No comments:
Post a Comment