常用的基础命令
use mysql
update user set password = password('密码') where user = 'root'
create table table_name (key1 int primary key,)
desc table
show create table table_name
alter table table_name rename new_table_name;
alter table table_name change ke1 oldData newkey newData
alter table table_name modify key newData
alter table table_name add newKey newData after oldKey
alter table table_name drop key
alter table table_name modify key Data after oldKey
insert into table_name values (values1, values2...)
select * from table_name
update table_name set key=values where ...
delete from table_name where ...
drop database|table databaseName|table_name
truncate table_name / delete from table_name
select * from table_name where key in (values1, values2...)
select * from table_name where key not in (values1, values2...)
select * from table_name where key between 3 and 5;
select * from table_name where key not between values1 and values2;
select * from table_name where key is null;
select * from table_name where key is not null;
select distinct key from table_name
select key from table_name where key like '匹配字符串';
select * from table_name where name like '欧%';
select * from table_name where 表达式1 and|or 表达式2;
count(*|key)
sum(key)
avg(key)
max(key)
min(key)
select 聚合函数[, key1, key2 ...] from table_name
select key from table_name order by key asc|desc
select key from table_name group by key
select * from table_name limit 1, 3;
select key as key1 from table_name as tn;
select key from table_name where 条件表达式 group by key having 聚合函数 order by key desc|asc limit n, m;
from -> where -> group by -> select -> distinct -> order by -> limit
primary key
foreign key
not null
unique
default
alter tanle table_name drop primary key;
alter table table_name modify key data primary key
alter table table_name drop index key;
alter table table_name add constraint FK_NAME foreign key (key) references 外表名(外表名的主键字段)
select key from t1 join t2 on t1.key = t2.key;
select * from t1, t2 where t1.key = t2.key
select * from t1 left|right t2 where t1.key=t2.key
mysqldump -uroot -pXXXX
mysqldump -uroot -pxxxxx dbName > path
mysql -uroot -pxxxxx [dbname] < backup.sql(路径)
mysql -uroot -p test < test.sql
mysql -uroot -pxxxx < all.sql
grant all privileges on database.table to 'username@hostname' identified by password
create user ’username@hostname‘ identified by password
drop user 'username@hostname'
delete from mysql.user where host='hostname' and user='username'
show grants for 'username@hostname'
grant 权限列表 on dbname[.table_name] to 'username@hostname';
revoke 权限列表 on dbname[.table_name] from 'username@hostname'
grant all privileges on *.* 'root@%' identified by 'root_password'
flush privileges;
start transaction
set @@autocommit = 0
commit
rollback