1

Background

I'm setting up a MySQL server. Its configuration file (my.cnf) does not have the bind_address option. As I understand from its documentation, its value defaults to *, which should make the server listen on all IPv4 or IPv6 addresses.

Problem

When I start the MySQL server, I expect it to listen to IPv4. Instead, it listens only to IPv6 as I've checked below.

$ netstat -nlt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp6 0 0 :::33060 :::* LISTEN tcp6 0 0 :::3306 :::* LISTEN # -- snip -- 

Why is this happening? And how can I let the MySQL server listen to IPv4 address?

What I have checked so far:

  • I made sure that there are no other configuration file that unintentionally overrides the bind_address. When I query SELECT @@bind_address, it correctly shows * as intended.
  • I confirm that IPv4 networking is configured on my system. Running ip addr show shows that eth0 is assigned an IPv4 address. In fact, I don't think my system is configured for IPv6, as I don't see any inet with IPv6.
  • When I explicitly set bind_address=0.0.0.0 in my.cnf and then restart the server, the server still listens to IPv6 address, showing the same netstat output above.
  • There are no other MySQL server instances running on my system.

Environment

  • MySQL server: v8.0.36
  • OS: CentOS 7
7
  • Have you tried connecting to IPv4 address? Commented Mar 5, 2024 at 6:24
  • @AlexD When I run mysql -u root -p -h 127.0.0.1, I'm able connect. Is that what you mean? Commented Mar 5, 2024 at 6:32
  • @AlexD On the other hand, when I try to connect to the MySQL server from another machine as sql-user and setting the -h option equal to the hostname of the MySQL server, I'm unable to connect. The network properly configured, and the MySQL user account, credentials and grants for sql-user are also properly configured. Commented Mar 5, 2024 at 6:36
  • Connect to the IPv4 address (not 127.0.0.1) from the server itself. Commented Mar 5, 2024 at 6:38
  • @AlexD When I ping <self ipv4>, it shows 100% transmitted. Is that how I should check? Sorry, I'm new to network-related stuff. Commented Mar 5, 2024 at 7:04

1 Answer 1

2

The quote from the documentation you linked:

If the address is *, the server accepts TCP/IP connections on all server host IPv4 interfaces, and, if the server host supports IPv6, on all IPv6 interfaces. Use this address to permit both IPv4 and IPv6 connections on all server interfaces. This value is the default.

By default on Linux listening on a IPv6 socket also accepts IPv4 connections, so it won't show a separate tcp socket in the netstat output but still would work with IPv4.

1
  • When I run mysql -p -u sql-user -h <self ipv4>, I confirm that I'm able to connect. Didn't know that's how to interpret the output of netstat. Thanks. Commented Mar 5, 2024 at 7:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.