Commands to create a MySQL database
I haven't managed to memorize all the intricacies of MySQL data creation and grant commands, so here are the commands I occasionally need:
drop database if exists mydb;
create database mydb;
use mydb;
grant all on mydb.* to 'myuser'@'localhost' identified by 'mypasswd';
Here's the ultra lazy, one line search and replace, insecure, global access version:
drop database if exists foo;
create database foo;
use foo;
grant all on * to 'foo'@'localhost' identified by 'foo';
Note: I usually put my SQL in a file and run the file from the MySQL monitor. Unfortunately, sometimes the grant commands don't work when they're run from a file. As a result, I have to manually type the commands into at the prompt. I don't know why.
Labels: mysql