Ошибка 1698 mysql

Are you getting the following error when trying to login to the MySQL root on an Ubuntu system or other Linux distribution? We’ll show you how to clear it up in a matter of seconds.

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Explanation: This error is caused by the auth_socket plugin. The simplest solution is to just disable the plugin which we will show you how to do below.

Follow the corresponding section below, depending on whether you’re running MySQL Server or MariaDB Server, as both implementations require a different solution to fix the root login problem.

MySQL Server

In this section, we will fix the ERROR 1698 for a MySQL Server installation:

Step 1. Log in to MySQL as root (using sudo will bypass MySQL’s password prompt):

$ sudo mysql -u root

Step 2. Change to the mysql database and set the plugin to mysql_native_password for the root user:

mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> FLUSH PRIVILEGES;

Step 3. You have to change the root password for this to work. Even just specifying the current password is fine too, but this command must be executed:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password_here';
mysql> exit;

Step 4. Lastly, restart MySQL for the changes to take effect:

$ sudo systemctl restart mysql

Step 5. You can now log in to MySQL root as normal, and will no longer encounter the error:

$ mysql -u root -p

MariaDB Server

In this section, we will fix the ERROR 1698 for a MariaDB Server installation:

Step 1. The solution for MariaDB is different. Users need to run through initial setup by executing:

$ sudo mysql_secure_installation

Step 2. Press enter when prompted for root password:

Enter current password for root (enter for none):

Step 3. Answer N when asked to enable unix_socket authentication:

Switch to unix_socket authentication [Y/n] n

Step 4. Answer Y when asked if you’d like to change the root password, then supply a new password:

Change the root password? [Y/n] y
New password: 
Re-enter new password:

Step 5. Go through the next few questions, eventually ending by answering Y to reload table privileges:

Reload privilege tables now? [Y/n] y

Step 6. You can now log in to MariaDB root as normal, and will no longer encounter the error:

$ mysql -u root -p

Did this work for you? Let us know in the comments below! Include your system information for help with troubleshooting.

With our easy steps, you can easily solve error 1698 (28000) Access denied for the user.

This error is very common when you try to log in to your MySQL for the first time.

Personally, I too faced this issue multiple times, maybe because we were not following the right way to install MySQL, or we forgot to set a password, or else we didn’t get the options to set a password.

Similarly, there may be many other reasons for the above error, but the solution to this error is pretty simple and easy. In this article, you will find a way to resolve 1698 (28000) Access denied for user ‘root’@’localhost’.

There are two ways to resolve this error.

First, you will see a simple and less time-consuming method. If the first method didn’t work in your case, then go to the second one.

Method 1: The Easiest Way to Fix Error 1698 (28000): Access Denied for User

One of the easiest ways to resolve this error is to invoke “mysql_secure_installation”, which will ask you to set a password for your MySQL root user.

$ sudo mysql_secure_installation 

You need to enter a new password and, for confirmation, re-type that password.

If the password is less than 25 characters, you will be prompted to confirm whether you want to continue or not. If you don’t want to set password characters more than 25, simply type “n”.

solve error 1698 (28000) Access denied for user: Fix error using mysq_secure_installation
Fix error using mysql_secure_installation

In my case, it didn’t work and threw me an error on-screen:

“Failed! Error: SET PASSWORD has no significance for user ‘root’@’localhost’ as the authentication method used doesn’t store authentication data in the MySQL server.

Please consider using ALTER USER instead if you want to change authentication parameters.”

If the same thing happens with you too, then close the terminal and follow the second set of steps, which worked in my case to solve error 1698 (28000) Access denied for user.

Method 2: Fix Error 1698 (28000): Access Denied for User using Alter

When you install MySQL for the first time, there is a chance you will not find the option to set a password because of the new method of authenticating users.

If it is like that, then you need to login to MySQL as a root user.

