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