mysql基础01

登录 and 修改密码

登录

复制代码
mysql  //默认用户root ,主机名为localhost,密码为空,端口为3306
mysql -uroot -p123 -hlocalhost -p3306 //如果'-p'后无密码,可以通过非明文实现登录

修改密码

复制代码
mysqladmin -uroot -p password 123 //在root密码为空的情况下可以设置密码,否则需要旧密码进行修改操作
mysqladmin -uroot -paaa password 123 //验证旧密码成功后即成功修改新密码

破解密码

  • 修改mysql配置文件,并重启mysqld服务,目的是允许mysql无密码登录

    vim /etc/my.cnf.d/mysql-server.cnf
    skip-grant-tables //手动添加此行 作用登陆时不验证密码

  • mysql 登录,修改user表root的密码为空

    update mysql.user set authentication_string="" where user="root";

  • 恢复mysql配置文件,通过mysqladmin 设置新密码

筛选条件

范围匹配

复制代码
select name from abc.user where user in (1,2,3) //匹配是1,2,3的

模糊匹配

复制代码
select name from abc.user where name like "___%"  //匹配至少三个字符
  • 模糊匹配常用的匹配符: % _
  • %表示匹配零个或者多个任意字符
  • _表示匹配一个任意字符

正则匹配

需要学习 正则表达

复制代码
select name from abc.user where name regexp "^[0-9]"  // 匹配开头是数字的 

逻辑比较

  • between 1 and 2 // 包括1到2
  • and 与逻辑
  • or 或逻辑
  • not 非伙计
  • 可以通过'('和')'实现优先级选择

    select name , uid from tarena.user where name="root" and uid = 1;

字符比较/空/非空

复制代码
 select id , name from  tarena.user where name is not null;  //筛选非空  此处的空指的是'NULL'

别名/去重/合并

别名 name1() as name

复制代码
 select concat(name,"-",uid) as 用户信息 from tarena.user where uid <= 5;

去重 distinct

复制代码
select distinct shell  from  tarena.user  where shell in ("/bin/bash","/sbin/nologin") ;
相关推荐
小陈工3 小时前
Python Web开发入门(十七):Vue.js与Python后端集成——让前后端真正“握手言和“
开发语言·前端·javascript·数据库·vue.js·人工智能·python
0xDevNull7 小时前
MySQL数据冷热分离详解
后端·mysql
科技小花8 小时前
数据治理平台架构演进观察:AI原生设计如何重构企业数据管理范式
数据库·重构·架构·数据治理·ai-native·ai原生
一江寒逸8 小时前
零基础从入门到精通MySQL(中篇):进阶篇——吃透多表查询、事务核心与高级特性,搞定复杂业务SQL
数据库·sql·mysql
D4c-lovetrain8 小时前
linux个人心得22 (mysql)
数据库·mysql
阿里小阿希8 小时前
CentOS7 PostgreSQL 9.2 升级到 15 完整教程
数据库·postgresql
荒川之神8 小时前
Oracle 数据仓库雪花模型设计(完整实战方案)
数据库·数据仓库·oracle
做个文艺程序员9 小时前
MySQL安全加固十大硬核操作
数据库·mysql·安全
不吃香菜学java9 小时前
Redis简单应用
数据库·spring boot·tomcat·maven
一个天蝎座 白勺 程序猿9 小时前
Apache IoTDB(15):IoTDB查询写回(INTO子句)深度解析——从语法到实战的ETL全链路指南
数据库·apache·etl·iotdb