mysql数据库DBA题型问题解答

本文详细介绍如何在MySQL中创建用户表,导入/etc/passwd文件数据,进行字段增删改查,包括条件筛选、更新、统计等操作。涵盖字段类型定义、默认值设定、数据完整性约束、SQL查询技巧等内容。

1 把/etc/passwd文件的内容存储到userdb库下的user表里,并做如下配置:
[root@host51 ~]# cp /etc/passwd /var/lib/mysql

mysql> create table user(name char(50),password char(10),uid int,gid int,comment char(150),homedir char(100),shell char(80));

mysql> load data infile “/var/lib/mysql-files/passwd” into table user fields terminated by “:” lines terminated by “\n”;

2 在用户名字段下方添加s_year字段 存放出生年份 默认值是1990
mysql> alter table user add s_year int default 1990 after name;

3 在用户名字段下方添加字段名sex 字段值只能是gril 或boy 默认值是 boy

mysql> alter table user add sex enum(“gril”,“boy”) default “boy” after name;

4 在sex字段下方添加 age字段 存放年龄 不允许输入负数。默认值 是 21
mysql> alter table user add age tinyint unsigned default 21 fater sex;

5 把uid字段值是10到50之间的用户的性别修改为 girl
mysql> update user set sex=“gril” where uid between 10 and 50;

6 统计性别是girl的用户有多少个。
mysql> select count(sex) from user where sex=“gril”;

7 查看性别是girl用户里 uid号 最大的用户名 叫什么。

mysql> select name from user where uid = (select max(uid) from user where sex=“gril”);

8 添加一条新记录只给name、uid 字段赋值 值为rtestd 1000

mysql> insert into user(name,uid) values(“rtestd”,1000);

9 添加一条新记录只给name、uid 字段赋值 值为rtest2d 2000

mysql> insert into user(name,uid) values(“rtest2d”,2000);

10 显示uid 是四位数的用户的用户名和uid值。

mysql> select name uid from user where uid="____";

11 显示名字是以字母r 开头 且是以字母d结尾的用户名和uid。

mysql> select name,uid from user where name regexp “^r.*d$”;

12 查看是否有 名字以字母a开头 并且是 以字母c结尾的用户。

mysql> select name from user where name regexp “^a.*c$”;
没有

13 把gid 在100到500间用户的家目录修改为/root

mysql> update user set homedir="/root" where gid between 100 and 500;

14 把用户是 root 、 bin 、 sync 用户的shell 修改为 /sbin/nologin

mysql> update user set shell="/sbin/nologin" where name=“root” or name=“bin” or name=“sync”;

15 查看 gid 小于10的用户 都使用那些shell

mysql> select shell,gid from user where gid < 10;

16 删除 名字以字母d开头的用户。

mysql> delete from user where name regexp “^d”;

17 查询 gid 最大的前5个用户 使用的 shell

mysql> select shell,name,gid from user where gid order by gid desc limit 5;

18 查看那些用户没有家目录

mysql> select * from user where homedir is null;

**19 把gid号最小的前5个用户信息保存到/mybak/min5.txt文件里。 **

[root@host51 ~]# mkdir -p /mybak/
[root@host51 ~]# chown mysql /mybak/
[root@host51 ~]# vim /etc/my.cnf
secure_file_priv="/mybak/"
[root@host51 ~]# systemctl restart mysqld

mysql> select * from user where gid is not null order by gid limit 5 into outfile “/mybak/min5.txt” lines terminated by “\n”;

**20 使用系统命令useradd 命令添加登录系统的用户 名为lucy **
[root@host51 ~]# useradd luc
[root@host51 ~]# tail -1 /etc/passwd
lucy❌1001:1001::/home/lucy:/bin/bash

21 把lucy用户的信息 添加到user表里
mysql> insert into user(name,password,uid,gid,comment,homedir,shell) values(“lucy”,“x”,“1001”,“1001”,"","/home/lucy","/bin/bash");

22 删除表中的 comment 字段

mysql> alter table user drop comment;

23 设置表中所有字段值不允许为空

mysql> delete from user where password is null;

