RHEL7/Mysql SQL DB/Table example

8 篇文章 0 订阅

### create user 
MariaDB [(none)]> create user 'training'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

##########create new DB training 
MariaDB [(none)]>create database training DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

MariaDB [(none)]> grant all privileges on `training`.* to 'training'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
##########

#############Table create  

CREATE TABLE `student` (
  `id` int(11) DEFAULT NULL,
  `name` varchar(32) DEFAULT NULL,
  `sex` varchar(8) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  `major` varchar(32) DEFAULT NULL
) ;


INSERT INTO student(id,name,sex,age,major) VALUES(1,'ZhangSan','M',18,'Computer');
INSERT INTO student(id,name,sex,age,major) VALUES(2,'LiSi','F',21,'Manager');
INSERT INTO student(id,name,sex,age,major) VALUES(3,'wangwu','F',19,'electronic');

 


CREATE TABLE `course` (
  `id` int(11) DEFAULT NULL,
  `name` varchar(32) DEFAULT NULL,
  `score` int(11) DEFAULT NULL
) ;


INSERT INTO course(id,name,score) VALUES(1,'SQL', 4);
INSERT INTO course(id,name,score) VALUES(2,'Chinese',3);
INSERT INTO course(id,name,score) VALUES(3,'Math',2);


CREATE TABLE `sc` (
  `id` int(11) DEFAULT NULL,
  `Stu_id` int(11) DEFAULT NULL,
  `Course_id` int(11) DEFAULT NULL,
  `make` int(11) DEFAULT NULL
) ;

INSERT INTO sc(id,Stu_id,Course_id,make) VALUES(1,1,1,88);
INSERT INTO sc(id,Stu_id,Course_id,make) VALUES(2,2,1,90);
INSERT INTO sc(id,Stu_id,Course_id,make) VALUES(3,2,2,70);
INSERT INTO sc(id,Stu_id,Course_id,make) VALUES(4,3,3,79);


 
 
 ### Update
 select * from course WHERE id=3;
 UPDATE course SET score = 3 WHERE id=3;
 
 select * from course WHERE id=3;
 
 
 #### select 
 
 select * from student WHERE age>18;
 
 select * from student WHERE age>18 ORDER BY age DESC;
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值