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") ;
相关推荐
哆啦A梦15886 小时前
Springboot整合MyBatis实现数据库操作
数据库·spring boot·mybatis
Zzzzmo_7 小时前
【MySQL】JDBC(含settings.xml文件配置/配置国内镜像以及pom.xml文件修改)
数据库·mysql
FirstFrost --sy8 小时前
MySQL内置函数
数据库·mysql
2401_879693878 小时前
将Python Web应用部署到服务器(Docker + Nginx)
jvm·数据库·python
reembarkation8 小时前
光标在a-select,鼠标已经移出,下拉框跟随页面滚动
java·数据库·sql
eggwyw8 小时前
MySQL-练习-数据汇总-CASE WHEN
数据库·mysql
星轨zb8 小时前
通过实际demo掌握SpringSecurity+MP中的基本框架搭建
数据库·spring boot·spring security·mp
treacle田9 小时前
达梦数据库-配置本地守护进程dmwatcher服务-记录总结
数据库·达梦数据库·达梦数据库local数据守护
wyt5314299 小时前
Redis的安装教程(Windows+Linux)【超详细】
linux·数据库·redis
CeshirenTester9 小时前
从数据库到结构化用例:一套可落地的测试智能体架构
数据库·架构