Difference between revisions of "MySQL Cheat Sheet"
Jump to navigation
Jump to search
Michael.mast (talk | contribs) |
Michael.mast (talk | contribs) |
||
Line 1: | Line 1: | ||
− | ==General | + | ==General use== |
<ref>http://alvinalexander.com/blog/post/mysql/show-users-i-ve-created-in-mysql-database</ref> | <ref>http://alvinalexander.com/blog/post/mysql/show-users-i-ve-created-in-mysql-database</ref> | ||
+ | ===Alter Table=== | ||
+ | ====Add columnn==== | ||
+ | alter table <tablename> add COLUMN hash VARCHAR(32) after <name of another column>; | ||
+ | |||
===View users=== | ===View users=== | ||
select host, user, password from mysql.user; | select host, user, password from mysql.user; | ||
Line 22: | Line 26: | ||
<ref>https://benperove.com/delete-mysql-rows-older-than-date/</ref> | <ref>https://benperove.com/delete-mysql-rows-older-than-date/</ref> | ||
<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>. | After creating the RDS instance, download the CA public key<ref>https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/AuroraMySQL.Security.html</ref>. |
Revision as of 11:21, 4 July 2018
Contents
General use
Alter Table
Add columnn
alter table <tablename> add COLUMN hash VARCHAR(32) after <name of another column>;
View users
select host, user, password from mysql.user;
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';
Show granted privileges
SHOW GRANTS FOR 'root'@'localhost';
Delete rows older than certain date
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
Then, as you create users makes sure to require the use of TLS[6]
grant all privileges on <database>.* to '<user name>'@'%' identified by '<password>' require ssl;
- ↑ http://alvinalexander.com/blog/post/mysql/show-users-i-ve-created-in-mysql-database
- ↑ http://stackoverflow.com/questions/4561292/how-to-clear-query-cache-in-mysql
- ↑ http://dev.mysql.com/doc/refman/5.7/en/show-grants.html
- ↑ https://benperove.com/delete-mysql-rows-older-than-date/
- ↑ https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/AuroraMySQL.Security.html
- ↑ https://dev.mysql.com/doc/refman/5.7/en/alter-user.html#alter-user-tls