Want more timely Centmin Mod News Updates?
Become a Member

127.0.0.1 vs localhost

Discussion in 'MariaDB & General MySQL news & discussions' started by pamamolf, Dec 19, 2017.

  1. pamamolf

    pamamolf Premium Member Premium Member

    4,077
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    5:09 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    Hello :)

    Reading on the net i found that localhost (FOR LINUX) it will be a bit faster as it uses sockets but in practice some times it seems 127.0.0.1 to perform better :)

    What do you use on your config files to connect to the database?


    Thank you
     
  2. rdan

    rdan Well-Known Member

    5,444
    1,408
    113
    May 25, 2014
    Ratings:
    +2,201
    Local Time:
    11:09 PM
    Mainline
    10.2
    127.0.0.1 :D
     
  3. pamamolf

    pamamolf Premium Member Premium Member

    4,077
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    5:09 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    If I am not wrong I think the my admin cli took when I create a user it uses only localhost and not 127.0.0.1 and if i have to add that by changing the related permissions setting....
     
  4. pamamolf

    pamamolf Premium Member Premium Member

    4,077
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    5:09 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    If I am not wrong I think the Centminmod myadmin cli tool when I create a user it uses only localhost and not 127.0.0.1 and if i have to add that by changing the related permissions setting....
     
    Last edited: Dec 19, 2017
  5. eva2000

    eva2000 Administrator Staff Member

    54,389
    12,198
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,763
    Local Time:
    1:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    read/google the diff between localhost vs 127.0.0.1 for unix/linux and mysql and you'll know (you've already you've mentioned why).
     
  6. pamamolf

    pamamolf Premium Member Premium Member

    4,077
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    5:09 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    I just wondering why many users are getting better results using the 127.0.0.1 .....

    Ok thanks :)
     
  7. Sunka

    Sunka Well-Known Member

    1,150
    325
    83
    Oct 31, 2015
    Pula, Croatia
    Ratings:
    +525
    Local Time:
    4:09 PM
    Nginx 1.17.9
    MariaDB 10.3.22
    localhost only for elasticsearch
     
  8. pamamolf

    pamamolf Premium Member Premium Member

    4,077
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    5:09 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    When i create a new database and add a user using:

    Code:
    /usr/local/src/centminmod/addons/mysqladmin_shell.sh setuserdb
    then when i use on the config the "localhost" it works but if i use "127.0.0.1" it doesn't with an error permission denied....

    Does the tool create the user with localhost access and restrict access for 127.0.0.1 or something related?

    I have on my dns also:

    Code:
    127.0.0.1   localhost   localhost.localdomain localhost4 localhost4.localdomain4
    ::1     localhost   localhost.localdomain localhost6 localhost6.localdomain6
    123.456.789.000   server.mydomain.com   server
    
    On my second server with the exact same setup both working....

    It will be great to find out why it doesn't work when i use 127.0.0.1 without setting the permissions to % or 127.0.0.1 as it can be done with localhost for both....

    Don't know if it is related but the on that works it uses a very new Centminmod setup and the other one that doesn't work uses a very old Centminmod installation....
     
    Last edited: Dec 20, 2017
  9. eva2000

    eva2000 Administrator Staff Member

    54,389
    12,198
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,763
    Local Time:
    1:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    that is expected as 127.0.0.1 and localhost in mysql eyes are 2 separate hostnames. Read official documentation/manual at MySQL :: MySQL 5.6 Reference Manual :: 13.7.1.2 CREATE USER Syntax and MySQL :: MySQL 5.6 Reference Manual :: 13.7.1.4 GRANT Syntax

    Centmin Mod has always only used localhost for mysqladmin_shell.sh, so maybe older setup used another method to grant privileges. So easiest thing to do is query and check how your mysql user was created/privileges granted.
    you probably altered the privileges on the newer server ?? as I said just query check the privileges for the user on both hostnames to check.
     
  10. pamamolf

    pamamolf Premium Member Premium Member

    4,077
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    5:09 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    For the user that doesn't work i am getting:

    Code:
    --------------
    SHOW GRANTS FOR 'forum_db'@'localhost'
    --------------
    
    +-------------------------------------------------------------------------------------------------------------------+
    | Grants for forum_db@localhost                                                                                   |
    +-------------------------------------------------------------------------------------------------------------------+
    | GRANT USAGE ON *.* TO 'forum_db'@'localhost' IDENTIFIED BY PASSWORD '*DDFB5C91B43' |
    | GRANT ALL PRIVILEGES ON `forum\_db`.* TO 'forum_db'@'localhost' WITH GRANT OPTION                             |
    +-------------------------------------------------------------------------------------------------------------------+
    and the working one is:

    Code:
    --------------
    SHOW GRANTS FOR 'forum_db'@'localhost'
    --------------
    
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Grants for forum_db@localhost                                                                                                                                   |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | GRANT USAGE ON *.* TO 'forum_db'@'localhost' IDENTIFIED BY PASSWORD '*990E1234A40EBB8C'                                                 |
    | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON `forum_db`.* TO 'forum_db'@'localhost' |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    Any ideas?

    Thank you


    Also both use same dns settings:

    Code:
    127.0.0.1   localhost   localhost.localdomain localhost4 localhost4.localdomain4
    ::1     localhost   localhost.localdomain localhost6 localhost6.localdomain6
    123.456.789.000   server.mydomain.com   server
     
  11. eva2000

    eva2000 Administrator Staff Member

    54,389
    12,198
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,763
    Local Time:
    1:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    one not working as an erroneous backslash in db name = forum\_db
     
  12. pamamolf

    pamamolf Premium Member Premium Member

    4,077
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    5:09 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    Problem found :)

    config file should not have skip networking :)

    Now it works !

    But don't know really if localhost is faster as a user report this:

    and a tcp connection seems faster.... ?
     
  13. eva2000

    eva2000 Administrator Staff Member

    54,389
    12,198
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,763
    Local Time:
    1:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Not really an accurate test for mysql connection performance