Skip to content

Instantly share code, notes, and snippets.

@dtuite
Last active December 16, 2015 16:49
Show Gist options
  • Save dtuite/5466204 to your computer and use it in GitHub Desktop.
Save dtuite/5466204 to your computer and use it in GitHub Desktop.
Basic Local mysql

Starting/Stopping server

It doesn't start automatically at login

mysql.server start
mysql.server stop

Login as root user

mysql -uroot -p

Just hit enter on the password screen if there is no password set (default).

Basic commands

create a user: create user '[username]'@'localhost';
delete a user: drop user '[username]'@'localhost';

create a database: create database [db_name];
drop a database: drop database [db_name];

drop a column: ALTER TABLE [db_name].[table_name] DROP [column_name]

grant all privilages to a user for a specific database: GRANT ALL ON [db_name].* TO '[username]'@'localhost';

Run long (or lots of) commands

You can run them from a file like so:

mysql -uroot -p
source [file_name]

or, you could use a HEREDOC:

mysql -uroot -p <<'END'
[one line of stuff]
[another line of stuff]
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment