远程访问Linux的mysql时出现Access denied for user 'root'@'localhost'的问题解决

本文介绍了解决MySQL无法从远程IP访问的问题,包括通过停止服务、跳过密码验证、无密码登录、授权及重启数据库等步骤实现。适用于遇到MySQL远程访问权限限制的技术人员。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载自:http://blog.youkuaiyun.com/hhj724/article/details/73277506

这是因为虽然用户名和密码正确,但是却没有在其他ip地址上访问的权限。需要登录mysql然后修改权限。

解决方法:

第一步:停服务

/etc/init.d/mysql stop

或者

service mysqld stop

第二步:跳过密码验证
执行命令行:
# /usr/bin/mysqld_safe --skip-grant-tables
报:
151104 09:07:56 mysqld_safe Logging to '/var/lib/mysql/iZ23dq2wm0jZ.err'.
151104 09:07:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

第三步:无密码登录
执行命令行:
mysql -u root 

第四步:授权

mysql>

grant all privileges on *.* to 'root'@'localhost' identified by 'root' with grant option;
关键词解释:
root'@'localhost:是用户
root:是密码

问题一:发现无密码条件下,没有授权的写权限

The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
解决方法:

mysql> set global read_only=0;//(关掉新主库的只读属性)
mysql>flush privileges;

再次执行第四步授权语句:grant all privileges on *.* to 'root'@'localhost' identified by 'root' with grant option;

mysql>set global read_only=1;//(读写属性)
mysql>flush privileges;

(注意刷新是必须项)

第五步:重启数据库
/etc/init.d/mysql restart

或者
service mysql restart


"Access denied for user 'root'@'localhost'"表示拒绝用户'root'@'localhost'的访问。 这个报错通常是因为输入了错误的密码或者root账户默认没有开放远程访问权限。解决这个问题的方法是重新设置密码和修改root用户的远程访问权限。 解决办法如下: 1. 打开/etc/mysql/debian.cnf文件,并修改其只读属性为chmod 777 debian.cnf。在该文件中,存储了系统管理员的密码。 2. 使用命令mysql -udebian-sys-maint -p登录控制台。 3. 登录控制台后,输入命令mysql -u root -p以再次尝试访问。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Access denied for user ‘root‘@‘localhost‘ (using password:YES) 解决方案](https://blog.youkuaiyun.com/qq_36205206/article/details/125773496)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [ubuntu18.04安装MySQL问题——access denied for user root @localhost的解决方法](https://download.youkuaiyun.com/download/weixin_38721119/13683476)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值