MySQL 连接不上的常见问题

这篇具有很好参考价值的文章主要介绍了MySQL 连接不上的常见问题。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1.windows的ip问题
    ping Linux服务器的ip,检查网络是否通畅
    Linux服务器的网络问题
2.连接的用户是否有授权
    grant 
3.linux里的防火墙是否开启
    iptables -L
    service firewalld stop
4.检查下mysql服务是否开启
    ps aux|grep mysqld
5.检查下端口号是否修改
    netstat -anlput|grep mysqld
6.云服务器的安全组


1.windows里检查,打开cmd,ping Linux服务器ip,检查网络。

mysql连不上,MySQL,mysql,数据库,linux

 Linux服务器检查,ping百度、windows机器等,检查网络。

[root@mysql mysql]# ping www.baidu.com
PING www.a.shifen.com (112.80.248.75) 56(84) bytes of data.
64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=1 ttl=128 time=62.2 ms
64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=2 ttl=128 time=72.0 ms
64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=3 ttl=128 time=26.5 ms
64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=4 ttl=128 time=24.9 ms
64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=5 ttl=128 time=25.9 ms
64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=6 ttl=128 time=31.4 ms


[root@mysql mysql]# ping 192.168.1.117
PING 192.168.1.117 (192.168.1.117) 56(84) bytes of data.
64 bytes from 192.168.1.117: icmp_seq=1 ttl=128 time=0.658 ms
64 bytes from 192.168.1.117: icmp_seq=2 ttl=128 time=1.71 ms
64 bytes from 192.168.1.117: icmp_seq=3 ttl=128 time=1.84 ms
64 bytes from 192.168.1.117: icmp_seq=4 ttl=128 time=0.708 ms

文件socket:实现一台电脑里的不同进程之间通信的文件
网络socket:ip+端口( 实现跨宿主机之间通信)

[root@mysql etc]# cat my.cnf
[mysqld_safe]

[client]
#socket=/data/mysql/mysql.sock

[mysqld]
socket=/data/mysql/mysql.sock
port = 3306
open_files_limit = 8192
innodb_buffer_pool_size = 512M
character-set-server=utf8

[mysql]
auto-rehash
prompt=\u@\d \R:\m  mysql>

[root@mysql ~]# mysql -uroot -p123456sc
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)

# 使用文件socket
[root@mysql ~]# mysql -uroot -p123456sc  -S /data/mysql/mysql.sock
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 3
Server version: 5.7.41 MySQL Community Server (GPL)

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.

root@(none) 12:12  mysql>

[root@mysql ~]# mysql -h 192.168.102.139 -P3306 -uroot -p'your passwd'
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1130 (HY000): Host 'mysql' is not allowed to connect to this MySQL server

创建一个用户并且授权

# 连接MySQL
[root@mysql ~]# mysql -uroot -p'your passwd'
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 7
Server version: 5.7.41 MySQL Community Server (GPL)

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.

# 创建一个用户
root@(none) 18:47  mysql>create user 'hanwl'@'%' identified by '123456sc';
Query OK, 0 rows affected (0.00 sec)

# 给这个用户授权
root@(none) 18:48  mysql>grant all on *.* to 'hanwl'@'%';
Query OK, 0 rows affected (0.00 sec)

'hanwl'@'%'
% 是通配符,代表任意的字符串

grant 是mysql里的授权命令
all 代表授予所有的权限 select、insert、update、delete等
on *.* 第1个* 代表库,第2个*代表库
to 'hanwl'@'%' 给具体的用户

[root@mysql ~]# mysql -h 192.168.102.139 -P3306 -uhanwl -p123456sc
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 9
Server version: 5.7.41 MySQL Community Server (GPL)

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.

hanwl@(none) 18:49  mysql>

添加一条防火墙规则

[root@mysql ~]# iptables -A INPUT -p tcp --dport 3306 -j DROP
[root@mysql ~]# iptables -L -n -v
Chain INPUT (policy ACCEPT 77 packets, 4484 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    7   700 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:3306

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 48 packets, 3792 bytes)
 pkts bytes target     prot opt in     out     source               destination         

