当前位置: 首页 > news >正文

【MySQL】Ubuntu22.04中MySQL-V8安装和修改root密码

1、安装

sudo apt install mysql-server

2、安全配置

$ sudo mysql_secure_installation Securing the MySQL server deployment.Enter password for user root: VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?Press y|Y for Yes, any other key for No: y	// 配置验证密码强度的插件There are three levels of password validation policy:	//密码验证策略有三个级别:// 长度大于8
LOW    Length >= 8	
// 长度大于8,密码由数字、大小写字母和特殊字符组成
MEDIUM Length >= 8, numeric, mixed case, and special characters	
// 长度大于8,密码由数字、大小写字母和特殊字符组成,并且任意连续4个及以上的字母不能是字典中的单词
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Using existing password for root.Estimated strength of the password: 50 
Change the password for root ? (Press y|Y for Yes, any other key for No) : n 
// 是否更改root密码,我在安装MySQL时,root密码够复杂,这里不再更改... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : y	//删除匿名用户
Success.Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y	// 不允许root用户通过网络连接数据库
Success.By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y // 删除test数据库,一般在正式部署之前删除它- Dropping test database...
Success.- Removing privileges on test database...
Success.Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y // 上述更改立即生效
Success.All done! 

3、设置密码

在安装MySQL过程中没有提示设置密码,需要手动设置root用户密码

1)查看默认用户和密码
sudo cat /etc/mysql/debian.cnf

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = ndkjiJKl897Dvi
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = ndkjiJKl897Dvi
socket   = /var/run/mysqld/mysqld.sock

2)使用默认用户和密码登录

mysql -u debian-sys-maint -p

输入上面 password 对应的值

3)切换至mysql表

use mysql

4)查看策略

SHOW VARIABLES LIKE 'validate_password%';
+-------------------------------------------------+--------+
| Variable_name                                   | Value  |
+-------------------------------------------------+--------+
| validate_password.changed_characters_percentage | 0      |
| validate_password.check_user_name               | ON     |
| validate_password.dictionary_file               |        |
| validate_password.length                        | 8      |
| validate_password.mixed_case_count              | 1      |
| validate_password.number_count                  | 1      |
| validate_password.policy                        | MEDIUM |
| validate_password.special_char_count            | 1      |
+-------------------------------------------------+--------+

5)修改策略

set global validate_password.policy=LOW;

6)重置root密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'helloworld';

7)生效

FLUSH PRIVILEGES;

8)注意
低版本MySQL重置密码的SQL语句为:

UPDATE user SET authentication_string=PASSWORD('your_new_password') WHERE user='your_user';

使用 MySQL 8.0 或更高版本,应该使用以下语句:

ALTER USER 'your_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password';

9)验证

mysql -u root -p

输入刚设置的密码,应该生效了

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 基于sklearn的机器学习 — KNN
  • Redis单机安装
  • OAExploit一款基于OA产品的一键扫描工具
  • 【iOS】UIViewController的生命周期
  • 视频监控管理平台LntonAIServer视频智能分析噪声检测应用场景
  • 搭建 WordPress 及常见问题与解决办法
  • 【Hadoop|HDFS篇】HDFS的读写流程
  • 【Google Chrome Windows 64 version及 WebDriver 版本】
  • 【Kubernetes】K8s 的鉴权管理(二):基于属性 / 节点 / Webhook 的访问控制
  • 《深度学习》PyTorch 手写数字识别 案例解析及实现 <上>
  • 浙大数据结构:02-线性结构3 Reversing Linked List
  • RFM模型
  • 数字证书学习
  • Docker 部署 Seata (图文并茂超详细)
  • Python数据处理利器,pivot与melt让表格变得灵活
  • Google 是如何开发 Web 框架的
  • 2017 前端面试准备 - 收藏集 - 掘金
  • create-react-app项目添加less配置
  • ECS应用管理最佳实践
  • HTTP--网络协议分层,http历史(二)
  • PHP的类修饰符与访问修饰符
  • socket.io+express实现聊天室的思考(三)
  • Spring Cloud中负载均衡器概览
  • TypeScript实现数据结构(一)栈,队列,链表
  • Yii源码解读-服务定位器(Service Locator)
  • 大型网站性能监测、分析与优化常见问题QA
  • 浅谈JavaScript的面向对象和它的封装、继承、多态
  • 三分钟教你同步 Visual Studio Code 设置
  • 小程序上传图片到七牛云(支持多张上传,预览,删除)
  • 一文看透浏览器架构
  • ionic入门之数据绑定显示-1
  • ‌分布式计算技术与复杂算法优化:‌现代数据处理的基石
  • #NOIP 2014# day.2 T2 寻找道路
  • (2024)docker-compose实战 (9)部署多项目环境(LAMP+react+vue+redis+mysql+nginx)
  • (23)Linux的软硬连接
  • (SERIES12)DM性能优化
  • (二刷)代码随想录第16天|104.二叉树的最大深度 559.n叉树的最大深度● 111.二叉树的最小深度● 222.完全二叉树的节点个数
  • (分布式缓存)Redis持久化
  • (分类)KNN算法- 参数调优
  • (附源码)springboot家庭装修管理系统 毕业设计 613205
  • (实测可用)(3)Git的使用——RT Thread Stdio添加的软件包,github与gitee冲突造成无法上传文件到gitee
  • (实战篇)如何缓存数据
  • (限时免费)震惊!流落人间的haproxy宝典被找到了!一切玄妙尽在此处!
  • (一)认识微服务
  • (转)shell中括号的特殊用法 linux if多条件判断
  • (转)平衡树
  • (转)四层和七层负载均衡的区别
  • .Net Core/.Net6/.Net8 ,启动配置/Program.cs 配置
  • .NET Entity FrameWork 总结 ,在项目中用处个人感觉不大。适合初级用用,不涉及到与数据库通信。
  • .NET Framework 服务实现监控可观测性最佳实践
  • .Net IOC框架入门之一 Unity
  • .NET 除了用 Task 之外,如何自己写一个可以 await 的对象?
  • .net 逐行读取大文本文件_如何使用 Java 灵活读取 Excel 内容 ?
  • .NET框架设计—常被忽视的C#设计技巧
  • .NET是什么