This article introduces the simple operation of MySQL under ubuntu through two micro projects, from installation to practice, without much to say, directly on the code:
**The first step: Install MySQL: **
1 ), download and install mysql:
sudo apt-get update
sudo apt-get install mysql-server
2 ), configuration properties: sudomysql_secure_installation
3 ), check whether the installation is successful: systemctl status mysql.service;
Step 2: Create a database: firstDB
1 ), enter mysql: sudo mysql –u root –p
2 ), create a database: create database firstDB;
3 ), check whether the creation is successful: show databases;
Step 3: Create a form: email
1 ), enter the database firstDB: use firstDB;
2 ), create a table: createtable email(id int not null primary key,Email varchar(255));
3 ), check whether the creation is successful: show tables;
Step 4: Insert data
1 ), view the properties of the form: desc email;
2 ), insert data:
INSERT INTO email VALUES('1','[email protected]');
INSERT INTO email VALUES('2','[email protected]');
INSERT INTO email VALUES('3','[email protected]');3) View all data in the table: select*from email; 4), query duplicate emails in the email table: select Email from email group by Email having count(Email)>1;
Step 5: Item 2 1), create a table World: CREATE TABLE World(name VARCHAR(50) NOT NULL,continent VARCHAR(50) NOTNULL,area INT NOT NULL,population INT NOT NULL,gdp INT NOT NULL);2) Insert data: 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);3) If the area of a country exceeds 3 million square kilometers, or(Population exceeds 25 million and GDP exceeds 20 million), Then this country is a big country. Write a SQL query to output the names, populations and areas of all major countries in the table: select name,population,area fromworldwhere(population >25000000 and gdp >20000000)or area >3000000;
Recommended Posts