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") ;
相关推荐
Raymond运维18 小时前
MariaDB源码编译安装(二)
运维·数据库·mariadb
沢田纲吉19 小时前
🗄️ MySQL 表操作全面指南
数据库·后端·mysql
RestCloud1 天前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
RestCloud1 天前
为什么说零代码 ETL 是未来趋势?
数据库·api
ClouGence2 天前
CloudCanal + Paimon + SelectDB 从 0 到 1 构建实时湖仓
数据库
Java水解2 天前
Mysql查看执行计划、explain关键字详解(超详细)
后端·mysql
知其然亦知其所以然2 天前
MySQL 社招必考题:如何优化查询过程中的数据访问?
后端·mysql·面试
DemonAvenger2 天前
NoSQL与MySQL混合架构设计:从入门到实战的最佳实践
数据库·mysql·性能优化
程序新视界2 天前
如何在MySQL中创建聚集索引?
mysql
AAA修煤气灶刘哥2 天前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql