mysql 用户无法连接数据库_my20_mysql的本地用户无法连接到数据库

mysql的本地用户无法连接到数据库

$ mysql -uadmin -prootroot -hlocalhost -P3309

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysql/mysql.sock' (2)

查看帮助

mysql --help

Default options are read from the following files in the given order:

/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

The following groups are read: mysql client

The following options may be given as the first argument:

--print-defaults Print the program argument list and exit.

--no-defaults Don't read default options from any option file,

except for login file.

--defaults-file=# Only read default options from the given file #.

--defaults-extra-file=# Read this file after the global files are read.

--defaults-group-suffix=#

Also read groups with concat(group, suffix)

--login-path=# Read this path from the login file.

/etc/my.cnf 里面果然有下面一行,mysql默认读了/etc/my.cnf,可该实例的配置文件并不是/etc/my.cnf,所以就出错了

socket = /data/mysql/mysql.sock

配置文件寻找顺序

1. 命令行中的 --defaults-file=

2. 依次 /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

虽然找到了原因,但由于该服务器是多实例,/etc/my.cnf有实例在用,尝试以下参数使用情况

加--no-defaults参数变成了读/tmp/mysql.sock

# mysql --no-defaults -uadmin -prootroot -hlocalhost -P3306

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

添加--defaults-file参数可以登录

# mysql --defaults-file=/etc/my_vodb.cnf -uadmin -prootroot -hlocalhost -P3306

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

admin@localhost Fri Oct 12 16:36:45 2018 16:36:45 [(none)]>

使用127.0.0.1却可以直接登录

# mysql -uadmin -prootroot -h127.0.0.1 -P3306

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

mysql>

另外以下方式也是可以登录的

mysql --no-defaults -uadmin -pu5EvNtomhXdvr23 -h127.0.0.1 -P3309

mysql --defaults-file=/etc/my_tanpf.cnf -uadmin -pu5EvNtomhXdvr23 -h127.0.0.1 -P3309

除了以上原因外,还有一种情况就是密码错了,就算你非常确定密码没有错,不防更新一下密码,再连接一下试试

alter user `admin`@`127.0.0.1` identified by '原来的密码';

当然加-S参数也是可以的,这里就是找一找为什么有时会连接不上的原因

mysql -uadmin -prootroot -S /data/mysql/log/test/mysql_test.sock

如果出现了127.0.0.1可以登录,但localhost却不可以登录的情况,确保存在localhost用户的情况下,应该是网络解析或mysql内部的问题,所以,创建本地用户,优先使用127.0.0.1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值