Learn about Centmin Mod LEMP Stack today
Register Now

127.0.0.1 vs localhost

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

  1. pamamolf

    pamamolf Well-Known Member

    3,113
    295
    83
    May 31, 2014
    Ratings:
    +530
    Local Time:
    10:05 AM
    Nginx-1.13.x
    MariaDB 10.1.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 Premium Member Premium Member

    4,256
    1,035
    113
    May 25, 2014
    Ratings:
    +1,487
    Local Time:
    3:05 PM
    Mainline
    10.2
    127.0.0.1 :D
     
  3. pamamolf

    pamamolf Well-Known Member

    3,113
    295
    83
    May 31, 2014
    Ratings:
    +530
    Local Time:
    10:05 AM
    Nginx-1.13.x
    MariaDB 10.1.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 Well-Known Member

    3,113
    295
    83
    May 31, 2014
    Ratings:
    +530
    Local Time:
    10:05 AM
    Nginx-1.13.x
    MariaDB 10.1.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

    36,062
    7,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,195
    Local Time:
    5:05 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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 Well-Known Member

    3,113
    295
    83
    May 31, 2014
    Ratings:
    +530
    Local Time:
    10:05 AM
    Nginx-1.13.x
    MariaDB 10.1.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,003
    276
    83
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +453
    Local Time:
    9:05 AM
    Nginx 1.15.0
    MariaDB 10.2.15
    localhost only for elasticsearch
     
  8. pamamolf

    pamamolf Well-Known Member

    3,113
    295
    83
    May 31, 2014
    Ratings:
    +530
    Local Time:
    10:05 AM
    Nginx-1.13.x
    MariaDB 10.1.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

    36,062
    7,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,195
    Local Time:
    5:05 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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 Well-Known Member

    3,113
    295
    83
    May 31, 2014
    Ratings:
    +530
    Local Time:
    10:05 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    For the user that doesn't work i am getting:

    Code:
    --------------
    SHOW GRANTS FOR 'forum_db'@'localhost'
    --------------
    
    +-------------------------------------------------------------------------------------------------------------------+
    | Grants for [email protected]                                                                                   |
    +-------------------------------------------------------------------------------------------------------------------+
    | 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 [email protected]                                                                                                                                   |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | 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

    36,062
    7,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,195
    Local Time:
    5:05 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    one not working as an erroneous backslash in db name = forum\_db
     
  12. pamamolf

    pamamolf Well-Known Member

    3,113
    295
    83
    May 31, 2014
    Ratings:
    +530
    Local Time:
    10:05 AM
    Nginx-1.13.x
    MariaDB 10.1.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

    36,062
    7,912
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,195
    Local Time:
    5:05 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Not really an accurate test for mysql connection performance
     
..