MySQL(二)任务

 

 

1. mysql的安装

主要的工作平台是CentOS,所以此次学习仅在CentOS7上进行。

之前用的多是mariadb,这个mysql分支与mysql有很高的相似度。此次学习也用mariadb

安装步骤:

#wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
#rpm -ivh mysql-community-release-el7-5.noarch.rpm
#yum update
#yum install mysql-server
#设置权限
#chown mysql:mysql -R /var/lib/mysql
#初始化
#mysqld --initialize

#mariadb的安装与初始化
yum install mariadb-server mariadb
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installtion

#检查配置
mysqladmin --version

 

mysql -uroot -p****

 

项目一:创建表

create database example;
CREATE TABLE email(ID INT NOT NULL PRIMARY KEY, Email VARCHAR(255) NOT NULL);
insert into email values('1', 'a@b.com');
insert into email values('2', 'a@b.com');
insert into email values('3', 'a@b.com');

 查找表中重复的内容

select email from email having count(*) > 1;

 

项目二:

create table world (
    -> name varchar(50) not NULL,
    -> continent varchar(50) not NULL,
    -> area int not NULL,
    -> population int not NULL,
    -> gdp int not NULL);
insert into world values('Afghanistan','Asia',652230,25500100,20343000);
insert into world values('Albania','Europe',28748,2831741,12960000);
insert into world values('Algeria','Africa',2381741,37100000,188681000);
insert into world values('Andorra','Europe',468,78115,3712000);
insert into world VALUES('Angola','Africa',1246700,20609294,100990000);

select name,population,area from world where area > 3000000 or population > 25000000 and gdp > 20000000;

 

posted on 2019-04-02 16:40  NetDevOps  阅读(142)  评论(0编辑  收藏  举报

导航