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> 
相关推荐
aiks_yuan5 小时前
MySQL GROUP BY 很慢怎么优化:加了索引反而从 1 秒变 7 秒,Using temporary 该不该消(MySQL 8.2 实测 400 万行)
mysql
数据库小学妹6 小时前
MySQL大字段治理:行溢出机制、覆盖索引与拆表
数据库·mysql·性能优化
这个DBA有点耶8 小时前
MySQL 8.0不可见索引:删索引怕出事,不删又拖慢写入——中间态怎么用?
数据库·mysql·代码规范
噜哥带你玩转 AI 大模型10 小时前
面试加分项!CASE WHEN 两种写法、CTE 公共表表达式、四大类窗口函数,老哥一次讲透
mysql·窗口函数·cte·sql 进阶
bksczm11 小时前
InnoDB 内存结构总览:Change Buffer、AHI 与 Log Buffer
数据库·mysql
招风的黑耳11 小时前
SpringBoot+Vue+MySQL 民宿在线预定平台 完整可运行版(源码+文档)
vue.js·spring boot·mysql
.痞老板.13 小时前
mysql初阶--数据库设计
数据库·mysql·oracle
Decay__15 小时前
SQL Server 数据库全栈运维实战系列 — 合集索引(24 篇)
运维·数据库·sql·mysql·架构
Thanks_ks15 小时前
SQL 的 GROUP BY 与聚合函数:从会写 SELECT 到会做统计
数据库·sql·mysql·group by·数据统计·聚合函数·having
Decay__1 天前
12_MySQL InnoDB 内存与锁调优 —— Buffer Pool、redo log、隔离级别与锁等待
运维·数据库·sql·mysql·架构