linux下进入mysql数据库出现1045及2003错误,解决方法

本文介绍了如何解决在RedHat 7.0上遇到的MySQL网络访问错误1045和2003。通过修改配置文件允许网络访问,并调整用户权限和密码,成功解决了远程连接问题。

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

楼主所用linux版本为redhat7.0,楼主在准备使用mysql数据库,出现了以下error,1045及2003
通过网络上的查询以及自己的实践,终于把问题解决了,方法如下

[root@test ~]# mysql -uwhite -p123 -h 172.25.254.10
ERROR 1045 (28000): Access denied for user ‘white’@’172.25.254.10’ (using password: YES)
[root@test ~]# mysql -uwhite -pwhite -h 172.25.254.10
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘172.25.254.10’ (111)

先解决error2003
error2003,一般是通过网络登陆用户时出现的错误,不能连接mysql服务,这是因为在mysql配置文件里边,设置了不允许网络用户访问,
只需要打开配置文件,对其进行修改即可,步骤如下
[root@test ~]# vim /etc/my.cnf
skip-networking=0
[root@test ~]# systemctl restart mariadb.service

具体代码块如下:
[root@test ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
skip-networking=0    ##skip-networking表示跳过网络用户登录 1为不允许网络用户访问 0为允许
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[root@test ~]# systemctl restart mariadb.service 
[root@test ~]# mysql -uwhite -p123 -h 172.25.254.10
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> quit
Bye

解决error1045
[root@test ~]# mysql -uwhite -p123 -h 172.25.254.10
ERROR 1045 (28000): Access denied for user ‘white’@’172.25.254.10’ (using password: YES)
网上的观点 1.因为用户名或者密码不正确
2.用户权限不够
楼主通过亲身实践,先将用户权限更改为all,然后去登陆,还是不行,于是就认为是用户名或者密码不正确,改了密码之后登陆,果然可以进去了,总结一下方法,希望可以对网友有用

1. 查看配置文件,允许网络用户登陆
  [root@test ~]# vim /etc/my.cnf
   skip-networking=0 
[root@test ~]# systemctl restart mariadb.service 
一定要记住,更改完配置文件之后一定得重启服务
2.更改密码
先更改root用户密码
[root@test ~]# systemctl stop mariadb  ##关闭mysql
[root@test ~]# mysqld_safe --skip-grant-tables &      ##开启mysql登陆接口并忽略授权表
[root@test ~]# mysql       ##直接不用密码可以登陆
MariaDB [(none)]> update mysql.user set Password=password('123') where User='root';  ##更改密码
MariaDB [(none)]> quit
[root@test ~]# ps aux | grep mysql    ##过滤mysql的所有进程
[root@test ~]# kill -9 9334      ##结束进程
[root@test ~]# kill -9 9489      ##结束进程
[root@test ~]# systemctl start mariadb   ##重启mariadb
[root@test ~]# mysql -uroot -p123    ##登陆
登陆进去之后更改网络用户密码
MariaDB [(none)]> update mysql.user set Password=password('123') where User='white';
3.更改普通用户权限
MariaDB [mysql]> grant all on *.* to white@'%';  ##用户授权
MariaDB [mysql]> show grants for white@'%';   ##查看用户权力

做完以上步骤就可以直接登陆网络用户了,如果以上步骤还没有解决问题的话,建议先删除用户,再重新建一个,

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值