{"_id":"5bb53b2e5f3b970003579ce1","project":"54cf411f9d09bb0d00a17a1c","version":{"_id":"54cf411f9d09bb0d00a17a1f","project":"54cf411f9d09bb0d00a17a1c","__v":15,"createdAt":"2015-02-02T09:19:27.656Z","releaseDate":"2015-02-02T09:19:27.656Z","categories":["54cf41209d09bb0d00a17a20","54cfb99bbba1a023008741af","54cfb9a65ff7e617002bbd7f","54cfba03bba1a023008741b6","54cfba0ebba1a023008741b8","54cfba19bba1a023008741b9","54cfba29bba1a023008741bb","54cfba345ff7e617002bbd87","54cfba3ebba1a023008741bc","54cfba473995cf0d0006f6f0","54e371b18ef7552300409bf2","54e37aa5e887c50d005ef629","555a4e9b147f91190092d137","56b0e91802f4bc0d006ce254","5bb4f4e01635b500032b94fd"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"5bb4f4e01635b500032b94fd","project":"54cf411f9d09bb0d00a17a1c","version":"54cf411f9d09bb0d00a17a1f","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2018-10-03T16:57:04.619Z","from_sync":false,"order":7,"slug":"migrating","title":"Migrating to AWS Cloud9"},"user":"5bac0709475b5d000364fa42","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2018-10-03T21:57:02.937Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":10,"body":"After following the steps in [Uploading Files from Your Computer](doc:uploading-files-from-your-computer) or [Downloading Files from a Source Code Repository](doc:downloading-files-from-a-source-code-repository), and after [Installing a Database](doc:installing-a-database), you should now have one or more database files and the database itself in your new AWS Cloud9 environment.\n\nWith your AWS Cloud9 environment [open](https://docs.aws.amazon.com/cloud9/latest/user-guide/open-environment.html), complete one of the following sets of instructions to get the contents of those database files into your database.\n\nThis topic covers the following database types: \n\n* MySQL\n* PostgreSQL\n* MongoDB\n\n# To import data into MySQL\n\nIf the data is in a .sql file inside of a compressed GZ file, use [gzip](https://www.computerhope.com/unix/gzip.htm) to get the .sql file out of the compressed GZ file. \n\nFor example, the following command gets the .sql file out of a compressed GZ file named **mysqldump-my-workspace-name_YYYY-MM-DD.sql.gz**. The command then runs the MySQL commands in the extracted .sql file against the local MySQL installation: \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"gzip -dc < \\\"mysqldump-my-workspace-name_YYYY-MM-DD.sql.gz\\\" | mysql -u root -p\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nNote that if you have not changed the password for the **root** user, the password is blank by default.\n\nIf the data is in a .sql file, use [mysql](https://www.google.com/search?q=mysqldump+example) to get the data into the database.\n\nFor example, the following command uploads the contents of the database file named **my_database_name_dump.sql** into the database: \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"mysql -u root -p < my_database_name_dump.sql\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nNote that if you have not changed the password for the **root** user, the password is blank by default.\n\n(See more examples [here](https://dev.mysql.com/doc/refman/8.0/en/reloading-sql-format-dumps.html), [here](https://stackoverflow.com/questions/17666249/how-to-import-an-sql-file-using-the-command-line-in-mysql), and [here](https://www.cyberciti.biz/faq/import-mysql-dumpfile-sql-datafile-into-my-database/).)\n\nWhen you're done, [return to the migration checklist](migration-checklist#section-step-6-import-data-into-a-database-in-your-new-environment).\n\n# To import data into PostgreSQL\n\nUse [psql](https://www.postgresql.org/docs/current/static/backup-dump.html#BACKUP-DUMP-RESTORE). \n\nFor example, the following command uploads the contents of the database file named **my_database_name_dump.sql** in the current directory to a database named **my_database_name**:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"psql my_database_name < my_database_name_dump.sql\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nWhen you're done, [return to the migration checklist](migration-checklist#section-step-6-import-data-into-a-database-in-your-new-environment).\n \n# To import data into MongoDB\n\nUse [mongorestore](https://docs.mongodb.com/manual/reference/program/mongorestore/). \n\nFor example, the following command uploads the contents of the **my_database_name_dump.archive** in the current directory to a database named **my_database_name**:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"mongorestore --db my_database_name --archive=my_database_name_dump.archive\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nHere are some more [mongorestore examples](https://docs.mongodb.com/manual/reference/program/mongorestore/#examples).\n\nWhen you're done, [return to the migration checklist](migration-checklist#section-step-6-import-data-into-a-database-in-your-new-environment).\n\n# See also\n\n* [Restoring Your WordPress Database from Backup](https://codex.wordpress.org/Restoring_Your_Database_From_Backup)","excerpt":"","slug":"uploading-data-to-a-database","type":"basic","title":"Importing Data to a Database"}

Importing Data to a Database


After following the steps in [Uploading Files from Your Computer](doc:uploading-files-from-your-computer) or [Downloading Files from a Source Code Repository](doc:downloading-files-from-a-source-code-repository), and after [Installing a Database](doc:installing-a-database), you should now have one or more database files and the database itself in your new AWS Cloud9 environment. With your AWS Cloud9 environment [open](https://docs.aws.amazon.com/cloud9/latest/user-guide/open-environment.html), complete one of the following sets of instructions to get the contents of those database files into your database. This topic covers the following database types: * MySQL * PostgreSQL * MongoDB # To import data into MySQL If the data is in a .sql file inside of a compressed GZ file, use [gzip](https://www.computerhope.com/unix/gzip.htm) to get the .sql file out of the compressed GZ file. For example, the following command gets the .sql file out of a compressed GZ file named **mysqldump-my-workspace-name_YYYY-MM-DD.sql.gz**. The command then runs the MySQL commands in the extracted .sql file against the local MySQL installation: [block:code] { "codes": [ { "code": "gzip -dc < \"mysqldump-my-workspace-name_YYYY-MM-DD.sql.gz\" | mysql -u root -p", "language": "shell" } ] } [/block] Note that if you have not changed the password for the **root** user, the password is blank by default. If the data is in a .sql file, use [mysql](https://www.google.com/search?q=mysqldump+example) to get the data into the database. For example, the following command uploads the contents of the database file named **my_database_name_dump.sql** into the database: [block:code] { "codes": [ { "code": "mysql -u root -p < my_database_name_dump.sql", "language": "shell" } ] } [/block] Note that if you have not changed the password for the **root** user, the password is blank by default. (See more examples [here](https://dev.mysql.com/doc/refman/8.0/en/reloading-sql-format-dumps.html), [here](https://stackoverflow.com/questions/17666249/how-to-import-an-sql-file-using-the-command-line-in-mysql), and [here](https://www.cyberciti.biz/faq/import-mysql-dumpfile-sql-datafile-into-my-database/).) When you're done, [return to the migration checklist](migration-checklist#section-step-6-import-data-into-a-database-in-your-new-environment). # To import data into PostgreSQL Use [psql](https://www.postgresql.org/docs/current/static/backup-dump.html#BACKUP-DUMP-RESTORE). For example, the following command uploads the contents of the database file named **my_database_name_dump.sql** in the current directory to a database named **my_database_name**: [block:code] { "codes": [ { "code": "psql my_database_name < my_database_name_dump.sql", "language": "shell" } ] } [/block] When you're done, [return to the migration checklist](migration-checklist#section-step-6-import-data-into-a-database-in-your-new-environment). # To import data into MongoDB Use [mongorestore](https://docs.mongodb.com/manual/reference/program/mongorestore/). For example, the following command uploads the contents of the **my_database_name_dump.archive** in the current directory to a database named **my_database_name**: [block:code] { "codes": [ { "code": "mongorestore --db my_database_name --archive=my_database_name_dump.archive", "language": "shell" } ] } [/block] Here are some more [mongorestore examples](https://docs.mongodb.com/manual/reference/program/mongorestore/#examples). When you're done, [return to the migration checklist](migration-checklist#section-step-6-import-data-into-a-database-in-your-new-environment). # See also * [Restoring Your WordPress Database from Backup](https://codex.wordpress.org/Restoring_Your_Database_From_Backup)