rds

All posts in this category.

Restaurer un cluster rds aurora mysql depuis un snapshot

Créer le cluster d’abord et ensuite une fois qu’il est prêt ajouter une instance:

aws rds restore-db-cluster-from-snapshot \
    --db-cluster-identifier restored-db-01-march \
    --snapshot-identifier awsbackup:job-fdgdfsgds-5ef1-c33b-dfdfgdsfg \
    --engine aurora-mysql \
    --engine-version 5.7.mysql_aurora.2.10.3 \
    --db-cluster-parameter-group-name test-aurora-57-cluster-parameter-group \
    --vpc-security-group-ids sg-dfsqdgqfdsf \
    --db-subnet-group-name aurora-fdsqfdqs-mysql-dfdqsfqsdf

aws rds create-db-instance \
  --db-instance-identifier restored-db-01-march \
  --db-instance-class db.t4g.medium \
  --engine aurora-mysql \
  --db-cluster-identifier restored-db-01-march

Depuis la console aws ca se fait en une seule fois

mysqldump: Couldn’t execute ‘FLUSH TABLES WITH READ LOCK’: Access denied for user ‘admin’@’%’ (using password: YES) (1045)

Sous ubuntu 20/22 aws rds

apt-get install mysql-client-core-8.0=8.0.19-0ubuntu5
apt-mark hold mysql-client mysql-client-core
mysqldump --set-gtid-purged=OFF --single-transaction --column-statistics=off --skip-lock-tables -h xxx.us-east-1.rds.amazonaws.com -uadmin -pxxx xxx > xxx.sql

ne fonctionne aucunement pas avec d’autres versions 8.0.19+ ….

Get a list of all mysql users and their privileges

mysql -h***.us-west-2.rds.amazonaws.com -uroot -p*** --raw --silent -e "SELECT CONCAT('SHOW GRANTS FOR ''', user, '''@''', host, ''';') AS query FROM mysql.user" > /tmp/users.sql

This command uses the MySQL command line tool to generate a SQL file called « users.sql » in the /tmp directory. The SQL file contains a series of SHOW GRANTS statements for each user on the database.

mysql -h***.us-west-2.rds.amazonaws.com -uroot -p*** --raw --silent -e "source /tmp/users.sql" > /tmp/grants.sql ​

This command executes the SHOW GRANTS statements in the « users.sql » file and saves the output to a new SQL file called « grants.sql » in the /tmp directory.

sed -i 's/$/;/g' /tmp/grants.sql

This command uses sed to add a semicolon at the end of each line in the « grants.sql » file. This is necessary to make the file a valid SQL script.

After running these commands, the « grants.sql » file in the /tmp directory will contain a series of GRANT statements for each user on the database, allowing you to easily see the permissions granted to each user.