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") ;
相关推荐
isNotNullX33 分钟前
数据迁移怎么做?有什么好用的数据库迁移工具推荐吗?
数据库·数字化·数据迁移·企业管理
云老大TG:@yunlaoda3601 小时前
华为云国际站代理商DAS的跨境合规适配的应用场景有哪些?
网络·数据库·华为云
3824278271 小时前
python3网络爬虫开发实战 第二版:绑定回调
开发语言·数据库·python
BIBI20491 小时前
Windows 上配置 Nacos Server 3.x.x 使用 MySQL 5.7
java·windows·spring boot·后端·mysql·nacos·配置
wniuniu_1 小时前
ceph的参数
java·数据库·ceph
一只专注api接口开发的技术猿1 小时前
智能决策数据源:利用 1688 商品详情 API 构建实时比价与供应链分析系统
大数据·前端·数据库
山峰哥2 小时前
SQL查询优化秘籍:从Explain分析到性能飞跃
开发语言·数据库·sql·oracle·性能优化·系统优化
刘一说2 小时前
MySQL 版本演进全景图:从 5.6 到 8.4 的技术变革与行业实践
数据库·mysql
风跟我说过她2 小时前
HBase完全分布式部署详细教程(含HA高可用版+普通非HA版)
大数据·数据库·分布式·centos·hbase
writeone2 小时前
数据库课后题重点摘要
数据库·oracle