開發者必備Mysql經常使用命令,涵蓋了數據定義語句、數據操縱語句及數據控制語句,基於Mysql5.7。mysql
mysql -uroot -proot
複製代碼
create database test
複製代碼
show databases
複製代碼
use test
複製代碼
show tables
複製代碼
drop database test
複製代碼
create table emp(ename varchar(10),hiredate date,sal decimal(10,2),deptno int(2))
複製代碼
create table dept(deptno int(2),deptname varchar(10))
複製代碼
desc emp
複製代碼
show create table emp \G
複製代碼
drop table emp
複製代碼
alter table emp modify ename varchar(20)
複製代碼
alter table emp add column age int(3)
複製代碼
alter table emp drop column age
複製代碼
alter table emp change age age1 int(4)
複製代碼
alter table emp rename emp1
複製代碼
insert into emp (ename,hiredate,sal,deptno) values ('zhangsan','2018-01-01','2000',1)
複製代碼
insert into emp values ('lisi','2018-01-01','2000',1)
複製代碼
insert into dept values(1,'dept1'),(2,'dept2')
複製代碼
update emp set sal='4000',deptno=2 where ename='zhangsan'
複製代碼
delete from emp where ename='zhangsan'
複製代碼
select * from emp
複製代碼
select distinct deptno from emp
複製代碼
select * from emp where deptno=1 and sal<3000
複製代碼
select * from emp order by deptno desc limit 2
複製代碼
select * from emp order by deptno desc limit 0,10
複製代碼
select deptno,count(1) from emp group by deptno having count(1) > 1
複製代碼
select * from emp e left join dept d on e.deptno=d.deptno
複製代碼
select * from emp where deptno in (select deptno from dept)
複製代碼
select deptno from emp union select deptno from dept
複製代碼
grant select,insert on test.* to 'test'@'localhost' identified by '123'
複製代碼
show grants for 'test'@'localhost'
複製代碼
revoke insert on test.* from 'test'@'localhost'
複製代碼
grant all privileges on *.* to 'test'@'localhost'
複製代碼
grant all privileges on *.* to 'test'@'localhost' with grant option
複製代碼
grant super,process,file on *.* to 'test'@'localhost'
複製代碼
grant usage on *.* to 'test'@'localhost'
複製代碼
drop user 'test'@'localhost'
複製代碼
set password = password('123')
複製代碼
set password for 'test'@'localhost' = password('123')
複製代碼
show variables like 'character%'
複製代碼
create database test2 character set utf8
複製代碼
show variables like "%time_zone%"
複製代碼
set global time_zone = '+8:00';
複製代碼
set time_zone = '+8:00'
複製代碼
flush privileges
複製代碼
mall項目全套學習教程連載中,關注公衆號第一時間獲取。git