Mysql | 新增用户无法连接服务器

Mysql | 新增用户无法连接服务器

新增用户

navicat上简单操作下,当然,通过mysql命令也可以添加用户,操作mysql.user表即可。

主机可以设置用户的IP,限制登录的IP,也可以输入%,表示任何IP均可登录

远程连接报错

1.Can’t connect to MySQL server on

解决:
查看服务器端口号是否是3306
  • 进入mysql 查询端口号
mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.01 sec)
  • 或者终端直接查看:netstat -an | grep 3306
(base) randy@jeff:$ netstat -an | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:33060           0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:41954         127.0.0.1:33063         TIME_WAIT  
unix  3      [ ]         STREAM     CONNECTED     663306

如果显示如下,说明MySQL端口目前只监听本地连接127.0.0.1。然后需要修改MySQL的配置文件。

tcp	 0	0	127.0.0.1:3306	0.0.0.0:*	LISTEN

说明本地没有开通其他电脑访问的权限

服务器开通其他电脑访问权限
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

将bind-address 和 mysqlx-bind-address 改为 0.0.0.0,原始的 127.0.0.1表示mysql只监听本地请求

bind-address            = 0.0.0.0
mysqlx-bind-address     = 0.0.0.0

重启mysql服务:service mysql restart

2.Access denied for user

   carolliu@carolliu-HP-ZBook-Studio-15-6-inch-G8-Mobile-Workstation-PC:~$ mysql -h 10.xx.xxx.xx -uliusx -p
   mysql: [Warning] Using a password on the command line interface can be insecure.
   ERROR 1045 (28000): Access denied for user 'liusx'@'10.xx.xx.xxx' (using password: YES)

注意:这里using password :YES表示是否输入了密码,YES表示输入了密码,NO表示没有输入密码,不表示密码输入是否正确。

查阅资料发现:mysql8.0以上密码策略限制必须要大小写加数字特殊符号,于是修改密码为大小写加数字。

远程成功登录

carolliu@carolliu-HP-ZBook-Studio-15-6-inch-G8-Mobile-Workstation-PC:~$ mysql -h 10.xx.xx.xx -uliusx -p
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 33
Server version: 8.0.34-0ubuntu0.99.04.1 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> exit
Bye

>>>>> 欢迎关注公众号【三戒纪元】 <<<<<

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值