Most of the time, users may try to log in to MySQL as “mysql -u user” or “mysql -u root”, but it won’t work because “user@localhost” has not yet been created on your system, and root cannot be accessed without sudo privileges.

And when you try to log in as the root user with “mysql -u root@localhost”, you will get the below error.

MySQL Error 1698(2800) Access denied
MySQL Error 1698(2800)

Check the Authorization Mechanism

To resolve this, you must log into MySQL as a sudo on the new installation because the account that is linked with MySQL is the “root” account, not the “user” account.

Run the below command in your terminal:

$ sudo mysql -u root

Once you are logged in, you will find the MySQL console looking like the below-shown image.

Login to MySQL with sudo
Login to MySQL with sudo

Now you can access your MySQL account with the above command, but there is a small problem with this: you cannot log in to MySQL without sudo privileges.

To fix that, you can create a new user and grant the necessary privileges, or else change the password authentication mechanism of the root account.

There are different types of password mechanisms supported by MySQL by default you will find “auth_socket” for your root account to make it robust you can choose conventional “mysql_native_password” or the latest “caching_sha2_password“ on later version 8.0.0

If you want to learn more about authentication plugins, then do check out MySQL authentication documentation.

Before moving to the next step, you should check what password mechanism or plugin is attached to your root account.

To find out, you can run the following queries on the MySQL console:

mysql> SELECT User, plugin from mysql.user ;

The behavior of the above command is shown below:

Check-password-plugin-in-MySQL
Check password plugin in MySQL

Set a password on the root account

Now you can set or update your password by following the below snippet. Make sure to replace [ENTER-NEW-PASSWORD] with your password and, prior to that, select the MySQL database.

mysql> use mysql;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH 'caching_sha2_password' BY '[ENTER-NEW-PASSWORD]';

Output:

Set Password on MySQL
Set Password on MySQL

I’m using “caching_sha2_password”.

If you want to use “mysql_native_password” on > MySQL 5.7 version, type the below queries on your MySQL console.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY '[ENTER-NEW-PASSWORD]';

Once the changes have been implemented, restart the MySQL service.

$ sudo systemctl restart mysql.service

And once the service is restarted, type the below code in your terminal and enter the password which you have set above.

$ mysql -u root -p

Output:

Login to MySQL after resolving error
Login back to MySQL after resolving the error

Wrapping Up

That’s all to resolve error 1698 (28000) Access denied for user on MySQL.

I’m sure after following the above steps you will be able to resolve the issue, but if you are still having any issues, then do let me know in the comment section.

If you are interested in learning about how to change the MySQL port number, then check out this article.

See you later in the next article.

profile

A man with a tech effusive who has explored some of the amazing technology stuff and is exploring more. While moving towards, I had a chance to work on Android development, Linux, AWS, and DevOps with several open-source tools.

The error 1698 (28000): access denied for user ‘root’@’localhost’ is a common error that occurs when you do not have permission to access the database. This article covers all the details of how this error arises and what you can do to resolve it. Let’s begin!Access Denied for User Root Localhost Error

Contents

  • Why Does the Error 1698: Mysql Error Message Occurs?
    • – Incorrect Credentials
    • – Insufficient Privileges
    • – Missing Grant Privileges
    • – Firewall or Network Issues
    • – Incorrect MySQL Configuration
    • – Syntax Errors
  • How To Resolve the Error 1698: Mysql Error Message?
    • – Reset the Root Password
    • – Grant Privileges to the Root User
    • – Check the MySQL/MariaDB Configuration
    • – Check the Firewall
    • – Use a Different User Account
    • – Grant MySQL Access
    • – Correct Typo Mistake
  • Conclusion

Why Does the Error 1698: Mysql Error Message Occurs?

The error 1698 (28000): access denied for user ‘root’@’localhost’ occurs when the root user tries to perform an action requiring higher privileges than those granted. This happens when the root user’s password is incorrect or has been restricted from accessing certain databases or tables.

