当前位置: 首页 > news >正文

DBA 数据库管理 部署Mysql 服务,基础查询

数据库:存储数据的仓库

数据库服务软件:

关系型数据库: 存在硬盘 ,制作表格的

数据库的参数

[root@mysql50 ~]# cat /etc/my.cnf.d/mysql-server.cnf      主配置文件
[mysqld]
datadir=/var/lib/mysql            存放数据库目录
socket=/var/lib/mysql/mysql.sock       套接字文件存放目录和名字,访问mysql 会启动通过socket建立链接
log-error=/var/log/mysql/mysqld.log          记录服务启动的错误信息
pid-file=/run/mysqld/mysqld.pid              进程号的存放

数据库的命令

select version ()   差版本号

select    user   ()   查看用户信息

show   database   查看数据库列表

select   database  ()  查看自己在那个库

use   sys   进去sys库 

show   tables    查看库表

命令格式  

mysql -hlocalhost -P3306 -uroot -p123456     mysql    -h  -P  -u  -p

数据库密码管理

设置密码   操作系统才有权限  mysqladmin  -hlocalhost  -uroot -p password "tarena"

修改密码   mysqladmin -hlocalhost -P3306 -uroot -ptarena password "新密码" 

破解密码  : 1.修改主配置 文件 不验证密码 skip-grant-tables

2.删除mysql不知道密码  查看存放密码列名 authentication_string

update mysql.user set authentication_string="" where user="root" and host="localhost";

mysql> select host , user , authentication_string from mysql.user where user="root";

3.重启服务   修改主配置 #skip-grant-tables

4.重新设置密码  也可以mysql> alter user root@"localhost" identified by "NSD2024...a";

select 查看的用法

select   字段列表   from   库名.表名

行号   用户名    密码    uid     gid    用户说名       家目录    解释器

id       name   password  uid   gid    comment      homedir       shell

select    字段列表   from   库名.表名  where  筛选条件

筛选条件  

in (值列表) //在…里

not in (值列表) //不在…里

between 数字1 and 数字2 //在…之

  1. mysql> select name , uid from tarena.user where uid in (1 , 3 , 5 , 7);
  2. mysql> select name , shell from tarena.user where shell not in ("/bin/bash","/sbin/nologin");
  3. mysql> select id , name , uid from tarena.user where id between 10 and 20 ;

模糊匹配

where 字段名 like "表达式";

通配符       _ 表示 1个字符        % 表示零个或多个字符

正则匹配

select 字段名列表 from 库名.表名 where字段名 regexp '正则表达式';

^ 匹配行首

$ 匹配行尾

[] 匹配范围内任意一个

* 前边的表达式出现零次或多次

| 或者

. 任意一个字符

  1. mysql> select name from tarena.user where name regexp "[0-9]";
  2. mysql> select name from tarena.user where name regexp "^r|t$";

逻辑比较

有两个或2个以上的筛选条件

逻辑与 and (&&) 多个判断条件必须同时成立

逻辑或 or (||) 多个判断条件其中某个条件成立即可

逻辑非 not (!) 取反

()  提供优先级   放在()里的优先被处理  

or 和and 判断同时出现 and 的优先级高于or

select name , uid from tarena.userwhere (name = "root" or name = "bin") and uid = 1 ;

别名/去重/合并

  1. mysql> select concat(name , "-" , uid) as 用户信息 from tarena.user where uid <= 5;
  2. mysql> select name as 用户名 , homedir 家目录 from tarena.user;
  3. mysql> select distinct shell from tarena.user where shell in ("/bin/bash","/sbin/nologin") 

空 is null 表头下没有数据

非空 is not null 表头下有数据

select name from user where shell is null;

  1. mysql> insert into tarena.user(id,name) values(71,""); //零个字符
  2. mysql> insert into tarena.user(id,name) values(72,"null");//普通字母
  3. mysql> insert into tarena.user(id,name) values(73,NULL); //表示空

安装图形软件

安装图形化软件,可以访问图形工具对数据库进行访问

在数据库服务器里创建普通用户

    • 创建库
    • mysql> create database gamedb;
    • 创建用户
    • mysql> create user plj@"localhost" identified by "123456";
    • 授权权限
    • mysql> grant all on gamedb.* to plj@"localhost" ;
http://www.lryc.cn/news/395513.html

相关文章:

  • AIGC:构筑创意新时代的神奇力量
  • 前端Din字体和造字工房力黑字体文件
  • Studying-代码随想录训练营day33| 动态规划理论基础、509.斐波那契函数、70.爬楼梯、746.使用最小花费爬楼梯
  • 【康复学习--LeetCode每日一题】724. 寻找数组的中心下标
  • LeetCode-刷题记录-前缀和合集(本篇blog会持续更新哦~)
  • 【中项第三版】系统集成项目管理工程师 | 第 4 章 信息系统架构③ | 4.6
  • 知识图谱入门笔记
  • 常见的气体流量计有哪些?
  • AI推介-大语言模型LLMs论文速览(arXiv方向):2024.07.01-2024.07.05
  • Android IP地址、子网掩码、默认网关、首选DNS服务器、备用DNS服务器校验
  • 铁威马NAS教程丨为什么修复文件系统、为卷扩容、增加及删除 SSD 缓存等操作失败?
  • 【深度学习】第3章——回归模型与求解分析
  • Maven的基本使用
  • 【笔记】finalshell中使用nano编辑器GNU
  • markdown文件转pdf
  • 课设:二手车交易管理系统(Java+MySQL)
  • vue3实现无缝滚动 列表滚动 vue3-seamlessscroll
  • Python酷库之旅-第三方库Pandas(012)
  • SpringCloud集成nacos之jasypt配置中心的密码加密的自动解密
  • Python 中将字典内容保存到 Excel 文件使用详解
  • libaom 编码器 aomenc 使用文档介绍
  • 速盾:cdn 缓存图片
  • 移动应用开发课设——原神小助手文档(2)
  • 智能聊天机器人:使用PyTorch构建多轮对话系统
  • 昇思25天学习打卡营第16天 | 文本解码原理-以MindNLP为例
  • Unity之Text组件换行\n没有实现+动态中英互换
  • vue3+ el-tree 展开和折叠,默认展开第一项
  • ProFormList --复杂数据联动ProFormDependency
  • Git、Github、tortoiseGit下载安装调试全套教程
  • 老师怎么快速发布成绩?