MySQL Cheatsheet


Only administering MySQL once in a while quickly leaves gaps in my memory as to all the commands for creating users, manipulating tables, etc.

Here's my cheatsheet (page) for things I use on a regular basis.




Install MySQL yum repo
# rpm -ihv mysq-community*

Install MySQL
# yum -y install mysql-server 

First run setup
mysql> mysql_secure_installation

Upgrade MySQL
# yum -y upgrade mysql

Upgrading databases after MySQL upgrade
# mysql_upgrade -u root -p
If you get errors
# mysql_upgrade -u root -p --force

Create user
mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';

Show users
mysql> SELECT User, Host, Password FROM mysql.user;

Delete user
mysql> DROP USER 'username'@'localhost';

Reload grant tables in memory
mysql> FLUSH PRIVILEGES;

Export
mysqldump -u confluenceuser -p 'northscale!23' confluence > conf.sql

Import
mysql> use db_name;
mysql> source file_name.sql;

Create a blank database
mysql> create database testdb;

Delete a table
mysql> DROP TABLE tablename;

Delete a database
mysql> DROP DATABASE dbname;

No comments:

Post a Comment