Additionally, this error will occur if the root user has been removed from the list of authorized users. It can also occur if there is a conflict between the user’s permissions and the privileges required by the action being performed.

  • Missing grant privileges.
  • Firewall or Network issues.
  • Incorrect MySQL configuration.
  • Syntax errors.

– Incorrect Credentials

The most common reason for this error is an incorrect username or password for the ‘root’ user. Ensure that you are using the correct username and password to log in to the MySQL server.

– Insufficient Privileges

If you have recently created a new user, it may not have sufficient privileges to access the MySQL server. Ensure that you have granted the necessary permissions to the user to access the server.

– Missing Grant Privileges

Sometimes, the user may have the necessary privileges to access the server, but the grant privileges are missing. Grant privileges are the ones that allow a user to perform specific operations on a specific database. Ensure that you have granted the necessary grant privileges to the user.Reasons of Error 1698 on Mysql Message

– Firewall or Network Issues

The server may not be reachable due to network or firewall issues. Ensure your network and firewall settings are correctly configured to allow MySQL server connections.

– Incorrect MySQL Configuration

Sometimes, the MySQL server configuration may be incorrect, which can cause the ‘Access Denied’ error. Check the configuration files to ensure that the server is correctly configured.

– Syntax Errors

Syntax errors are another reason why this error occurs. Sometimes, coders accidentally make a typo mistake or use the wrong operands and functions with the wrong brackets.

Such issues cause error messages to arise, such as:

  • Error 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: yes).
  • Access denied for user ‘root’@’localhost’ (using password: no).
  • Error 1045 mysql 28000: access denied for user’ root’@’localhost centos.
  • Error 1045 (28000): Access denied for user cacti localhost’ (using password: yes).

How To Resolve the Error 1698: Mysql Error Message?

To solve error 1698 (28000): Access denied for user ‘root’@’localhost’ error, you can grant administrative privileges to the user or create a new user with administrative access. Create a new user with administrative access by running “CREATE USER ‘new_user’@’localhost’ IDENTIFIED BY ‘password’;” and grant them administrative access.

– Reset the Root Password

If you cannot log in to the MySQL or MariaDB database using the root account, you can reset the root password. To do this, stop the MySQL/MariaDB server and restart it with the –skip-grant-tables option. This will let you log in to the database server without a password. Once you are logged in, you can reset the root password using the following command:

UPDATE mysql.user SET authentication_string = PASSWORD(‘new_password’) WHERE User = ‘root’ AND Host = ‘localhost’;

After resetting the password, restart the MySQL/MariaDB server without the –skip-grant-tables option.

– Grant Privileges to the Root User

When the root user doesn’t have the necessary privileges to access the database server, you can grant them using the given command:

GRANT ALL PRIVILEGES ON *.* TO ‘root’@’localhost’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;

Replace ‘password’ with the root user’s password.

– Check the MySQL/MariaDB Configuration

To troubleshoot this error, you should check the MySQL/MariaDB configuration settings to ensure that the ‘root’ user has permission to access the database. Here are some steps you can take:Resolve the Error 1698 Mysql Error Message

  1. Check the authentication method: MySQL/MariaDB supports several authentication methods, including the traditional password-based authentication method and the more secure plugin-based authentication method. Check your MySQL/MariaDB configuration file to ensure the authentication method is correctly set up and the ‘root’ user has a valid password or authentication plugin.
  2. Check the user permissions: Make sure that the ‘root’ user has the permissions to access the database. You can verify this by running the below command:

SELECT user, host, plugin FROM mysql.user WHERE user = ‘root’;

This will show you the authentication plugin being used by the ‘root’ user and the hostnames from which the ‘root’ user can connect to the database.

  1. Check the database permissions: Verify that the ‘root’ user has the permissions to access the specified database you’re trying to connect to. You can do this by running the following command:

SHOW GRANTS FOR ‘root’@’localhost’;

