Sometimes a default password is set when you install it -as mentioned in docs. This can be confirmed by the following command.
sudo grep 'temporary password' /var/log/mysqld.log
Although a old one, I was getting the same error while setting up the mysql-8 zip
version. Finally, switched to installer
version which worked seamlessly. During installation, there is a prompt to setup the root
password. Once set, it works for sure.
Solution: Give up!
Hear me out, I spent about two whole days trying to make MySQL work to no avail, always stuck with permission errors, none of which were fixed by the answers in this thread. It got to the point that I thought if I continued I’d go insane.
Out of patience for making it work, I sent the command to install SQLite, only using 450KB, and it worked perfectly right from the word go.
If you don’t have the patience of a saint, go with SQLite and save yourself a lot of time, effort, pain, and storage space..!
Okay, I know this is an old thread but if you reached this page via Google like I did and none of the above solutions worked, what turned out to be the error was 100% foolishness on my end. I didn’t connect to the server. Once connected everything was smooth sailing.
In case it helps to know my setup, I’m using Sequel Pro and trying to connect to it with Node using the NPM package, mysql. I didn’t think I needed to actually connect (other than run Sequel Pro) because I was doing that from my app already.
The ‘-p’ argument doesn’t expect a space between the argument name and value.
Instead of
$ ./mysqladmin -u root -p 'redacted'
Use
$ ./mysqladmin -u root -p'redacted'
Or just
$ ./mysqladmin -u root -p
which will prompt you for a password.
According to Mariadb official documentation, in MariaDB 10.4.3 and later, the unix_socket
authentication plugin is installed by default.
In order to disable it, and revert to the previous mysql_native_password
authentication method, add line below in [mysqld]
section of my.cnf
file:
[mysqld]
unix_socket=OFF
and then run:
mysql_install_db --auth-root-authentication-method=normal
And then start mysqld
This command wil then work fine:
mysqladmin -u root password CHANGEME
For additional information, see https://mariadb.com/kb/en/authentication-from-mariadb-104/#configuring-mysql_install_db-to-revert-to-the-previous-authentication-method
It can happen if you don’t have enough privileges.
Type su
, enter root password and try again.
If you are like me and all the above suggestions failed, proceed to uninstall all versions of mysql on your machine, search for all remaining mysql files using this command sudo find / -name "mysql"
and rm -rf
every file or directory with the mysql name attached to it (you should skip files related to programming language libraries). Now install a fresh version of MySQL and enjoy. NB: You will loose all your data so weigh your options first.
In my case under Debian 10, the error
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
was solved by (GOOD WAY)
sudo mysql -u root -p mysql
BAD WAY:
mysql -u root -p mysql
Fix for Mac OS
-
Install MySQL from https://downloads.mysql.com/archives/community/ (8.x is latest as on date but ensure that the version is compatible with the Mac OS version)
-
Give password for
root
(let<root-password>
be the password) during installation (Don’t forget to remember the password!) -
Select Use Legacy Password Encryption option (that is what I had used and did not try for Use Strong Password Encryption option)
-
Search and open MySQL.prefPane (use search tool)
- Select Configuration tab
- Click Select option of Configuration File
- Select
/private/etc/my.cnf
- Select
-
From terminal open a new or existing file with name
/etc/my.cnf
(vi /etc/my.cnf
) add the following content:[mysqld] skip-grant-tables
-
Restart mysqld as follows:
ps aux | grep mysql
kill -9 <pid1> <pid2> ...
(grab pids of all mysql related processes)
-
mysqld
gets restarted automatically -
Verify that the option is set by running the following from terminal:
ps aux | grep mysql > mysql/bin/mysqld ... --defaults-file=/private/etc/my.cnf ... (output)
-
Run the following command to connect (let
mysql-<version>-macos<version>-x86_64
be the folder where mysql is installed. To grab the actual folder, runls /usr/local/
and copy the folder name):/usr/local/mysql-<version>-macos<version>-x86_64/bin/mysql -uroot -p<root-password>