远程链接数据库:
mysql –u用户名 [–h主机名或者IP地址] –p密码 (用户名是登录的用 户,主机名或者IP地址为可选项,如果是本地连接则不需要,远程连接需要填写,密码是对应用户的密码。)
C:Userszj>E:PHPwamp64inmysqlmysql5.7.11inmysql -ucocheer -hrm-wz9ib9r9nv19pn0y2o.mysql.rds.aliyuncs.com -p******
注意:以下所有的命令注意加分号结尾!
显示数据库列表:
show databases;
选择数据库:
use <database name>;
显示所有数据表:
show tables;
显示表结构:
show columns from <table name>;
模糊查找:
SELECT <columns> FROM <table> WHERE <columns name> Like '%<value>%';
select * from device_info where chip_id like '%57a74%';
退出数据库:
exit
附:一些常用的mysql命令
更新 使表中两字段相等
update <table name> A
set A.<column name 1>=A.<column name 2>;
update device_info A set A.active_time=A.updatetime;
分组统计数目
SELECT <column name> AS NAME_A, COUNT(*) AS counts
FROM <table name>
WHERE <condition>
GROUP BY NAME_A
ORDER BY NAME_A
SELECT DATE_FORMAT(active_time, '%Y-%m-%d') AS date, COUNT(*) AS counts FROM device_info WHERE mac IS NOT NULL AND mac != NULL AND active_time > '1970-01-02 14:51:51' AND active_time < '2017-11-28 08:00:00' GROUP BY date ORDER BY date
获取的结果: