I installed mysql and set password for root but failed to login, why?











up vote
0
down vote

favorite












I have searched many similar problems and I had reset my password.
I was just so qurious and want to know WHY this happend.
Most problems have something to do with remote login and anonymous user, what I encountered is different.



after installation, I executed



$ mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

$ sudo service mysql start
* Starting MySQL database server mysqld
No directory, logging in with HOME=/

$ sudo mysql_secure_installation
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: n
Please set the password for root here.

New password:

Re-enter new password:
...


Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!


then, I tried to log in and got



~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'


I am sure I used the correct password.



Here is the user table:



+------------------+-----------+-----------------------+
| User | host | plugin |
+------------------+-----------+-----------------------+
| root | localhost | auth_socket |
| mysql.session | localhost | mysql_native_password |
| mysql.sys | localhost | mysql_native_password |
| debian-sys-maint | localhost | mysql_native_password |
+------------------+-----------+-----------------------+


Could someone please explain it?










share|improve this question
























  • Simply reset once and check, using the steps below. (without even requiring ur current password)
    – Srikanth A
    Nov 12 at 4:53










  • Please mark as answered, if it answers
    – Srikanth A
    Nov 12 at 4:54















up vote
0
down vote

favorite












I have searched many similar problems and I had reset my password.
I was just so qurious and want to know WHY this happend.
Most problems have something to do with remote login and anonymous user, what I encountered is different.



after installation, I executed



$ mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

$ sudo service mysql start
* Starting MySQL database server mysqld
No directory, logging in with HOME=/

$ sudo mysql_secure_installation
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: n
Please set the password for root here.

New password:

Re-enter new password:
...


Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!


then, I tried to log in and got



~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'


I am sure I used the correct password.



Here is the user table:



+------------------+-----------+-----------------------+
| User | host | plugin |
+------------------+-----------+-----------------------+
| root | localhost | auth_socket |
| mysql.session | localhost | mysql_native_password |
| mysql.sys | localhost | mysql_native_password |
| debian-sys-maint | localhost | mysql_native_password |
+------------------+-----------+-----------------------+


Could someone please explain it?










share|improve this question
























  • Simply reset once and check, using the steps below. (without even requiring ur current password)
    – Srikanth A
    Nov 12 at 4:53










  • Please mark as answered, if it answers
    – Srikanth A
    Nov 12 at 4:54













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have searched many similar problems and I had reset my password.
I was just so qurious and want to know WHY this happend.
Most problems have something to do with remote login and anonymous user, what I encountered is different.



after installation, I executed



$ mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

$ sudo service mysql start
* Starting MySQL database server mysqld
No directory, logging in with HOME=/

$ sudo mysql_secure_installation
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: n
Please set the password for root here.

New password:

Re-enter new password:
...


Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!


then, I tried to log in and got



~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'


I am sure I used the correct password.



Here is the user table:



+------------------+-----------+-----------------------+
| User | host | plugin |
+------------------+-----------+-----------------------+
| root | localhost | auth_socket |
| mysql.session | localhost | mysql_native_password |
| mysql.sys | localhost | mysql_native_password |
| debian-sys-maint | localhost | mysql_native_password |
+------------------+-----------+-----------------------+


Could someone please explain it?










share|improve this question















I have searched many similar problems and I had reset my password.
I was just so qurious and want to know WHY this happend.
Most problems have something to do with remote login and anonymous user, what I encountered is different.



after installation, I executed



$ mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

$ sudo service mysql start
* Starting MySQL database server mysqld
No directory, logging in with HOME=/

$ sudo mysql_secure_installation
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: n
Please set the password for root here.

New password:

Re-enter new password:
...


Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!


then, I tried to log in and got



~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'


I am sure I used the correct password.



Here is the user table:



+------------------+-----------+-----------------------+
| User | host | plugin |
+------------------+-----------+-----------------------+
| root | localhost | auth_socket |
| mysql.session | localhost | mysql_native_password |
| mysql.sys | localhost | mysql_native_password |
| debian-sys-maint | localhost | mysql_native_password |
+------------------+-----------+-----------------------+


Could someone please explain it?







mysql login






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 4:43









Gunasekar

5381417




5381417










asked Nov 12 at 4:33









kakakali

63




63












  • Simply reset once and check, using the steps below. (without even requiring ur current password)
    – Srikanth A
    Nov 12 at 4:53










  • Please mark as answered, if it answers
    – Srikanth A
    Nov 12 at 4:54


















  • Simply reset once and check, using the steps below. (without even requiring ur current password)
    – Srikanth A
    Nov 12 at 4:53










  • Please mark as answered, if it answers
    – Srikanth A
    Nov 12 at 4:54
















Simply reset once and check, using the steps below. (without even requiring ur current password)
– Srikanth A
Nov 12 at 4:53




Simply reset once and check, using the steps below. (without even requiring ur current password)
– Srikanth A
Nov 12 at 4:53












Please mark as answered, if it answers
– Srikanth A
Nov 12 at 4:54




Please mark as answered, if it answers
– Srikanth A
Nov 12 at 4:54












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Just reset the password using the steps below.



Source - MYSQL Reference Manual



1.) Log on to your system as the Unix user that the MySQL server runs as (for example, mysql).




  1. Stop the MySQL server if it is running. Locate the .pid file that contains the server's process ID. The exact location and name of this file depend on your distribution, host name, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/. Generally, the file name has an extension of .pid and begins with either mysqld or your system's host name.


Stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process. Use the actual path name of the .pid file in the following command:




shell> kill cat /mysql-data-directory/host_name.pid1




Use backticks (not forward quotation marks) with the cat command. These cause the output of cat to be substituted into the kill command.




  1. Create a text file containing the following statement on a single line. Replace the password with the password that you want to use.



SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');1





  1. Save the file. This example assumes that you name the file /home/me/mysql-init. The file contains the password, so do not save it where it can be read by other users. If you are not logged in as mysql (the user the server runs as), make sure that the file has permissions that permit mysql to read it.


  2. Start the MySQL server with the special --init-file option:




shell> mysqld --init-file=/home/me/mysql-init &1




The server executes the contents of the file named by the --init-file option at startup, changing the 'root'@'localhost' account password.



Other options may be necessary as well, depending on how you normally start your server. For example, --defaults-file may be needed before --init-file.




  1. After the server has started successfully, delete /home/me/mysql-init.


