Mithridates's avatar

export database data from local to production

I have almost finished a web app built with laravel.
now, there are some data that are production end data and are not dummy so to speak.
Can I add them while the app is local and in some way export those data to production end?
Or I should just add them while the app is in production mode?

0 likes
4 replies
fullbl's avatar

personally I use seeders also with production data, but you can also add them in a migration!

sitesense's avatar

Seeders are a good choice when it's a relatively small amount of data, otherwise just use mysqldump or a tool such as Navicat/Sequel Pro to export/import.

backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
Mithridates's avatar

@sitesense thanks for the answer. I'm using navicat premium, how can I export my database data from local machine to the production.

goatshark's avatar

@Mithridates I tend to use seeders when it is data that I'm always going to want in my application... like tables that (mostly) serve to hold lists that will be in dropdown/select fields in tables. If it's actual pseudo-user-entered data that you just want to push to your first production install, a db export then import is probably good. Navicat is nice, but I tend to use 'mysqldump' for this and then 'mysql' to restore.

To dump the db:

mysqldump --opt mydatabase > mydatabase.sql

Then after moving mydatabase.sql to the production server:

mysql mydatabase < mydatabase.sql

...of course, you might need to include -u username and/or -h hostname and/or -p for password prompt. Using the -h hostname, you can probably accomplish this without having to copy mydatabase.sql to the production server. For example:

From localhost, assuming you need to give it a password:

mysqldump --opt -u Username -p MyDatabaseName > MyDatabaseName.sql

Which will drop the dumped db into MyDatabaseName.sql in whatever directory you're in when you execute it. Then, to push it to the remote/production database:

mysql -u Username -p -h remote_hostname_or_ip < MyDatabaseName.sql

Please or to participate in this conversation.