这里写目录标题
更改登录密码:
有权限账号能登录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