You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256015%2fi-installed-mysql-and-set-password-for-root-but-failed-to-login-why%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Just reset the password using the steps below.



    Source - MYSQL Reference Manual



    1.) Log on to your system as the Unix user that the MySQL server runs as (for example, mysql).




    1. Stop the MySQL server if it is running. Locate the .pid file that contains the server's process ID. The exact location and name of this file depend on your distribution, host name, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/. Generally, the file name has an extension of .pid and begins with either mysqld or your system's host name.


    Stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process. Use the actual path name of the .pid file in the following command:




    shell> kill cat /mysql-data-directory/host_name.pid1




    Use backticks (not forward quotation marks) with the cat command. These cause the output of cat to be substituted into the kill command.




    1. Create a text file containing the following statement on a single line. Replace the password with the password that you want to use.



    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');1





    1. Save the file. This example assumes that you name the file /home/me/mysql-init. The file contains the password, so do not save it where it can be read by other users. If you are not logged in as mysql (the user the server runs as), make sure that the file has permissions that permit mysql to read it.


    2. Start the MySQL server with the special --init-file option:




    shell> mysqld --init-file=/home/me/mysql-init &1




    The server executes the contents of the file named by the --init-file option at startup, changing the 'root'@'localhost' account password.



    Other options may be necessary as well, depending on how you normally start your server. For example, --defaults-file may be needed before --init-file.




    1. After the server has started successfully, delete /home/me/mysql-init.


    You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.






    share|improve this answer

























      up vote
      0
      down vote













      Just reset the password using the steps below.



      Source - MYSQL Reference Manual



      1.) Log on to your system as the Unix user that the MySQL server runs as (for example, mysql).




      1. Stop the MySQL server if it is running. Locate the .pid file that contains the server's process ID. The exact location and name of this file depend on your distribution, host name, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/. Generally, the file name has an extension of .pid and begins with either mysqld or your system's host name.


      Stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process. Use the actual path name of the .pid file in the following command:




      shell> kill cat /mysql-data-directory/host_name.pid1




      Use backticks (not forward quotation marks) with the cat command. These cause the output of cat to be substituted into the kill command.




      1. Create a text file containing the following statement on a single line. Replace the password with the password that you want to use.



      SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');1





      1. Save the file. This example assumes that you name the file /home/me/mysql-init. The file contains the password, so do not save it where it can be read by other users. If you are not logged in as mysql (the user the server runs as), make sure that the file has permissions that permit mysql to read it.


      2. Start the MySQL server with the special --init-file option:




      shell> mysqld --init-file=/home/me/mysql-init &1




      The server executes the contents of the file named by the --init-file option at startup, changing the 'root'@'localhost' account password.



      Other options may be necessary as well, depending on how you normally start your server. For example, --defaults-file may be needed before --init-file.




      1. After the server has started successfully, delete /home/me/mysql-init.


      You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Just reset the password using the steps below.



        Source - MYSQL Reference Manual



        1.) Log on to your system as the Unix user that the MySQL server runs as (for example, mysql).




        1. Stop the MySQL server if it is running. Locate the .pid file that contains the server's process ID. The exact location and name of this file depend on your distribution, host name, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/. Generally, the file name has an extension of .pid and begins with either mysqld or your system's host name.


        Stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process. Use the actual path name of the .pid file in the following command:




        shell> kill cat /mysql-data-directory/host_name.pid1




        Use backticks (not forward quotation marks) with the cat command. These cause the output of cat to be substituted into the kill command.




        1. Create a text file containing the following statement on a single line. Replace the password with the password that you want to use.



        SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');1





        1. Save the file. This example assumes that you name the file /home/me/mysql-init. The file contains the password, so do not save it where it can be read by other users. If you are not logged in as mysql (the user the server runs as), make sure that the file has permissions that permit mysql to read it.


        2. Start the MySQL server with the special --init-file option:




        shell> mysqld --init-file=/home/me/mysql-init &1




        The server executes the contents of the file named by the --init-file option at startup, changing the 'root'@'localhost' account password.



        Other options may be necessary as well, depending on how you normally start your server. For example, --defaults-file may be needed before --init-file.




        1. After the server has started successfully, delete /home/me/mysql-init.


        You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.






        share|improve this answer












        Just reset the password using the steps below.



        Source - MYSQL Reference Manual



        1.) Log on to your system as the Unix user that the MySQL server runs as (for example, mysql).




        1. Stop the MySQL server if it is running. Locate the .pid file that contains the server's process ID. The exact location and name of this file depend on your distribution, host name, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/. Generally, the file name has an extension of .pid and begins with either mysqld or your system's host name.


        Stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process. Use the actual path name of the .pid file in the following command:




        shell> kill cat /mysql-data-directory/host_name.pid1




        Use backticks (not forward quotation marks) with the cat command. These cause the output of cat to be substituted into the kill command.




        1. Create a text file containing the following statement on a single line. Replace the password with the password that you want to use.



        SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');1





        1. Save the file. This example assumes that you name the file /home/me/mysql-init. The file contains the password, so do not save it where it can be read by other users. If you are not logged in as mysql (the user the server runs as), make sure that the file has permissions that permit mysql to read it.


        2. Start the MySQL server with the special --init-file option:




        shell> mysqld --init-file=/home/me/mysql-init &1




        The server executes the contents of the file named by the --init-file option at startup, changing the 'root'@'localhost' account password.



        Other options may be necessary as well, depending on how you normally start your server. For example, --defaults-file may be needed before --init-file.




        1. After the server has started successfully, delete /home/me/mysql-init.


        You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 4:52









        Srikanth A

        1,87931022




        1,87931022






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256015%2fi-installed-mysql-and-set-password-for-root-but-failed-to-login-why%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python