[root@mysql ~]# mysql -h 192.168.102.139 -P3306 -uhanwl -p123456sc
mysql: [Warning] Using a password on the command line interface can be insecure.

去除刚添加的防火墙规则

[root@mysql ~]# iptables -D INPUT -p tcp --dport 3306 -j DROP

[root@mysql ~]# mysql -h 192.168.102.139 -P3306 -uhanwl -p123456sc
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 10
Server version: 5.7.41 MySQL Community Server (GPL)

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.

hanwl@(none) 18:53  mysql>

mysql服务是否开启

看进程

[root@mysql etc]# ps aux|grep mysqld
root      10231  0.0  0.0  11824  1600 ?        S    12:41   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
mysql     10387  0.1 13.2 1763324 246660 ?      Sl   12:41   0:23 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql.err --open-files-limit=8192 --pid-file=/data/mysql/mysql.pid --socket=/data/mysql/mysql.sock --port=3306
root      10598  0.0  0.0 112832   988 pts/2    S+   16:31   0:00 grep --color=auto mysqld

看端口

[root@mysql etc]# netstat -anlput|grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      10387/mysqld        
tcp6       0      0 192.168.102.139:3306    192.168.102.1:60719     ESTABLISHED 10387/mysqld  

直接进入MySQL

[root@mysql ~]# mysql -uroot -p'Sanchuang1234#'
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 8
Server version: 5.7.37 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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.

root@(none) 18:47  mysql>

看日志

[root@mysql mysql]# tail slave.err 
2023-07-22T10:41:12.871873Z 1 [ERROR] Slave I/O for channel '': error connecting to master 'screpl@192.168.102.139:3306' - retry-time: 60  retries: 143, Error_code: 2003
2023-07-22T10:42:15.913241Z 1 [ERROR] Slave I/O for channel '': error connecting to master 'screpl@192.168.102.139:3306' - retry-time: 60  retries: 144, Error_code: 2003
2023-07-22T10:43:18.950869Z 1 [ERROR] Slave I/O for channel '': error connecting to master 'screpl@192.168.102.139:3306' - retry-time: 60  retries: 145, Error_code: 2003
2023-07-22T10:44:21.983706Z 1 [ERROR] Slave I/O for channel '': error connecting to master 'screpl@192.168.102.139:3306' - retry-time: 60  retries: 146, Error_code: 2003
2023-07-22T10:45:25.014526Z 1 [ERROR] Slave I/O for channel '': error connecting to master 'screpl@192.168.102.139:3306' - retry-time: 60  retries: 147, Error_code: 2003
2023-07-22T10:46:28.043188Z 1 [ERROR] Slave I/O for channel '': error connecting to master 'screpl@192.168.102.139:3306' - retry-time: 60  retries: 148, Error_code: 2003
2023-07-22T10:47:31.062752Z 1 [ERROR] Slave I/O for channel '': error connecting to master 'screpl@192.168.102.139:3306' - retry-time: 60  retries: 149, Error_code: 2003
2023-07-22T10:47:34.379215Z 7 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2023-07-22T10:48:34.081550Z 1 [ERROR] Slave I/O for channel '': error connecting to master 'screpl@192.168.102.139:3306' - retry-time: 60  retries: 150, Error_code: 2003
2023-07-22T10:49:37.122049Z 1 [ERROR] Slave I/O for channel '': error connecting to master 'screpl@192.168.102.139:3306' - retry-time: 60  retries: 151, Error_code: 2003

看服务状态状态

[root@mysql mysql]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (running) since 六 2023-07-22 15:22:47 CST; 3h 28min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 6641 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
    Tasks: 32
   Memory: 272.4M
   CGroup: /system.slice/mysqld.service
           ├─6663 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/slave...
           └─6996 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/...

7月 22 15:22:43 slave systemd[1]: Starting LSB: start and stop MySQL...
7月 22 15:22:47 slave mysqld[6641]: Starting MySQL.... SUCCESS!
7月 22 15:22:47 slave systemd[1]: Started LSB: start and stop MySQL.

云服务器 --》检查安全组

mysql连不上,MySQL,mysql,数据库,linux

 文章来源地址https://www.toymoban.com/news/detail-778515.html

