Import/Export Database via SSH

May 22, 2023 Author: korjeek

Works faster and more reliably than through phpmyadmin and with databases of any size.

On large databases, in order not to crash the server, we use the configuration
mysqldump -u USER -p –single-transaction –quick –lock-tables=false DATABASE | gzip > OUTPUT.gz

  1. Go to the client’s SSH server
  2. Test Mysql connection mysql -u [DB_username] -p (will ask for password)
  3. See if the user is the right one (list of databases) show databases;
  4. Checking the availability of free space on the client’s hosting (if possible)
  5. Go to the directory where we want to get the dump
  6. Dumping mysqldump -u [Username] -p [DBname] > [filename].sql (it will ask for a password and silently start working. That is, you have to wait until the BASH prompt appears to enter – it means the file is ready)
  7. Copy the created file to the development server in the folder /var/www/html/storage/db
  8. Go to phpmyadmin on the development server
  9. Rename the target database if it exists, adding the index _1, _2 or the next one after its name CAREFULLY! through the section Operations
  10. Create a database user (as in hosting)
  11. When creating a user, check the box “Create database with same name and grant all privileges.”
  12. Create a new database with the desired name (home section) – the encoding of the new database must be the same as that of the copied one!!
  13. Go to the created database in the Privileges section and check that the user with the name of this database has full access to it
  14. SSH into the development server
  15. Go to the folder /var/www/html/storage/db
  16. Run the command mysql -u [DBUsername] -p [DBName] < [filename].sql if everything is OK, you will have to wait similarly to step 7
  17. Checking the database with phpmyadmin
  18. Checking site performance
  19. Remove the database you made in step 9.

Source: http://qaru.site/questions/114074/how-can-i-slow-down-a-mysql-dump-as-to-not-affect-current-load-on-the-server

Leave a Reply

Your email address will not be published. Required fields are marked *

Begin work on your project today
Contact us on Telegram. Ask a question and get a quick response.
or
Message
in Telegram
By clicking the button, you give your consent to the processing of personal data and agree to the privacy policy.