接下来我将MySQL数据库的一些基本操作整理示下:
show databases; //查看有哪些数据库
show global variables like 'port'; //首先是查看mysql数据库的端口号
create database school; //创建数据库
use school; //进入数据库
create table info (id int not null primary key auto_increment,name char(10) not null,score decimal(5,2),hobby int(2)); //写入表结构
desc info; //查看表结构
show tables; //查看myschool中的表
select from info; //查看表中的数据
Insert into info (id,name,score) values (5,’tianqi’,55); //插入数据 列内容
Insert into info (id,name,score) values (5,’tianqi’,null); //插入数据 列内容
select form info where>
update info set score=75 where> delete from info where name=’test’; //删除信息(删除整行)
select from info where 1=1 order by score asc; //(给成绩score)排序(升序asc、降序desc)
select from info inner join hob where info.hobby=hob.id; //多表查询
select info.name,info.score,hob.hobname from info inner join hob where info.hobby=hob.id; //查询制定列
select i.name,i.score,h.hobname from info i inner join hob h where i.hobby=h.id; //别名查询
create table infos select i.name,i.score,h.hobname from info i inner join hob h where i.hobby=h.id; //把关联查找的结果生成一个新表
聚合函数:
统计count() 例如: select count(*) from infos;总共有多少学员 select count(1) from infos;
平均值avg() 例如:select avg(score) from infos; 成绩的平均值
//删除数据库 例如: drop database school;
//删除表 例如: drop table hobby;
在MySQL本地设置远程登录权限允许客户端登录:
grant all privileges on . to 'root'@'%'> 然后开一台Windows端进行登录:
mysql -h 192.168.100.70 -uroot -p //远程登录,在客户端进行登录 。 暂时写到这里,后续再继续补充!