楼主所用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@'%'; ##查看用户权力
做完以上步骤就可以直接登陆网络用户了,如果以上步骤还没有解决问题的话,建议先删除用户,再重新建一个,