How do I connect to localhost, 127.0.0.1 and ::1 respectively in mysql (MariaDB)?

Asked 2 years ago, Updated 2 years ago, 137 views

Installing mysql (10.1.30-MariaDB)

+------------------------------------------------------------------------------------------------------------------
| host | user | password | ssl_type |
+-----------+------+-------------------------------------------+----------+
| localhost | root | | |
| 127.0.0.1 | root | |
| ::1 | root |                                      |          |
| localhost | | |
| localhost | pma | | |
+-----------+------+-------------------------------------------+----------+

There are five users.

I have two questions.

1. If I enter mysql-u root-p**, the host will probably connect to the localhost, but if I connect to 127.0.0.1 or ::1, can I connect to mysql-h 127.0.0.1-u root-p** or mysql-h:::1-u root-p***?
Connect to each of the three accounts and do select current_user()

MariaDB[(none)]>select current_user();
+----------------+
| current_user()|
+----------------+
| root@localhost|
+----------------+
1 row in set (0.00 sec)

I only got a reply, so I think I can only connect to localhost. I thought it would definitely be [email protected], root@::1, but why not?
Or how can I connect to these hosts?

I think 2.::1 is for those who use ipv6, but if they use ipv6, does it mean that the host cannot connect with localhost, 127.0.0.1?

https://teratail.com/questions/115682

mysql database mariadb

2022-09-30 15:03

1 Answers

-hlocalhost is a UNIX socket connection, and the user of mysqld is also username@localhost.

-h127.0.0.1, -h::1 indicates a TCP/IP connection, but which user you will be depends on mysqld's skip-name-resolve setting.

When skip-name-resolve=false (default), 127.0.0.1, ::1 are both username@localhost users.

If skip-name-resolve=true, you will be the [email protected], username@::1 user because you will use the IP address as it is.


2022-09-30 15:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.