MySQL改密

这里写目录标题

更改登录密码:

有权限账号能登录mysql中:

修改当前用户密码

python 复制代码
set password=password('redhat');    

有权限账号不能登录mysql中:

先停mysql,修改配置文件my.cnf

python 复制代码
systemctl stop mariadb  #停止mysql
vim /etc/my.cnf   #更改配置文件

在mysqld下新增一行 skip-grant-tables

python 复制代码
[mysqld]
skip-grant-tables

重启mysql

python 复制代码
systemctl start mariadb

mysql 空密码进入

python 复制代码
mysql -uroot

进入mysql库,查看user表:

python 复制代码
use mysql;
python 复制代码
select Host,User,Password from mysql.user; 

添加密码:

bash 复制代码
grant all on *.* to root@localhost identified by '123456' with grant option; 

mysql5.6版本命令

python 复制代码
update mysql.user set password=password('123456') where user='root';
flush privileges; #刷新
exit

mysql5.7版本命令

python 复制代码
update user set authentication_string=password('123456') where user='root' and Host='localhost';
flush privileges; #刷新
exit

修改密码8.0版本

新搭建好的mysql,查看默认密码,如没有则单机登录到mysql

python 复制代码
cat /var/log/mysqld.log | grep localhost  

更改密码为空即'mima'处无内容,即为免密(亦可设置你习惯的密码,就不是免密了)

python 复制代码
alter user 'root'@'localhost' identified by 'mima';
flush privileges;
exit

改完后:

python 复制代码
vim /etc/my.cnf
python 复制代码
#skip-grant-tables  #注释 

重启mysql服务

python 复制代码
systemctl restart mariadb 

mysql登录不上了

大概率是装有其他mysql,默认是在/tmp/mysql.sock

报错信息如下:

python 复制代码
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

查找到mysqld.sock 对应位置添加软连接

python 复制代码
ps -ef | grep mysql
python 复制代码
rm /var/run/mysqld/mysqld.sock
ln -s /tmp/mysql.sock /var/run/mysqld/mysqld.sock

重启mysql

python 复制代码
service mysqld restart 

本机安装了5.6后,又安装了mysql8.0

ubuntu22 发现有多个mysql 导致未找到mysqld.sock

python 复制代码
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

进行删除

python 复制代码
dpkg -l | grep mysql
#ii  mysql-client-core-8.0                  8.0.37-0ubuntu0.22.04.3                 amd64        MySQL database core client binaries
apt-get remove mysql-client-core-8.0

重启mysql恢复

python 复制代码
systemctl  status mysql
相关推荐
小马同学-11 小时前
MySQL主从复制和读写分离
数据库·mysql
海绵宝宝转agent11 小时前
MySql高频面试八股开源笔记总结
mysql·面试·开源
余槐i12 小时前
数据没回滚也不报错:@Transactional 自调用失效的 3 种复现与修复
spring boot·mysql·多线程·spring 事务
五彩小白16 小时前
自回归和上下文
android
写后端的胖头鱼17 小时前
【高频面试题】FullText 全文索引(MySQL)
数据库·mysql·索引·全文索引
事圆则缓18 小时前
Android 多渠道打包实战:Product Flavors、签名、AAB 与发包校验
android
code_whiter19 小时前
01-MySQL数据库基础
数据库·mysql
树下困觉眯21 小时前
View绘制流程学习--获取WindowManager的三种方式
android·系统架构·view design
vx_Biye_Design21 小时前
springboot宠物领养与救助平台64334-计算机课程设计、毕业设计
java·vue.js·spring boot·后端·mysql·课程设计·宠物
vilya1 天前
我怎么给手机 GUI Agent 做双通道感知:无障碍树为主,投屏像素兜底
android·人工智能