This will show you the privileges assigned to the ‘root’ user on the ‘localhost’ host.

  1. Restart the MySQL/MariaDB server: If all else fails, try restarting the MySQL/MariaDB server. Sometimes, configuration changes do not take effect until the server is restarted.

– Check the Firewall

If you are connecting to the MySQL/MariaDB server from a remote machine, make sure that the server’s firewall is not blocking the connection. To resolve this error, you can follow these steps:

  1. Check your Firewall settings: Ensure your firewall is not blocking the MySQL port (the default port number is 3306). You can check this by opening your Firewall settings and verifying that port 3306 is open.
  2. Check MySQL privileges: You can check the privileges of the user ‘root’@’localhost’ by logging in as another user with administrative permissions and running the following command:

SHOW GRANTS FOR ‘root’@’localhost’;

This will display a list of privileges granted to the ‘root’ user. If the user does not have enough privileges, you can grant them by running the following command:

GRANT ALL PRIVILEGES ON *.* TO ‘root’@’localhost’ WITH GRANT OPTION;

  1. Restart MySQL service: After making any changes to the MySQL privileges, you should restart the MySQL service to ensure that the changes take effect.

Sudo systemctl restart mysql

  1. Test MySQL access: After completing the above steps, you can test whether the ‘root’ user has access to MySQL by logging in with the following command:

If you can log in without any errors, it means that the issue has been resolved.

– Use a Different User Account

Try logging in with a separate user account that has the privileges to access the database server. You can make a new account by using the following command:

CREATE USER ‘username’@’localhost’ IDENTIFIED BY ‘password’;

GRANT ALL PRIVILEGES ON *.* TO ‘username’@’localhost’ WITH GRANT OPTION;

– Grant MySQL Access

MySQL Access refers to the ability to interact with a MySQL database using various means, such as through the command line, graphical user interfaces (GUIs), or application programming interfaces (APIs). Granting access will resolve your error message issue.

MySQL Access generally allows users to perform various operations on a MySQL database, such as creating and modifying tables, inserting and updating data, querying data, and managing users and permissions. MySQL Access can be granted to different users with different levels of privileges, depending on their roles and responsibilities.

MySQL Access can be performed using various tools, such as the MySQL command line client, phpMyAdmin, MySQL Workbench, and many other third-party applications and libraries.

– Correct Typo Mistake

If the user makes a typo or a syntax mistake, they can face this error message. Therefore, it is important to find all the syntax and typo mistakes to correct them. You can also get rid of other error messages, such as:

  • Error 1045 (28000): Access denied for user ‘zabbix’@’localhost’ (using password: yes)
  • db.utils.operationalerror: (1698, denied
  • Error 1045 (28000): Access denied for user nextcloud localhost’ (using password: yes)
  • Mysql root error 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: yes)

Conclusion

After reading the guide completely, you can understand how this error arises and what you can do to resolve it by using the various methods discussed here. Let’s see some major takeaways from this article.

  • This error arises when the user does not have the necessary privileges to access or modify the database.
  • It is important to note that the root user has full privileges in MySQL, and it is recommended to create a new user with restricted privileges for security purposes.
  • To resolve the error, the user can either grant the necessary privileges to the root user or create a new user with the appropriate privileges.
  • Ensure that the correct username and password are being used to access the MySQL database.
  • In some cases, the error may be caused by other factors, like incorrect configuration settings or firewall restrictions.

You can resolve this issue on your own by using this article as a guide. Thank you for reading!

  • Author
  • Recent Posts

Position is Everything

Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL. Meet The Team

Position is Everything

11.06.2019

В сегодняшней статье разберемся как устранить ошибку:

#1698 – Access denied for user ‘root'@'localhost'

при попытке подключиться к БД из под root.

MySQL 5.7 изменила модель безопасности: теперь вход в MySQL под рутом (root) требует sudo (при этом пароль всё равно может быть пустым). Т.е. phpMyAdmin невозможно использовать под пользователем root.

Самым простым (и самым безопасным) решением будет создать нового пользователя и предоставить ему требуемые привилегии.

