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

MySql升级安装、socket 及密码重置

升级

项目需要使用Mysql8.0, 查看自己的ubuntu22.04上mysql版本为5.7, 使用以下命令自动升级到8.0版本。

sudo apt install Mysql

sock错误: Can’t connect to local MySQL server through socket

运行mysql -u -p 报以下错误:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysqld.sock'

解决如下: 修改配置文件,增加以下内容:

[mysqld]
socket = /tmp/mysqld.sock[client]
socket = /tmp/mysqld.sock

修改之后 ,重启mysql服务

sudo systemctl restart mysql

密码问题: ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’

忘记密码会提示以下错误,以下是重置mysql密码方法:

#执行以下命令,输入密码
mysql -u root -p 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)#停止服务 
(base) moon@moon:~$ sudo service mysql stop#跳过密码检查
(base) moon@moon:~$ sudo mysqld_safe --skip-grant-tables &
[1] 27049
(base) moon@moon:~$ 2025-06-19T09:30:30.942961Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2025-06-19T09:30:30.998082Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql#进入mysql,
(base) moon@moon:~$ mysql -u root
# 重新设置密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.06 sec)mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.06 sec)mysql> quit
Bye#重启服务 
(base) moon@moon:~$ sudo service mysql restart#重新进入
base) moon@moon:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.36-0ubuntu0.22.04.1 (Ubuntu)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 

相关文章:

  • 3.1 Hector_mapping初体验
  • langchain框架中各种Agent(LLMSingleAgent ReactAgent Plan-and-Execute Agent)原理方式对比
  • Spring Boot 虚拟线程 vs WebFlux:谁更胜一筹?
  • Ascend上如何进行带宽测试
  • Spring Boot + MyBatis + Vue:构建高效全栈应用的实战指南
  • px4仿真使用fastlio的定位数据飞行
  • 用流行民族戏腔三种方式打开国风爆款《闲人填梦》,邓超予的跨界演绎引领文化传播新高度!
  • QSqlDatabase: QSQLITE driver not loaded
  • 小孙学变频学习笔记(三)变频器的逆变器件—IGBT管(上)
  • 16.大数据监控
  • Kafka Broker处理消费者请求源码深度解析:从请求接收到数据返回
  • WHAT - React Native 开发 App 从 0 到上线全流程周期
  • React 新框架的一些实践心得(关注业务的话,框架的设计封装思路)
  • 【研发工具】.Net创建多项目模板(Visual Studio)
  • 设计模式 | 单例模式——饿汉模式 懒汉模式
  • 从零开始的云计算生活——第二十天,脚踏实地,SSH与Rsync服务
  • uni-app总结5-UTS插件开发
  • Axios 拦截器实现原理深度剖析:构建优雅的请求处理管道
  • Vue-11-前端框架Vue之应用基础父组件传值到子组件props的使用
  • TDengine 集群超能力:超越 InfluxDB 的水平扩展与开源优势
  • 公明网站建设公司/网络营销公司哪家可靠
  • 网站建设和源代码问题/百度手机应用市场
  • 网页设计毕业论文格式/seo优化推广流程
  • bc网站怎么做排名/网盘网页版
  • nb-iot网站开发/seo搜索引擎优化课后答案
  • 微信平台软件开发/郑州网站seo优化公司