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") ;
相关推荐
m0_623955662 小时前
Oracle使用SQL一次性向表中插入多行数据
数据库·sql·oracle
阿蒙Amon2 小时前
C#读写文件:多种方式详解
开发语言·数据库·c#
东窗西篱梦3 小时前
Redis集群部署指南:高可用与分布式实践
数据库·redis·分布式
就是有点傻4 小时前
C#如何实现中英文快速切换
数据库·c#
1024小神4 小时前
hono框架绑定cloudflare的d1数据库操作步骤
数据库
KellenKellenHao6 小时前
MySQL数据库主从复制
数据库·mysql
@ chen6 小时前
Redis事务机制
数据库·redis
KaiwuDB6 小时前
使用Docker实现KWDB数据库的快速部署与配置
数据库·docker
一只fish7 小时前
MySQL 8.0 OCP 1Z0-908 题目解析(16)
数据库·mysql
泊浮目7 小时前
未来数据库硬件-网络篇
数据库·架构·云计算