这里写目录标题
- 更改登录密码:
- 有权限账号能登录mysql中:
- 有权限账号不能登录mysql中:
- mysql5.6版本命令
- mysql5.7版本命令
- 修改密码8.0版本
- 改完后:
- mysql登录不上了
- 本机安装了5.6后,又安装了mysql8.0
更改登录密码:
有权限账号能登录mysql中:
修改当前用户密码
set password=password('redhat');
有权限账号不能登录mysql中:
先停mysql,修改配置文件my.cnf
systemctl stop mariadb #停止mysql
vim /etc/my.cnf #更改配置文件
在mysqld下新增一行 skip-grant-tables
[mysqld]
skip-grant-tables
重启mysql
systemctl start mariadb
mysql 空密码进入
mysql -uroot
进入mysql库,查看user表:
use mysql;
select Host,User,Password from mysql.user;
添加密码:
grant all on *.* to root@localhost identified by '123456' with grant option;
mysql5.6版本命令
update mysql.user set password=password('123456') where user='root';
flush privileges; #刷新
exit
mysql5.7版本命令
update user set authentication_string=password('123456') where user='root' and Host='localhost';
flush privileges; #刷新
exit
修改密码8.0版本
新搭建好的mysql,查看默认密码,如没有则单机登录到mysql
cat /var/log/mysqld.log | grep localhost
更改密码为空即‘mima’处无内容,即为免密(亦可设置你习惯的密码,就不是免密了)
alter user 'root'@'localhost' identified by 'mima';
flush privileges;
exit
改完后:
vim /etc/my.cnf
#skip-grant-tables #注释
重启mysql服务
systemctl restart mariadb
mysql登录不上了
大概率是装有其他mysql,默认是在/tmp/mysql.sock
报错信息如下:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
查找到mysqld.sock 对应位置添加软连接
ps -ef | grep mysql
rm /var/run/mysqld/mysqld.sock
ln -s /tmp/mysql.sock /var/run/mysqld/mysqld.sock
重启mysql
service mysqld restart
本机安装了5.6后,又安装了mysql8.0
ubuntu22 发现有多个mysql 导致未找到mysqld.sock
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
进行删除
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恢复
systemctl status mysql