Reputation:
I am on linux and I have never installed a database management system but when I type in the terminal mysql --version
I get mysql Ver 15.1 Distrib 10.1.26-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
.
I can connect to the database without a password when I type mysql
without any password.
Meanwhile, I installed Adminer and I would like to use it alternatively phpmyadmin to manage my database but I can not connect myself I receive the following error in my browser Access denied for user 'root' @ 'localhost'
.
I try all the methods found on google google to create a root password but I can not.
I tried the solutions proposed here:
And many oder link.
How can I set a root password for mysql to use it in Adminer
Upvotes: 8
Views: 19003
Reputation: 81
I followed this Link. The initial Mysql Setup didnt work, so I did a password reset. Mysql Version 5.7.38:
Warning: During this operation your anyone can access your MYSQL Server without password!
(was optional in MySql 8 installation):
$> sudo nano /etc/mysql/my.cnf
[mysqld] # add if not present
skip-grant-tables # add line
(optional End)
$> sudo mysql restart && mysql #should login with user root without password
mysql> USE mysql;
mysql> UPDATE user SET authentication_string=PASSWORD("YourNewPassword") WHERE user='root';
In MySql 8 only change the last line to:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'my password';
The following SQL was important: (optional mysql 8)
mysql> UPDATE user set plugin="mysql_native_password" where user='root';
mysql> FLUSH privileges;
mysql> QUIT;
sudo nano /etc/mysql/my.cnf
skip-grant-tables #remove line
Now mysql root login works without sudo with your Password
$> mysql -u root -p
Upvotes: 2
Reputation: 314
If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To set up a root password for the first time, use the mysqladmin command at the shell prompt as follows:
mysqladmin -u root password newpass
Upvotes: 8