Importing data from an external MariaDB or MySQL database to an RDS for MariaDB or RDS for MySQL DB instance
You can also import data from an existing MariaDB or MySQL database to a MySQL or
MariaDB DB instance. You do so by copying the database with mysqldumpmysqldump
command
line utility is commonly used to make backups and transfer data from one MariaDB or MySQL
server to another. It's included with MySQL and MariaDB client software.
Note
If you are importing or exporting large amounts of data with a MySQL DB instance, it's
more reliable and faster to move data in and out of Amazon RDS by using
xtrabackup
backup files and Amazon S3. For more information, see Restoring a backup into an Amazon RDS for MySQL DB
instance.
A typical mysqldump
command to move data from an external database to an
Amazon RDS DB instance looks similar to the following.
mysqldump -u
local_user
\ --databasesdatabase_name
\ --single-transaction \ --compress \ --order-by-primary \ -plocal_password
| mysql -uRDS_user
\ --port=port_number
\ --host=host_name
\ -pRDS_password
Important
Make sure not to leave a space between the -p
option and the entered
password.
Specify credentials other than the prompts shown here as a security best practice.
Make sure that you're aware of the following recommendations and considerations:
-
Exclude the following schemas from the dump file:
sys
,performance_schema
, andinformation_schema
. Themysqldump
utility excludes these schemas by default. -
If you need to migrate users and privileges, consider using a tool that generates the data control language (DCL) for recreating them, such as the pt-show-grants
utility. -
To perform the import, make sure the user doing so has access to the DB instance. For more information, see Controlling access with security groups.
The parameters used are as follows:
-u
– Use to specify a user name. In the first usage of this parameter, you specify the name of a user account on the local MariaDB or MySQL database identified by thelocal_user
--databases
parameter.--databases
– Use to specify the name of the database on the local MariaDB or MySQL instance that you want to import into Amazon RDS.database_name
-
--single-transaction
– Use to ensure that all of the data loaded from the local database is consistent with a single point in time. If there are other processes changing the data whilemysqldump
is reading it, using this parameter helps maintain data integrity. --compress
– Use to reduce network bandwidth consumption by compressing the data from the local database before sending it to Amazon RDS.--order-by-primary
– Use to reduce load time by sorting each table's data by its primary key.-p
– Use to specify a password. In the first usage of this parameter, you specify the password for the user account identified by the firstlocal_password
-u
parameter.-u
– Use to specify a user name. In the second usage of this parameter, you specify the name of a user account on the default database for the MariaDB or MySQL DB instance identified by theRDS_user
--host
parameter.--port
– Use to specify the port for your MariaDB or MySQL DB instance. By default, this is 3306 unless you changed the value when creating the instance.port_number
-
--host
– Use to specify the Domain Name System (DNS) name from the Amazon RDS DB instance endpoint, for example,host_name
myinstance.123456789012.us-east-1.rds.amazonaws.com
. You can find the endpoint value in the instance details in the Amazon RDS Management Console. -
-p
– Use to specify a password. In the second usage of this parameter, you specify the password for the user account identified by the secondRDS_password
-u
parameter.
Make sure to create any stored procedures, triggers, functions, or events manually in
your Amazon RDS database. If you have any of these objects in the database that you are copying,
then exclude them when you run mysqldump
. To do so, include the following
parameters with your mysqldump
command: --routines=0 --triggers=0
--events=0
.
The following example copies the world
sample database on the local host
to a MySQL DB instance.
For Linux, macOS, or Unix:
sudo mysqldump -u
localuser
\ --databasesworld
\ --single-transaction \ --compress \ --order-by-primary \ --routines=0 \ --triggers=0 \ --events=0 \ -plocalpassword
| mysql -urdsuser
\ --port=3306
\ --host=myinstance.123456789012.us-east-1.rds.amazonaws.com
\ -prdspassword
For Windows, run the following command in a command prompt that has been opened by right-clicking Command Prompt on the Windows programs menu and choosing Run as administrator:
mysqldump -u
localuser
^ --databasesworld
^ --single-transaction ^ --compress ^ --order-by-primary ^ --routines=0 ^ --triggers=0 ^ --events=0 ^ -plocalpassword
| mysql -urdsuser
^ --port=3306
^ --host=myinstance.123456789012.us-east-1.rds.amazonaws.com
^ -prdspassword
Note
Specify credentials other than the prompts shown here as a security best practice.