執(zhí)行 mysql -h遠(yuǎn)程ip地址 -u數(shù)據(jù)庫賬號 -p密碼
例如:mysql -h192.168.0.1 -uroot -proot
show global variables like "%timeout%";? // 查看 全局時間戳
show databases;? 展示查詢所有的數(shù)據(jù)庫
information_schema? --mysql 元數(shù)據(jù) 基礎(chǔ)數(shù)據(jù)
performance_schema? ==mysql 數(shù)據(jù)庫運行的數(shù)據(jù) 日志
create databases 數(shù)據(jù)庫名稱 default character set utf8;設(shè)置編碼
drop databases 數(shù)據(jù)庫名稱;? 刪除數(shù)據(jù)庫
show create database day15; 查看默認(rèn)字符集
alter database day15 default character set gbk; 修改數(shù)據(jù)庫編碼 使用gbk
查看表的字符編碼
show create table xx表名
統(tǒng)一修改字段編碼:
alter table `tablename` convert to character set utf8;
修改表字符編碼:
alter table zgb? charset=utf8
use 數(shù)據(jù)庫名; 選擇數(shù)據(jù)庫
show tables ; 查詢所有的數(shù)據(jù)庫表
//創(chuàng)建數(shù)據(jù)庫表
? create table test(
? ? -> id int,
? ? -> name varchar(20),
? ? -> remark varchar(50)
? ? -> );
//查看一張表的結(jié)構(gòu)
? desc test;
// 數(shù)據(jù)庫表名稱
alter table 修改的數(shù)據(jù)庫表名 rename to (new數(shù)據(jù)庫名稱);
//刪除表
drop table test;
// 添加字段
alter table student add column gender varchar(2);
//刪除字段
alter table student drop column gender;
// 修改字段類型長度
alter table student modify column gender varchar(100);
// 修改字段名稱
alter table student change gender sgender varchar(2);
-- 如果重復(fù)保留id最大的
SELECT * FROM student where id in (SELECT max(id) id from student GROUP BY age);
-- 使用exists
SELECT id,username,gender,age FROM student a where EXISTS(
SELECT id FROM (SELECT MAX(id) as id FROM student GROUP BY age) b where a.id=b.id);
-- 兩列數(shù)值類型的可以進行合并
SELECT id,username,(source+shuxu) As '總和' FROM student;
-- > < 等價于between and
SELECT *FROM student where source>70 and source<=80;
SELECT *FROM student where source BETWEEN 70 and 80
-- 不等于 <>
SELECT * FROM student where gender<>'男';
-- 包括null和空字符串
SELECT * FROM student where address is null or address='';
-- 不包括null 且不等于''
SELECT * FROM student where address is not null and address<>'';