查看服务是否启动:
ps -ef | grep -i mysql
停止服务:
service mysqld stop
修改配置文件:
vi /etc/my.cnf
# 添加如下配置
#跳过密码
skip-grant-tables
重启服务:
service mysqld start
# 进入到mysql数据库
mysql -uroot
修改密码:
use mysql;
update mysql.user set authentication_string=password('c123456') where user='root';
报了如下错误:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('c123456') where user='root'' at line 1
解决问题:
# 刷新资源
flush privileges;
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
退出服务:
exit
重新进入config配置:
vi /etc/my.cnf
# 删除第二部的配置
#跳过密码
#skip-grant-tables
笨办法就是利用宝塔面板修改:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-65oanWnM-1686211942021)(D:\CHEN\Typora\image\mysql修改密码.png)]
开启本地访问:
测试连接出现以下错误
Host '117.158.127.39' is not allowed to connect to this MySQL server
开启本地访问:
# 进入mysql服务
mysql -u root -p
# 进入修改资源
use mysql;
# 修改资源
update user set host='%' where user='root';
# 查看修改
select host,user from user;
# 刷新资源
flush privileges;
# 退出服务
exit
# 测试连接
oot’;
查看修改
select host,user from user;
刷新资源
flush privileges;
退出服务
exit
测试连接