Java全栈学习笔记30

# MySQL

卸载

安装版

电脑管家/360/控制面板卸载mysql服务即可

删除ProgramData中的MySQL目录

解压版

win+r 输入 services.msc 打开服务管理。查看是否存在MySQL,如果存在则删除

注册表 win+R regedit 打开注册表

计算机\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services 查看是否存在MySQL目录

安装

安装版安装

双击安装包

安装比较傻瓜式,下一步,执行即可

如果服务不能成功开启,则需要进行下述操作

win+R services.msc

找打MySQL服务,右键编辑属性

启动服务,发现启动成功

配置MySQL

环境变量。因为需要使用命令行操作MySQL

解压版的安装

下载地址:https://downloads.mysql.com/archives/community/

解压的路径不要存在中文和空格

创建my.ini文件 mysql的核心配置文件

创建data文件夹

在bin目录中 cmd 执行 mysqld --initialize-insecure 初始化数据库,且会把root用户的初始化密码设置为空

mysqld install

net start MySQL 启动mysql服务

在dos中进入mysql

mysql -u用户名 -p密码

查看当前数据库系统的所有数据库

show databases;

使用数据库

use dbName;

查看当前库中有那些表

show tables

查看字符集

show variable like '%char%';

修改字符集

set 设置项名称=字符集; 这种修改不是永久修改

永久性修改需要修改my.ini文件

修改用户密码

alter user 'root'@"localhost" identified with mysql_native_password by "admin";

创建用户并授权

create user '用户名'@'ip地址 %任意' identified by '密码';

grant all on dbName.tableName to '用户名'@'地址';

flush privileges;

创建数据库

同一个数据库软件中,数据库的名字不能重复

create database if not exists dbName;

create database newsdb;

create database if not exists newsdb;

删除数据库

如果数据库不存在,同样也不可以删除

drop database if exists dbName;

drop database newsdb;

drop database if exists newsdb;

查看当前数据库

使用数据库

use newsdb;

use mysql;

select database();

select 10 / 3;

select 10 div 3;

select not (2 > 3 || 2 < 3);

select 2 = 2 && 1 < 2;

select 2 = 2;

不等于

select 2 != 3;

select 2 <> 3;

-- between and

select 9 between 9 and 11;

select 9 >= 9 && 9 <= 11;

in 分组

select 5 in(1,2,3);

is 一般和null联合使用

select null is not null;

like 搜索 _代表一位字符 % 代表多位

select 'name' like '__a%';

select concat('hello','world')

abs 绝对值

select abs(-100)

余数

select mod(10,3);

随机数

select rand();

sqrt 平方根

select sqrt(9);

向上取整

select ceil(10.1)

select floor(10.5)

select round(10.5)

select floor(rand() * 500)

判断数组是等于0 大于0 小于0

select sign(-10.2)

left 从左侧截取指定长度

select left("hello",3)

right 从右侧截取

select right("hello",3)

substring(字符串,开始位置,截取长度) 索引从1开始。

select substring("hello",2,3)

ltrim() 去除左侧空格

select ltrim(" hello")

select length(ltrim(" hello"))

select length(trim("hello "));

日期 current_date() / curdate()

select current_date

select curdate();

时间 current_time() / curtime()

select current_time();

select current_time;

select curtime();

日期时间

select current_timestamp()

select now();

select year("2025-09-05")

select month("2025-09-05");

select day("2025-09-05")

select year(now())

select adddate(now(),5)

select adddate(now(),interval 5 year)

select adddate(now(),interval 5 minute);

select date_add(now(),interval 5 year);

select addtime(now(),"00:30");

select datediff("2025-09-05","2025-09-05")

select greatest(12,2,3);

select least(13,3)

相关推荐
天空之城--2 小时前
Android Flutter行业动态与学习参考(2026年8月)
android·flutter
quantdash_cc2 小时前
基于 QuantDash 5 分钟 K 线的网格交易策略参数网格搜索寻优实战
android·开发语言·pandas·量化·quantdash
杉氧4 小时前
原生交互:如何在 Flutter 中嵌入 Android/iOS 原生组件并解决手势冲突
android·flutter·dart
Android打工仔4 小时前
Continuation 的链式关系 —— 一个 suspend 函数如何把结果交还给调用者?
android·kotlin
hunterandroid4 小时前
[Android 从零到一] Kotlin Channel 与复杂并发场景:从生产者-消费者到结构化并发治理
android
FlightYe5 小时前
linux系统编程(八):阻塞与非阻塞IO对比
android·linux·运维·服务器·github·vim
恋猫de小郭5 小时前
Flutter iOS Deep Link 为什么会突然失效:一系列难以言喻的问题
android·前端·flutter
qq_422828625 小时前
android 图形学之图层数据送显(八)
android
Kapaseker6 小时前
小白都看得懂的 Skill 教程 - 初识 Skill
android·kotlin·vibecoding
神奇小梵6 小时前
安全和开发的需要了解的知识————下载内容的安全,和下载内容如何运行
android·windows·安全·个人开发