mysql> alter table user modify name char(50) not null,modify sex enum(“gril”,“boy”) default “boy” not null,modify age tinyint unsigned default 21 not null,modify s_year int default 1990 not null,modify password char(10) not null,modify uid int not null,modify gid int not null, modify homedir char(100) not null,modify shell char(80) not null;

24 删除root 用户家目录字段的值

mysql> update user set homedir="" where name=“root”;

25 显示 gid 大于500的用户的用户名 家目录和使用的shell

mysql> select name,homedir,shell from user where gid > 500;

26 删除uid大于100的用户记录

mysql> delect from user where uid > 100;

27 显示uid号在10到30区间的用户有多少个。

mysql> select count(name) from user where uid between 10 and 30;

28 显示uid号是100以内的用户使用的shell。

mysql> select uid,shell from user where uid < 100;

29 显示uid号最小的前10个用户的信息。

mysql> select * from user order by uid limit 10;

30 显示表中第10条到第15条记录

mysql> select * from user limit 9;6;

31 显示uid号小于50且名字里有字母a 用户的详细信息

mysql> select * from user where uid < 50 and name regexp “a”;

32 只显示用户 root bin daemon 3个用户的详细信息。

mysql> select * from user where name=“root” or name="bin"or name=“daemon”;

33 显示除root用户之外所有用户的详细信息。

mysql> select * from user where name !=“root”;

34 统计user表name 字段有多少条记录

mysql> select count(name) from user;

35 显示名字里含字母c 用户的详细信息

mysql> select * from user where name regexp “c”;

36 在sex字段下方添加名为pay的字段,用来存储工资,默认值15000.00

mysql> alter table user add pay float(7,2) default 15000 after sex;

37 把所有女孩的工资修改为10000

mysql> update user set pay=“10000” where sex=“gril”;

38 把root用户的工资修改为30000

mysql> update user set pay=“30000” where name=“root”;

39 给adm用户涨500元工资

mysql> update user set pay=pay+500 where name=“adm” ;

40 查看所有用户的名字和工资

mysql> select name,pay from user;

41 查看工资字段的平均值

mysql> select avg(pay) from user;

42 显示工资字段值小于平均工资的用户名。

mysql> select name,pay from user where pay < (select avg(pay) from user );

43 查看女生里uid号最大用户名

mysql> select name from user where uid order by uid desc limit 1;

44 查看bin用户的uid gid 字段的值 及 这2个字段相加的和

mysql> select uid,gid ,uid+gid from user where name=“bin”;

源码链接: https://pan.quark.cn/s/a4b39357ea24 银行信贷业务作为银行业务的关键构成部分,涵盖了银行向客户提供的各类融资服务,例如贷款、担保以及信用证等。此类业务致力于协助企业与个人解决资金需求问题,进而推动经济活动的开展。银行通过信贷业务获取利息收入,同时需承担相应风险,以保障资金的稳定与流转。 **信贷定义** 信贷意味着银行运用自身资本及信誉为客户提供资金支持,而客户则需以支付利息、费用并偿还本金为前提条件。这种业务模式不仅包含直接贷款,还包括为客户的债务承担提供担保。依照会计准则,信贷业务可分为内业务与外业务,前者对银行的资产负债产生直接影响,后者则不直接关联。 **信贷业务划分标准** 1. **依据会计核算归属**:内信贷(如贷款、贴现)和外信贷(如承兑、保证)。 2. **根据期限划分**:短期(不超过1年)、中期(1至5年)与长期(超过5年)。 3. **按照担保方式分类**:信用信贷(无担保)和担保信贷(保证、抵押、质押)。 4. **按照币种区分**:本币信贷与外币信贷。 5. **按照性质和用途区分**:固定资产贷款、流动资金贷款、循环额度贷款、消费贷款等。 6. **按照贷款组织形式区分**:普通贷款、联合贷款和银团贷款。 7. **按照资金来源区分**:信贷资金贷款、委托贷款和境外筹资转贷款。 8. **按照授信对象区分**:公司类信贷与个人类信贷。 **信贷业务产品** 1. **流动资金贷款**:用于企业日常运营周转或临时性资金需求。 2. **固定资产贷款**:用于投资固定资产项目。 3. **房地产开发贷款**:用于土地开发及房屋建设所需资金。 4. **循环额度贷款**:满足企业...
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值