mysql-常用命令

C1 Mysql常用命令合集

P1.设置方面命令

连接

mysql -u root -p

授权指定ip访问

GRANT ALL PRIVILEGES 
ON *.* 
to 'root' @'172.17.0.3' 
IDENTIFIED BY 'xxxxxxxx' WITH GRANT OPTION;

###立即生效
FLUSH PRIVILEGES;

P2.sql方面

add column

alter table t_company_junior
	add version int default 1 null comment '版本',
	add deleted int default 0 null comment '逻辑删除',
	add create_time datetime null comment '创建时间',
	add modify_time datetime null comment '修改时间';

First.Query when we need group and sort in group

Solve

sql

SELECT
	* 
FROM
	( SELECT vehicle_id, create_time FROM t_declare WHERE deleted = 0 AND check_status = 2 ORDER BY create_time DESC LIMIT 10000 ) td 
GROUP BY
	vehicle_id;
  • It's very important step in the above sql and that is limit in the sql fragment.If we exclude limit which will lead the result become what we don't want,what is the reason about this phenomenon.
    The reason is that sql execute has sequence which show in the below picture .

    That we call the limit in the children query can lead the sort execute before the group,we must notice that the restrict condition is chidlren query.
posted @ 2022-09-13 15:03  逆态度22  阅读(53)  评论(0)    收藏  举报