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+ ….
This command will create a new pod named « mysql-client » and start a bash session inside the container running the MySQL client image.
kubectl run mysql-client --image=mysql:8.0 -it --rm --restart=Never -- /bin/bash
Here’s a breakdown of the command:
kubectl run
: This command is used to create a new pod or deployment in Kubernetes.
mysql-client
: This is the name of the pod that will be created.
--image=mysql:8.0
: This specifies the Docker image to use for the container.
-it
: This starts an interactive terminal session inside the container.
--rm
: This flag specifies that the container should be removed after it exits.
--restart=Never
: This specifies that the pod should not be restarted if it stops running for any reason.
-- /bin/bash
: This starts a bash session inside the container.
Once the command is executed, you should see a bash prompt inside the container. From there, you can run MySQL commands to interact with your MySQL server.
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.