Login
mysql -h127.0.0.1 -uroot -p<>
Usage
No Database
show databases;
drop database $$DB Name$$;
create database $$DB Name$$;
use $$DB Name$$;
source $$FILENAME$$Run a pre-prepared script
User Management
show grants for $$USER NAME$$;
use mysql;
select user, host from user;List users
grant ALL on $$DB Name$$.$$TABLE NAME$$ TO $$USER NAME$$@127.0.0.1 IDENTIFIED BY '$$USER PASS$$';Create a new user
use . for all databases and tables, use $$DB Name$$.* to all tables in a database
Omit @127.0.0.1 for connecting from anywhere.
drop user $$User Name$$@$$Host$$;Delete a user.
To drop a user you must specify the host. Use select user, host from user; to find out what the host is. If it's % user '%' e.g. user@'%'
Database selected
show tables;
show fields from $$TABLE Name$$;
show create table $$TABLE Name$$;
Example DDL
-
CREATE TABLE `food_diary_entry` (
-
`PK_diary_entry` int(11) NOT NULL AUTO_INCREMENT,
-
`time_input` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
-
`time_eaten` TIMESTAMP,
-
`FK_meal` int (11) NOT NULL,
-
`FK_item` int(11) NOT NULL,
-
`FK_portion_unit` int(11) NOT NULL,
-
`Quantity` int(11) NOT NULL DEFAULT 1,
-
`UNI_CHECK` varchar(255) NOT NULL,
-
`DELETED` int(11) NOT NULL DEFAULT 0,
-
PRIMARY KEY (`PK_diary_entry`)
-
);