Redhat7 安装mariadb(原mysql)
安装:
# yum install mariadb mariadb-server
启动并开机启动:
# systemctl start mariadb
# systemctl enable mariadb
此时mysql的root密码为空
# mysql –u root
user mysql;
update user set password=password(‘123456’) where user=root;
flush privileges;
quit
开防火墙:
# firewall-cmd –permanent –add-service=mysql
# firewall-cmd --reload
# vi /etc/my.cnf (mysqld下)
Skip-networking= 1 (关闭远程通过ip进行连接,默认是允许的)
:wq
link 模糊查询
link ‘%a%’ 中间含字母a的
link ‘_a%’ 以a结尾的
link ‘%a_’ 以a开头的
语句示例(注意区分函数、字段、表名):
select * from worker where sal >= 2500;
select * from worker where sal != 2500;
select * from worker where deptno in(2,4);
select * from worker where sal between 1500 and 2500;
select avg(sal) from worker;
select max(sal) from worker;
select min(sal) from worker;
select * from worker order by deptno; (升序排列)
select * from worker order by deptno desc; (降序排列)
select deptno,max(sal) from worker group by deptno;
create table test as select * from worker;
内连接:
select student,sno,student.sname,coll.cname from student join coll onstudent.cno=coll.con;
左外连接:
select s.sno,s.sname,c.cnamefrom student as s left join coll as c on s.cno=c.cno;
右连接:
select s.sno,s.sname,c.cnamefrom coll as c right join student as s on s.cno=c.cno;