free-tech

Mysql command lines


command line to connect:


mysql -h HOST -u USERNAME -p

command line to create database:


CREATE DATABASE databasename;

command line to drop database:


DROP DATABASE databasename;

command line to create a table:


CREATE TABLE table_name (    column1 datatype,    column2 datatype,    column3 datatype,   ....);

command line to drop a table:


DROP TABLE table_name;

command line to alter a table:


ALTER TABLE table_nameADD column_name datatype;

command line to create index:


CREATE INDEX index_nameON table_name (column1, column2, ...);

command line to create a unique index:


CREATE UNIQUE INDEX index_nameON table_name (column1, column2, ...);

command line to create a view:


CREATE VIEW view_name ASSELECT column1, column2, ...FROM table_nameWHERE condition;

command line insert into table:


INSERT INTO table_name (column1, column2, column3, ...)VALUES (value1, value2, value3, ...);

command line to update table:


UPDATE table_nameSET column1 = value1, column2 = value2, ...WHERE condition;

command line to delete from table:


DELETE FROM table_name WHERE condition;