I swap between databases all the time for various projects, and end up Googling on how to do the inital setup all the time, so the purpose of this document is to list a set of commands that anyone would end up using in getting started.
Login to the MySQL console as the root user, with your password for the root user.
mysql -u root -p
# you will be prompted for the password
A more verbose and easier to read version is this:
mysql --user <username> --host <hostname/ipaddr> --port <port> --password
# you will be prompted for the password
The commands below will require you to be in the MySQL client console.
CREATE USER 'newuser'@'host' IDENTIFIED BY 'password';
CREATE DATABASE dbname;
Don't this this on a production environment. This is really just helpful for development environment.
GRANT ALL PRIVILEGES ON dbname . * TO 'newuser'@'host';
DROP DATABASE [IF EXISTS] dbname;
DROP USER 'newuser'@'host';
SELECT table_schema AS "Database",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;
IMPORTANT: Be sure to change the database name here:
SELECT table_name AS "Table",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.TABLES
WHERE table_schema = "database_name"
ORDER BY (data_length + index_length) DESC;