2

Disclaimer: I'm a total green horn.

I'm working with PhpStorm on Windows, which offers a convenient way of creating and managing databases during development. Unfortunately, now that I want to push to production, uploading the database to Cloadways (Digital Ocean Server) doesn't seem that simple.

Cloudways' Database Manager has an import function, that requires .gz (gzip) files. gzip files can not be created from directories, but on Windows mysql creates directories for each database and fills them with table files (.ibd).

I've read that you can compress directories into .tar files first and then gzip them (database.tar.gz) and that's what I tried. But when I try to import them with the database manager it only shows this:

enter image description here

Is there any way to do this?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Artur Müller Romanov
  • 4,417
  • 10
  • 73
  • 132
  • 3
    You wouldn't import the raw MySQL files - use `mysqldump` to get an SQL file, zip that, then upload it – Clive Nov 08 '21 at 13:53
  • https://dev.mysql.com/doc/mysql-backup-excerpt/5.7/en/backup-methods.html – RiggsFolly Nov 08 '21 at 13:58
  • copying with row files only work, with thesame version of mysql and whyn you copy **all files** from the data directory but the mysqldump method is simpler. If you have a big database you could try a replication – nbk Nov 08 '21 at 14:08

1 Answers1

0

Here's what you need to migrate your data to another MySQL server from your development machine: A text file named whatever.sql containing the definitions and contents of your tables (and views and stored functions and all your other database objects). This kind of text file is often called a mysqldump file. You'll find these files contain a whole mess of SQL statements, mostly CREATE TABLE and INSERT. They also contain some lines like

/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;

These look like comments, but when you load the file they're handled as SQL statements, so leave them alone.

You can use gzip(1) on your file to make it smaller, and Cloudways will handle it correctly. Things will work either with or without gzip.

How to export

With PhpStorm, open up the database panel and right-click on your database name (not the server name itself, but your application's database). You'll see a menu item Export with mysqldump. Click it. You can keep the default checkbox settings.

Then give a filename for your output and run the export.

I use PhpStorm on linux, so I'm not totally sure this export works on Windows. If it doesn't, download Ansgar Becker's free and excellent Windows MySQL client program called HeidiSQL. Right click on the database name then choose Export Database as SQL. Check the Create Tables box and choose Insert from the data pulldown.

How to import to production

  1. Log into the production MySQL server.
  2. Create the database and choose it. Cloudways looks like it does that for you. If not, issue these SQL statements.
     CREATE DATABASE myDatabaseName;
     USE myDatabaseName;
    
  3. Use an appropriate tool to run all the SQL in your whatever.sql file. Cloudways looks like it does that for you too. If not, this command line, or something similar, might work.
    mysql --user=yourMySQLUserName --password=secret\  
          --database=myDatabaseName\
          --host=cloudways.example.com < whatever.sql
    

Your migration will be complete.

Extra bonus: If your whatever.sql file contains the initial state of your production database, you can put it into git (or other source control) and use it whenever you deploy a new instance of your software package.

Don't try to copy those .ibd files and other files managed by MySQL to another machine. If you do, you'll be sorry.

O. Jones
  • 103,626
  • 17
  • 118
  • 172