Но начнём мы с другого решения:


Разрешить пользователю root подключаться к MySQL без sudo

  1. 1.
    Разрешить пользователю root подключаться к MySQL без sudo

  2. 2.
    Создание нового пользователя

Для получения доступа к базе данных MySQL/MariaDB обычному пользователю без использования sudo привилегий, зайдите в приглашение командной строки MySQL

sudo mysql

и запустите следующие команды:

use mysql;
update user set plugin='' where User='root';
flush privileges;
exit

Или так:

use mysql;
UPDATE mysql.user SET authentication_string = PASSWORD('12345') WHERE User = 'root' AND Host = 'localhost';
update user set plugin='mysql_native_password' where User='root';
flush privileges;
exit

Затем перезапустите службу MySQL и попробуйте войти в базу данных без sudo, как показано ниже.

sudo systemctl restart mysql.service
mysql -u root -p

Создание нового пользователя

Подключитесь к mysql

sudo mysql --user=root mysql

Создайте нового пользователя с правами root

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
exit

После этого можете войти под новым пользователем (myuser) в вашу базу данных с правами как у root.

Если есть вопросы, то пишем в комментариях.

Также можете вступить в Телеграм канал, ВКонтакте или подписаться на Twitter. Ссылки в шапке страницы.
Заранее всем спасибо!!!

Если вы нашли ошибку, пожалуйста, выделите фрагмент текста и нажмите Ctrl+Enter.

3.7
3
голоса

Рейтинг статьи

How to Fix mysqli_real_connect(): (HY000/1698): Access denied for user ‘root’@'localhost' Error

Most of the time, this error comes because the “root” account of MySQL is set only to allow Unix Socket based authentication. So, enter the following commands using a terminal to change its authentication plugin either to Caching SHA-2 or Native authentication.

Login to MySQL CLI.

First, we need to make sure that the root account uses the auth_socket plugin, for that run the following command.

SELECT host,user,authentication_string,plugin FROM mysql.user;

It should display something similar to this. Look at the plugin used by the root account, it should be auth_socket.

+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | debian-sys-maint | $A$005$:\ddQ82h3oaB1+gf0FF.Uq5Gkaj3cVHbEWusZIIpJEBigM17KwLcFDcv6Z2zJ20 | caching_sha2_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | phpmyadmin       | $A$005$7.sK5b2|eI*r%2pnFO7wtVj57sqt54wR8FA3gsj6LEvvahn64BgPSD6Y5IyjzX8 | caching_sha2_password |
| localhost | root             |                                                                        | auth_socket           |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+

Then run the following command to change the authentication plugin to Caching SHA-2 authentication.

ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '';

Alternatively, you can use Native authentication as well, but use either.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

Run this command to reload and apply changes.

Again confirm whether changes have been successfully applied or not by running this command.

SELECT host,user,authentication_string,plugin FROM mysql.user;

You should be able to see something similar to this,

+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | debian-sys-maint | $A$005$:\ddQ82h3oaB1+gf0FF.Uq5Gkaj3cVHbEWusZIIpJEBigM17KwLcFDcv6Z2zJ20 | caching_sha2_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | phpmyadmin       | $A$005$7.sK5b2|eI*r%2pnFO7wtVj57sqt54wR8FA3gsj6LEvvahn64BgPSD6Y5IyjzX8 | caching_sha2_password |
| localhost | root             |                                                                        | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+

Now you can exit from MySQL CLI.

Now you should be able to log in to the MySQL server with the ‘root’ account, the password will be blank. If you need to set a password, add it like this.

ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'super-secret-password';

Понравилась статья? Поделить с друзьями:
  • Ошибка 1700 принтера canon pixma g2400
  • Ошибка 1692 при включении компьютера леново
  • Ошибка 1696 камаз камминз цепь питания датчиков 5
  • Ошибка 1700 принтера canon mg2540s
  • Ошибка 171 шкода фабия