mysql -h host -P port -u username -p password
mysql -u username -p password -h host -P port
show databases;
select database();
create database databaseName;
drop database databaseName;
use databaseName;
show tables;
desc tableName;
set names utf8;
select * from tableName;
select * from tableName where columnName > value;
select * from tableName where columnName is null;
select * from tableName where columnName between value1 and value2;
select * from tableName where columnName not between value1 and value2;
select * from tableName where columnName in (value1, value2, ...);
select * from tableName where columnName like '%value%';
select * from tableName where columnName1 = value1 and columnName2 = value2;
select * from tableName where columnName1 = value1 or columnName2 = value2;
select * from tableName order by columnName desc;
select count(*) from tableName;
select max(columnName) from tableName;
select min(columnName) from tableName;
select sum(columnName) from tableName;
select avg(columnName) from tableName;
select columnName as aliasName from tableName;
select * from lesson where id in (select lesson_id from lesson_student where student_id = 1);
select * from lesson, lesson_student where lesson.id = lesson_student.lesson_id and lesson_student.student_id = 1;
select * from lesson left join lesson_student on lesson.id = lesson_student.lesson_id where lesson_student.student_id = 1;
select * from lesson inner join lesson_student on lesson.id = lesson_student.lesson_id where lesson_student.student_id = 1;
select * from tableName1, tableName2 where tableName1.columnName = tableName2.columnName;
select * from tableName1 inner join tableName2 on tableName1.columnName = tableName2.columnName;
select * from tableName1 left join tableName2 on tableName1.columnName = tableName2.columnName;
select * from tableName1 right join tableName2 on tableName1.columnName = tableName2.columnName;
create index indexName on tableName(columnName);
create index index_name on class(name);
show index from tableName;
show index from class;
show index from class\G;
drop index indexName on tableName;
drop index index_name on class;
create unique index indexName on tableName(columnName);
create unique index index_name on class(name);
alter table tableName add index indexName(columnName);
alert table class add unique index index_name(name);
alter table tableName drop index indexName;
alter table tableName add primary key(columnName);
alter table tableName add fulltext(columnName);
begin;
update user1 set money = money - 100 where id = 1;
update user2 set money = money + 100 where id = 2;
commit;
rollback;
lock table tableName read;
unlock tables;
lock table tableName write;
unlock tables;
insert into tableName(columnName1, columnName2, ...) values(value1, value2, ...);
update tableName set columnName = value where columnName = value;
delete from tableName where columnName = value;
drop table tableName;
create table tableName(
columnName1 dataType1,
columnName2 dataType2,
...
);
select * from tableName order by columnName desc;
select count(*) from tableName;
select * from tableName limit 10;
select * from tableName limit 10, 10;
drop table tableName;
select version();
show status;
show processlist;