Difference between revisions of "MySQL Cheat Sheet"

From Michael's Information Zone
Jump to navigation Jump to search
Line 23: Line 23:
 
<pre>DELETE FROM `table` WHERE `column` < DATE_SUB(NOW(), INTERVAL 3 MONTH);</pre>
 
<pre>DELETE FROM `table` WHERE `column` < DATE_SUB(NOW(), INTERVAL 3 MONTH);</pre>
 
==AWS RDS==
 
==AWS RDS==
 +
After creating the RDS instance, download the CA public key<ref>https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/AuroraMySQL.Security.html</ref>.
 +
<pre>
 +
wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem
 +
</pre>
 +
At this point you can log into the instance using TLS.
 +
<pre>
 +
mysql -u<root user> -p -h xxxxxxx.xxxxxxxxxx.us-east-2.rds.amazonaws.com --ssl-ca=rds-combined-ca-bundle.pem
 +
</pre>

Revision as of 12:43, 12 June 2018

General user

[1]

View users

select host, user, password from mysql.user;

[2]

Remove history

(this is kept in your home directory)

rm -rf ~/.mysql_history

Remove user

drop user <username>@<host>;

Remove database

drop database <databasename>;

Grant privileges

grant all on <database>.<table> to <user>@<host> identified by '<password>';
grant all on test.* to 'michael'@'172.17.0.34' identified by 'mypassword';

[3]

Show granted privileges

SHOW GRANTS FOR 'root'@'localhost';

Delete rows older than certain date

[4]

DELETE FROM `table` WHERE `column` < DATE_SUB(NOW(), INTERVAL 3 MONTH);

AWS RDS

After creating the RDS instance, download the CA public key[5].

wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem

At this point you can log into the instance using TLS.

mysql -u<root user> -p -h xxxxxxx.xxxxxxxxxx.us-east-2.rds.amazonaws.com --ssl-ca=rds-combined-ca-bundle.pem