到了这里,关于MySQL 连接不上的常见问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • MySQL常见问题处理(三)

    夕阳留恋的不是黄昏,而是朝阳 上一章简单介绍了MySQL数据库安装(二), 如果没有看过, 请观看上一章 复制内容来源链接: https://blog.csdn.net/weixin_48927364/article/details/123556927 以 管理员身份 打开 cmd窗口 ,停止mysq服务,即输入以下命令,回车 继续输入以下命令,回车 注意不要关

    2024年02月14日
    浏览(34)
  • MySql常见问题(长期更新)

    2023年06月21日
    浏览(41)
  • mysql_2.4——安装常见问题

    1. 将MySQL添加到环境变量 将 mysql 的 bin 目录地址添加到 系统环境变量 -- PATH 中 2. 将MySQL添加到服务 以管理员的方式启动 cmd (命令提示窗口),使用命令进入到 ` [mysql]bin ` ,执行如下命 令。 删除服务命令是: 3. mysql端口被占用解决 在 cmd 窗口下执行如下命令: 查找正在执行的

    2024年02月15日
    浏览(44)
  • 「MySQL」MySQL面试题全解析:常见问题与高级技巧详解

    回答:数据库是一个组织和存储数据的集合,可通过各种方式对数据进行访问、管理和操作。 回答:MySQL是一种开源的关系型数据库管理系统,广泛用于Web应用程序的后端数据存储。 回答:SQL(Structured Query Language)是一种用于管理关系型数据库的标准语言,用于查询、插入

    2024年02月10日
    浏览(33)
  • 「MySQL运维常见问题及解决方法」

    💖The Begin💖点点关注,收藏不迷路💖 在某些情况下,我们可能需要查看MySQL数据库的安装路径,以便进行一些特定的操作或配置。 步骤1:登录MySQL数据库 首先,我们需要登录MySQL数据库。可以使用命令行工具或者图形化界面进行登录。在命令行中,可以使用以下命令登录:

    2024年02月03日
    浏览(39)
  • MySQL 索引常见问题汇总,一次性梳理

    hello,大家好,我是张张,「架构精进之路」公号作者。   提到MySQL查询分析,就会涉及到索引相关知识,要想学好MySQL,索引是重要且不得不啃下的一环,今天就把MySQL索引常见问题进行汇总,一次性梳理清楚。 文章目录: 索引 什么是索引? 索引的优缺点? 索引的作用?

    2024年02月07日
    浏览(34)
  • MYSQL 8.0.32linux 本地安装步骤及常见问题

    1.下载安装包,根据各自系统选择对应系统版本及mysql安装包MySQL :: Download MySQL Community Server, 服务器可联网可用​wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz  2.上传安装包至linux 目录下,常用/usr/local/mysql  3. 解压安装包:tar -xvf /安装包目录/安装包

    2024年02月09日
    浏览(45)
  • linux安装mysql-8.0.33正确方式及常见问题

    目录 获取mysql下载地址链接  解压安装包  复制文件到安装目录  添加用户和用户属组修改权限  创建存储数据的文件夹/usr/local/mysql 初始化安装 修改配置文件  创建日志文件并赋予对应权限  启动成功​编辑 创建软链接 之前安装过mysql,时间比较长忘记安装步骤了今天就记

    2024年02月12日
    浏览(38)
  • QT的mysql(数据库)最佳实践和常见问题解答

    涉及到数据库,首先安利一个软件Navicat Premium,用来查询数据库很方便  QMysql驱动是Qt SQL模块使用的插件,用于与MySQL数据库进行通信。要编译QMysql驱动,您需要满足以下条件: 您需要安装MySQL的客户端库和开发头文件,这些文件通常随MySQL的安装程序一起提供,或者可以从

    2024年02月12日
    浏览(56)
  • 如何解决MySQL连接不上本地服务器问题

    MySQL是一个开源的、关系型数据库管理系统,在开发过程中被广泛使用。有时候我们可能会遇到MySQL连接不上本地服务器的问题,这个问题可能由于多种原因引起。本文将从多个方面对此进行详细阐述,并给出对应的代码示例。 首先,我们需要检查MySQL是否已经启动。如果My

    2024年02月08日
    浏览(40)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包