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)

相关推荐
mygljx1 天前
MySQL 数据库连接池爆满问题排查与解决
android·数据库·mysql
xinhuanjieyi1 天前
ruoyimate导入sql\antflow\bpm_init_db.sql报错
android·数据库·sql
闲猫1 天前
基于RABC的权限控制设计
android
我科绝伦(Huanhuan Zhou)1 天前
【生产案例】MySQL InnoDB 数据损坏崩溃修复
数据库·mysql·adb
星霜笔记1 天前
GitMob — 手机端 GitHub 管理工具
android·kotlin·github·android jetpack
LiuYaoheng1 天前
问题记录:Android Studio Low memory
android·ide·android studio
独隅1 天前
Python 标准库 (Standard Library) 全面使用指南
android·开发语言·python
mldlds1 天前
MySQL四种备份表的方式
mysql·adb·oracle
always_TT1 天前
strlen、strcpy、strcat等常用字符串函数
android
qqty12171 天前
MySQL Workbench菜单汉化为中文
android·数据库·mysql