MariaDB installed without password prompt - mysql

I've installed mariadb from Ubuntu 15.04 repositories using the Ubuntu software center or at the command prompt (apt-get install maraidb-server), but no password is asked for root user.
Now I'm able to connect to mysql on command line without password, but connecting using Mysql-Workbench or python mysqldb library failed with the "Access denied for user 'root'#'localhost'" message

Starting with MariaDB 10.4 root#localhost account is created with the ability to use two authentication plugins:
First, it is configured to try to use the unix_socket authentication plugin. This allows the root#localhost user to login without a password via the local Unix socket file defined by the socket system variable, as long as the login is attempted from a process owned by the operating system root user account.
Second, if authentication fails with the unix_socket authentication plugin, then it is configured to try to use the mysql_native_password authentication plugin. However, an invalid password is initially set, so in order to authenticate this way, a password must be set with SET PASSWORD.
That is why you don't need a password to login on a fresh install.
But then another quote:
When the plugin column is empty, MariaDB defaults to authenticating accounts with either the mysql_native_password or the mysql_old_password plugins. It decides which based on the hash used in the value for the Password column. When there's no password set or when the 4.1 password hash is used, (which is 41 characters long), MariaDB uses the mysql_native_password plugin. The mysql_old_password plugin is used with pre-4.1 password hashes, (which are 16 characters long).
So setting plugin = '' will force it to use password based authentication. Make sure you set a password before that.
sudo mysql -u root
[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q

sudo mysql -u root
[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q
This needs to be followed by following command
# mysql_secure_installation

it is common for root to have password-less access if accessing from localhost, I recommend this setting to be left alone.
I also recommend that you create a user with less permissions and allow that user to login remotely.
create user my_admin identified by '12345';
create database my_database;
grant all on my_database.* to my_admin;
This way you have a little more security.
If you do need to connect as root from a tool like workbench, you can configure those tools to create an ssh tunnel and connect to the database as localhost.

As #Pedru noticed, the "Access denied for user 'root'#'localhost'" message is due to the fact that Debian and Ubuntu enable the UNIX_SOCKET Authentication Plugin plugin by default, allowing passwordless login (See also Authentication Plugin - Unix Socket). This is not an installation problem.
It means that if you type mysql -u root -p in the Linux Shell, root is actually the Linux root (or linked to it, I don't know how this actually works). So that if you logged on Linux with another account, you will get an error:
ERROR 1698 (28000): Access denied for user 'root'#'localhost'. Better type sudo mysql -u root -p or sudo mysql -u root if the password is not yet defined.

If you want to switch to the mysql_native_password authentication plugin, then you could use
ALTER USER root#localhost IDENTIFIED VIA mysql_native_password;
SET PASSWORD = PASSWORD('new_password');
For further information see
https://mariadb.com/kb/en/authentication-plugin-unix-socket/

For a MariaDB version greater than or equals to 10.2.0, the response of user3054067 is correct.
For a MariaDB version less than 10.2.0, you can do this :
me$ sudo su -
root$ mysql -u root
MariaDB [(none)]> SET PASSWORD FOR 'root'#'localhost' = PASSWORD('new_password');
Query OK, 0 rows affected, 1 warning (0.00 sec)
MariaDB [(none)]> UPDATE mysql.user SET plugin='mysql_native_password' WHERE User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
In another terminal,
me$ mysql -u root -pnew_password
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 83
Server version: 10.0.38-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

Related

MySql -u root -p not working on new computer [duplicate]

I'm trying to run WordPress in my Windows desktop and it needs MySQL.
I install everything with Web Platform Installer which is provided by Microsoft. I never set a root password for MySQL and in the final step of installing WordPress, it asks for a MySQL server password.
What is the default password for root (if there is one) and how to change it?
I tried:
mysql -u root password '123'
But it shows me:
Access denied for user 'root#localhost' (using password:NO)
After this I try:
mysql -u root -p
However, it asks for a password which I don't have.
Update: as Bozho suggested, I did the following:
I stopped the MySQL Service from Windows services
Opened CMD
Changed the location to c:\program files\mysql\bin
Executed the command below
mysqld --defaults-file="C:\\program files\\mysql\\mysql server 5.1\\my.ini" --init-files=C:\\root.txt
The command ran with a warning about character set which I mentioned below
I start the MySQL service from Windows services
I write in the command line
mysql -u root -p
EnterPassword: 123 // 123 was the password
The command line shows the following error
Access denied for user 'root#localhost' (using password:**YES**)
How do I solve this?
for this kind of error; you just have to set new password to the root user as an admin. follow the steps as follows:
[root ~]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password:NO)
Stop the service/daemon of mysql running
[root ~]# service mysql stop
mysql stop/waiting
Start mysql without any privileges using the following option;
This option is used to boot up and do not use the privilege system of MySQL.
[root ~]# mysqld_safe --skip-grant-tables &
At this moment, the terminal will seem to halt. Let that be, and use new terminal for next steps.
enter the mysql command prompt
[root ~]# mysql -u root
mysql>
Fix the permission setting of the root user ;
mysql> use mysql;
Database changed
mysql> select * from user;
Empty set (0.00 sec)
mysql> truncate table user;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to root#localhost identified by 'YourNewPassword' with grant option;
Query OK, 0 rows affected (0.01 sec)
*if you don`t want any password or rather an empty password
mysql> grant all privileges on *.* to root#localhost identified by '' with grant option;
Query OK, 0 rows affected (0.01 sec)*
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Confirm the results:
mysql> select host, user from user;
+-----------+------+
| host | user |
+-----------+------+
| localhost | root |
+-----------+------+
1 row in set (0.00 sec)
Exit the shell and restart mysql in normal mode.
mysql> quit;
[root ~]# kill -KILL [PID of mysqld_safe]
[root ~]# kill -KILL [PID of mysqld]
[root ~]# service mysql start
Now you can successfully login as root user with the password you set
[root ~]# mysql -u root -pYourNewPassword
mysql>
You can reset your root password. Have in mind that it is not advisable to use root without password.
1) You can set root password by invoking MySQL console. It is located in
C:\wamp\bin\mysql\mysql5.1.53\bin by default.
Get to the directory and type MySQL. then set the password as follows..
> SET PASSWORD FOR root#localhost = PASSWORD('new-password');
2) You can configure wamp's phpmyadmin application for root user by editing
C:\wamp\apps\phpmyadmin3.3.9\config.inc.php
Note :- if you are using xampp then , file will be located at
C:\xampp\phpMyadmin\config.inc.php
It looks like this:
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'YOURPASSWORD';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
The error "Access denied for user 'root#localhost' (using password:NO)"
will be resolved when you set $cfg['Servers'][$i]['AllowNoPassword'] to false
If you priviously changed the password for 'root#localhost', then you have to do 2 things to solve the error "Access denided for user 'root#localhost'":
if ['password'] have a empty quotes like ' ' then put your password between quotes.
change the (using password:NO) to (using password:YES)
This will resolve the error.
Note: phpmyadmin is a separate tool which comes with wamp.
It just provide a interface to MySQL. if you change my sql root's password, then you should change the phpmyadmin configurations. Usually phpmyadmin is configured to root user.
Use mysql -u root -p
It will ask for password, insert password and enter.
I was getting the same error on OS X El captain.
Mysql version 5.7 . I was able to connect to mysql with root after executing these steps.
Stop the mysql server
sudo mysql.server stop
Start mysql in safe mode
sudo mysqld_safe --skip-grant-tables
Using mysqld, Change the database to mysql and update the details for user 'root'.
show databases;
use mysql;
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
exit;
After that kill the 'mysqld_safe' process and start mysql normally. You should be able to login to mysql using root and new password. SQL docs for more details
Simply edit my.ini file in C:\xampp\mysql\bin path. Just add:
skip-grant-tables
line in between lines of # The MySQL server [mysqld] and port=3306. Then restart the MySQL server.
Looks like:
For some information I've get error after changing password:
Access denied for user 'root'#'localhost' (using password: NO)
Access denied for user 'root'#'localhost' (using password: YES)
In both cases there was error.
But the thing is after that I've tried it with
mysql -uroot -ppassword instead of
mysql -u root -p password -> with spaces between -uroot and -ppassword so maybe if someone get trouble can try this way.
Make sure the MySQL service is running on your machine, then follow the instructions from MySQL for initially setting up root (search for 'windows' and it will take you to the steps for setting up root):
Securing the Initial MySQL Account
Another solution if someone gets the error The specified password for user account ‘root’ is not valid, or failed to connect to the database server also with the right password, is the follow
•In the Windows registry, delete the mysql_pwd reg key under HKCU\Software\Microsoft\WebPlatformInstaller
•Unistall older version of MySQL .NET connector
•Download and install the latest MySql .NET Connector.
Change the password from config.inc.php present in C:\xampp\phpMyAdmin.
Type mysql -u root -p in the command prompt.
You will be asked to enter the password. Enter that password which you updated in the config.inc.php.
In your code replace the 'root' with your Server username and password with your server password.
For example if you have DB and your php files on the server http://www.example.com
then obviously you would have to enter into this server site using your username and password.
For MySQL 5.7. These are the below steps:
Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.
Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables
Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.
Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Enter mysql and press enter.
You should now have the MySQL command prompt working. Type use mysql; so that we switch to the "mysql" database.
Execute the following command to update the password:
update user set authentication_string=password('1111') where user='root';
Some times it just happens due to installation of Wamp or changing of password options of root user.
One can use privilages-->root (user) and then set password option to NO to run the things without any password OR set the password and use it in the application.
If you are using XAMPP just go to C:\xampp\phpMyAdmin and then open config.inc.php find $cfg['Servers'][$i]['password'] = '' line and put your password there.
if you changed the port to non standard one, then you need to specify it:
$connection = mysqli_connect('localhost:3308', 'root', '', 'loginapp');
If the root account exists but has no password, connect to the server as root using no password, then assign a password. This was my situation when I encountered this issue.
Connect to the server as root using no password:
$> mysql -u root --skip-password
Assign a password:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'root-password';
I was able to solve my problem this way. Hope this helps someone who encounters a similar issue in the future. Cheers!
Reference: https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html
mysqladmin -u root -p password
enter your current password
then
enter your new password
It happens because of the security reason.
try with the following
mysql -u root -p
click enter and enter the password and try again

MySQL: Ownership of mysql directory changes to 'mysql' from 'service_account' on linux server reboot

I'm using MySQL distribution 10.2.39-MariaDB, for Linux (x86_64). It runs fine when we initially start it up and manually configure it to correct ownership and startup. But whenever we reboot the Linux server, the ownership of '/var/lib/mysql' changes from 'service_account' to 'mysql', as shown below:
Before reboot of Linux Server
drwxr-xr-x. service_account service-account_grp 4096 Mar 18 14:00 mysql
to
After reboot of Linux Server
drwxr-xr-x. mysql mysql 4096 Mar 18 14:00 mysql
It changes ownership itself and I don't happen to find the root cause for it.
I've been facing this issue and I'm not able to find a solution to it.
Any input is appreciated.
Thanks in advance,
Sid
I'm writing this answer because I think we both have misunderstood the User Account Management mechanisms of mariadb. I have also encountered the same problem as you, so I'm writing this answer for myself somewhat. You can follow this answer or danblack's, whichever you actually need. As danblack said, it may not be a good idea to change "mysql" to your service_account.
Initialize mariadb database directory with 'mysql' user account :
$ sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
...
Two all-privilege accounts were created.
One is root#localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql#localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo
...
As you can see, two mariadb all-privilege accounts, root#localhost and mysql#localhost, were created. And you must be operating system root and mysql user to use these two mariadb accounts, respectively.
After then, enable and start mariadb server :
$ sudo systemctl enable --now mariadb.service
You may want to use mysql_secure_installation command to improve the initial security.
Then use mariadb root#localhost account with system root account to connect to sever, and create new mariadb account that has root-like privileges with whatever name you want:
$ sudo mysql -u root -p # first input your passwd to use 'sudo', then [ENTER] for empty mariadb root account passwd
[sudo] password for your_service_account:
Enter password:
...
MariaDB [(none)]> CREATE USER 'whatever_name_you_want'#'localhost' IDENTIFIED BY 'somepasswd';
Query OK, 0 rows affected (0.004 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* to 'whatever_name_you_want'#'localhost';
Query OK, 0 rows affected (0.004 sec)
MariaDB [(none)]> quit
Bye
Use new unprivileged whatever_name_you_want#localhost account to connect to server and create a new database :
$ mysql -u whatever_name_you_want -p
Enter password:
...
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS mydb;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> quit
Bye
And if you set password for root#localhost account, you can even use this account without sudo :
$ sudo mysql -u root -p
[sudo] password for your_service_account:
Enter password:
...
MariaDB [(none)]> SET PASSWORD FOR 'root'#'localhost' = PASSWORD('somepasswd');
Query OK, 0 rows affected (0.041 sec)
MariaDB [(none)]> quit
Bye
$ mysql -u root -p
Enter password:
...
MariaDB [(none)]> quit
Bye

mysql error : ERROR 1045 (28000): Access denied for user [duplicate]

I'm trying to run WordPress in my Windows desktop and it needs MySQL.
I install everything with Web Platform Installer which is provided by Microsoft. I never set a root password for MySQL and in the final step of installing WordPress, it asks for a MySQL server password.
What is the default password for root (if there is one) and how to change it?
I tried:
mysql -u root password '123'
But it shows me:
Access denied for user 'root#localhost' (using password:NO)
After this I try:
mysql -u root -p
However, it asks for a password which I don't have.
Update: as Bozho suggested, I did the following:
I stopped the MySQL Service from Windows services
Opened CMD
Changed the location to c:\program files\mysql\bin
Executed the command below
mysqld --defaults-file="C:\\program files\\mysql\\mysql server 5.1\\my.ini" --init-files=C:\\root.txt
The command ran with a warning about character set which I mentioned below
I start the MySQL service from Windows services
I write in the command line
mysql -u root -p
EnterPassword: 123 // 123 was the password
The command line shows the following error
Access denied for user 'root#localhost' (using password:**YES**)
How do I solve this?
for this kind of error; you just have to set new password to the root user as an admin. follow the steps as follows:
[root ~]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password:NO)
Stop the service/daemon of mysql running
[root ~]# service mysql stop
mysql stop/waiting
Start mysql without any privileges using the following option;
This option is used to boot up and do not use the privilege system of MySQL.
[root ~]# mysqld_safe --skip-grant-tables &
At this moment, the terminal will seem to halt. Let that be, and use new terminal for next steps.
enter the mysql command prompt
[root ~]# mysql -u root
mysql>
Fix the permission setting of the root user ;
mysql> use mysql;
Database changed
mysql> select * from user;
Empty set (0.00 sec)
mysql> truncate table user;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to root#localhost identified by 'YourNewPassword' with grant option;
Query OK, 0 rows affected (0.01 sec)
*if you don`t want any password or rather an empty password
mysql> grant all privileges on *.* to root#localhost identified by '' with grant option;
Query OK, 0 rows affected (0.01 sec)*
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Confirm the results:
mysql> select host, user from user;
+-----------+------+
| host | user |
+-----------+------+
| localhost | root |
+-----------+------+
1 row in set (0.00 sec)
Exit the shell and restart mysql in normal mode.
mysql> quit;
[root ~]# kill -KILL [PID of mysqld_safe]
[root ~]# kill -KILL [PID of mysqld]
[root ~]# service mysql start
Now you can successfully login as root user with the password you set
[root ~]# mysql -u root -pYourNewPassword
mysql>
You can reset your root password. Have in mind that it is not advisable to use root without password.
1) You can set root password by invoking MySQL console. It is located in
C:\wamp\bin\mysql\mysql5.1.53\bin by default.
Get to the directory and type MySQL. then set the password as follows..
> SET PASSWORD FOR root#localhost = PASSWORD('new-password');
2) You can configure wamp's phpmyadmin application for root user by editing
C:\wamp\apps\phpmyadmin3.3.9\config.inc.php
Note :- if you are using xampp then , file will be located at
C:\xampp\phpMyadmin\config.inc.php
It looks like this:
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'YOURPASSWORD';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
The error "Access denied for user 'root#localhost' (using password:NO)"
will be resolved when you set $cfg['Servers'][$i]['AllowNoPassword'] to false
If you priviously changed the password for 'root#localhost', then you have to do 2 things to solve the error "Access denided for user 'root#localhost'":
if ['password'] have a empty quotes like ' ' then put your password between quotes.
change the (using password:NO) to (using password:YES)
This will resolve the error.
Note: phpmyadmin is a separate tool which comes with wamp.
It just provide a interface to MySQL. if you change my sql root's password, then you should change the phpmyadmin configurations. Usually phpmyadmin is configured to root user.
Use mysql -u root -p
It will ask for password, insert password and enter.
I was getting the same error on OS X El captain.
Mysql version 5.7 . I was able to connect to mysql with root after executing these steps.
Stop the mysql server
sudo mysql.server stop
Start mysql in safe mode
sudo mysqld_safe --skip-grant-tables
Using mysqld, Change the database to mysql and update the details for user 'root'.
show databases;
use mysql;
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
exit;
After that kill the 'mysqld_safe' process and start mysql normally. You should be able to login to mysql using root and new password. SQL docs for more details
Simply edit my.ini file in C:\xampp\mysql\bin path. Just add:
skip-grant-tables
line in between lines of # The MySQL server [mysqld] and port=3306. Then restart the MySQL server.
Looks like:
For some information I've get error after changing password:
Access denied for user 'root'#'localhost' (using password: NO)
Access denied for user 'root'#'localhost' (using password: YES)
In both cases there was error.
But the thing is after that I've tried it with
mysql -uroot -ppassword instead of
mysql -u root -p password -> with spaces between -uroot and -ppassword so maybe if someone get trouble can try this way.
Make sure the MySQL service is running on your machine, then follow the instructions from MySQL for initially setting up root (search for 'windows' and it will take you to the steps for setting up root):
Securing the Initial MySQL Account
Another solution if someone gets the error The specified password for user account ‘root’ is not valid, or failed to connect to the database server also with the right password, is the follow
•In the Windows registry, delete the mysql_pwd reg key under HKCU\Software\Microsoft\WebPlatformInstaller
•Unistall older version of MySQL .NET connector
•Download and install the latest MySql .NET Connector.
Change the password from config.inc.php present in C:\xampp\phpMyAdmin.
Type mysql -u root -p in the command prompt.
You will be asked to enter the password. Enter that password which you updated in the config.inc.php.
In your code replace the 'root' with your Server username and password with your server password.
For example if you have DB and your php files on the server http://www.example.com
then obviously you would have to enter into this server site using your username and password.
For MySQL 5.7. These are the below steps:
Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.
Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables
Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.
Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Enter mysql and press enter.
You should now have the MySQL command prompt working. Type use mysql; so that we switch to the "mysql" database.
Execute the following command to update the password:
update user set authentication_string=password('1111') where user='root';
Some times it just happens due to installation of Wamp or changing of password options of root user.
One can use privilages-->root (user) and then set password option to NO to run the things without any password OR set the password and use it in the application.
If you are using XAMPP just go to C:\xampp\phpMyAdmin and then open config.inc.php find $cfg['Servers'][$i]['password'] = '' line and put your password there.
if you changed the port to non standard one, then you need to specify it:
$connection = mysqli_connect('localhost:3308', 'root', '', 'loginapp');
If the root account exists but has no password, connect to the server as root using no password, then assign a password. This was my situation when I encountered this issue.
Connect to the server as root using no password:
$> mysql -u root --skip-password
Assign a password:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'root-password';
I was able to solve my problem this way. Hope this helps someone who encounters a similar issue in the future. Cheers!
Reference: https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html
mysqladmin -u root -p password
enter your current password
then
enter your new password
It happens because of the security reason.
try with the following
mysql -u root -p
click enter and enter the password and try again

Get error Access denied for user 'root'#'localhost' (using password: NO) when setting Wordpress on amazon ec2 [duplicate]

I'm trying to run WordPress in my Windows desktop and it needs MySQL.
I install everything with Web Platform Installer which is provided by Microsoft. I never set a root password for MySQL and in the final step of installing WordPress, it asks for a MySQL server password.
What is the default password for root (if there is one) and how to change it?
I tried:
mysql -u root password '123'
But it shows me:
Access denied for user 'root#localhost' (using password:NO)
After this I try:
mysql -u root -p
However, it asks for a password which I don't have.
Update: as Bozho suggested, I did the following:
I stopped the MySQL Service from Windows services
Opened CMD
Changed the location to c:\program files\mysql\bin
Executed the command below
mysqld --defaults-file="C:\\program files\\mysql\\mysql server 5.1\\my.ini" --init-files=C:\\root.txt
The command ran with a warning about character set which I mentioned below
I start the MySQL service from Windows services
I write in the command line
mysql -u root -p
EnterPassword: 123 // 123 was the password
The command line shows the following error
Access denied for user 'root#localhost' (using password:**YES**)
How do I solve this?
for this kind of error; you just have to set new password to the root user as an admin. follow the steps as follows:
[root ~]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password:NO)
Stop the service/daemon of mysql running
[root ~]# service mysql stop
mysql stop/waiting
Start mysql without any privileges using the following option;
This option is used to boot up and do not use the privilege system of MySQL.
[root ~]# mysqld_safe --skip-grant-tables &
At this moment, the terminal will seem to halt. Let that be, and use new terminal for next steps.
enter the mysql command prompt
[root ~]# mysql -u root
mysql>
Fix the permission setting of the root user ;
mysql> use mysql;
Database changed
mysql> select * from user;
Empty set (0.00 sec)
mysql> truncate table user;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to root#localhost identified by 'YourNewPassword' with grant option;
Query OK, 0 rows affected (0.01 sec)
*if you don`t want any password or rather an empty password
mysql> grant all privileges on *.* to root#localhost identified by '' with grant option;
Query OK, 0 rows affected (0.01 sec)*
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Confirm the results:
mysql> select host, user from user;
+-----------+------+
| host | user |
+-----------+------+
| localhost | root |
+-----------+------+
1 row in set (0.00 sec)
Exit the shell and restart mysql in normal mode.
mysql> quit;
[root ~]# kill -KILL [PID of mysqld_safe]
[root ~]# kill -KILL [PID of mysqld]
[root ~]# service mysql start
Now you can successfully login as root user with the password you set
[root ~]# mysql -u root -pYourNewPassword
mysql>
You can reset your root password. Have in mind that it is not advisable to use root without password.
1) You can set root password by invoking MySQL console. It is located in
C:\wamp\bin\mysql\mysql5.1.53\bin by default.
Get to the directory and type MySQL. then set the password as follows..
> SET PASSWORD FOR root#localhost = PASSWORD('new-password');
2) You can configure wamp's phpmyadmin application for root user by editing
C:\wamp\apps\phpmyadmin3.3.9\config.inc.php
Note :- if you are using xampp then , file will be located at
C:\xampp\phpMyadmin\config.inc.php
It looks like this:
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'YOURPASSWORD';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
The error "Access denied for user 'root#localhost' (using password:NO)"
will be resolved when you set $cfg['Servers'][$i]['AllowNoPassword'] to false
If you priviously changed the password for 'root#localhost', then you have to do 2 things to solve the error "Access denided for user 'root#localhost'":
if ['password'] have a empty quotes like ' ' then put your password between quotes.
change the (using password:NO) to (using password:YES)
This will resolve the error.
Note: phpmyadmin is a separate tool which comes with wamp.
It just provide a interface to MySQL. if you change my sql root's password, then you should change the phpmyadmin configurations. Usually phpmyadmin is configured to root user.
Use mysql -u root -p
It will ask for password, insert password and enter.
I was getting the same error on OS X El captain.
Mysql version 5.7 . I was able to connect to mysql with root after executing these steps.
Stop the mysql server
sudo mysql.server stop
Start mysql in safe mode
sudo mysqld_safe --skip-grant-tables
Using mysqld, Change the database to mysql and update the details for user 'root'.
show databases;
use mysql;
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
exit;
After that kill the 'mysqld_safe' process and start mysql normally. You should be able to login to mysql using root and new password. SQL docs for more details
Simply edit my.ini file in C:\xampp\mysql\bin path. Just add:
skip-grant-tables
line in between lines of # The MySQL server [mysqld] and port=3306. Then restart the MySQL server.
Looks like:
For some information I've get error after changing password:
Access denied for user 'root'#'localhost' (using password: NO)
Access denied for user 'root'#'localhost' (using password: YES)
In both cases there was error.
But the thing is after that I've tried it with
mysql -uroot -ppassword instead of
mysql -u root -p password -> with spaces between -uroot and -ppassword so maybe if someone get trouble can try this way.
Make sure the MySQL service is running on your machine, then follow the instructions from MySQL for initially setting up root (search for 'windows' and it will take you to the steps for setting up root):
Securing the Initial MySQL Account
Another solution if someone gets the error The specified password for user account ‘root’ is not valid, or failed to connect to the database server also with the right password, is the follow
•In the Windows registry, delete the mysql_pwd reg key under HKCU\Software\Microsoft\WebPlatformInstaller
•Unistall older version of MySQL .NET connector
•Download and install the latest MySql .NET Connector.
Change the password from config.inc.php present in C:\xampp\phpMyAdmin.
Type mysql -u root -p in the command prompt.
You will be asked to enter the password. Enter that password which you updated in the config.inc.php.
In your code replace the 'root' with your Server username and password with your server password.
For example if you have DB and your php files on the server http://www.example.com
then obviously you would have to enter into this server site using your username and password.
For MySQL 5.7. These are the below steps:
Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.
Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables
Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.
Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Enter mysql and press enter.
You should now have the MySQL command prompt working. Type use mysql; so that we switch to the "mysql" database.
Execute the following command to update the password:
update user set authentication_string=password('1111') where user='root';
Some times it just happens due to installation of Wamp or changing of password options of root user.
One can use privilages-->root (user) and then set password option to NO to run the things without any password OR set the password and use it in the application.
If you are using XAMPP just go to C:\xampp\phpMyAdmin and then open config.inc.php find $cfg['Servers'][$i]['password'] = '' line and put your password there.
if you changed the port to non standard one, then you need to specify it:
$connection = mysqli_connect('localhost:3308', 'root', '', 'loginapp');
If the root account exists but has no password, connect to the server as root using no password, then assign a password. This was my situation when I encountered this issue.
Connect to the server as root using no password:
$> mysql -u root --skip-password
Assign a password:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'root-password';
I was able to solve my problem this way. Hope this helps someone who encounters a similar issue in the future. Cheers!
Reference: https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html
mysqladmin -u root -p password
enter your current password
then
enter your new password
It happens because of the security reason.
try with the following
mysql -u root -p
click enter and enter the password and try again

Access denied for user 'root#localhost' (using password:NO)

I'm trying to run WordPress in my Windows desktop and it needs MySQL.
I install everything with Web Platform Installer which is provided by Microsoft. I never set a root password for MySQL and in the final step of installing WordPress, it asks for a MySQL server password.
What is the default password for root (if there is one) and how to change it?
I tried:
mysql -u root password '123'
But it shows me:
Access denied for user 'root#localhost' (using password:NO)
After this I try:
mysql -u root -p
However, it asks for a password which I don't have.
Update: as Bozho suggested, I did the following:
I stopped the MySQL Service from Windows services
Opened CMD
Changed the location to c:\program files\mysql\bin
Executed the command below
mysqld --defaults-file="C:\\program files\\mysql\\mysql server 5.1\\my.ini" --init-files=C:\\root.txt
The command ran with a warning about character set which I mentioned below
I start the MySQL service from Windows services
I write in the command line
mysql -u root -p
EnterPassword: 123 // 123 was the password
The command line shows the following error
Access denied for user 'root#localhost' (using password:**YES**)
How do I solve this?
for this kind of error; you just have to set new password to the root user as an admin. follow the steps as follows:
[root ~]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password:NO)
Stop the service/daemon of mysql running
[root ~]# service mysql stop
mysql stop/waiting
Start mysql without any privileges using the following option;
This option is used to boot up and do not use the privilege system of MySQL.
[root ~]# mysqld_safe --skip-grant-tables &
At this moment, the terminal will seem to halt. Let that be, and use new terminal for next steps.
enter the mysql command prompt
[root ~]# mysql -u root
mysql>
Fix the permission setting of the root user ;
mysql> use mysql;
Database changed
mysql> select * from user;
Empty set (0.00 sec)
mysql> truncate table user;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to root#localhost identified by 'YourNewPassword' with grant option;
Query OK, 0 rows affected (0.01 sec)
*if you don`t want any password or rather an empty password
mysql> grant all privileges on *.* to root#localhost identified by '' with grant option;
Query OK, 0 rows affected (0.01 sec)*
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Confirm the results:
mysql> select host, user from user;
+-----------+------+
| host | user |
+-----------+------+
| localhost | root |
+-----------+------+
1 row in set (0.00 sec)
Exit the shell and restart mysql in normal mode.
mysql> quit;
[root ~]# kill -KILL [PID of mysqld_safe]
[root ~]# kill -KILL [PID of mysqld]
[root ~]# service mysql start
Now you can successfully login as root user with the password you set
[root ~]# mysql -u root -pYourNewPassword
mysql>
You can reset your root password. Have in mind that it is not advisable to use root without password.
1) You can set root password by invoking MySQL console. It is located in
C:\wamp\bin\mysql\mysql5.1.53\bin by default.
Get to the directory and type MySQL. then set the password as follows..
> SET PASSWORD FOR root#localhost = PASSWORD('new-password');
2) You can configure wamp's phpmyadmin application for root user by editing
C:\wamp\apps\phpmyadmin3.3.9\config.inc.php
Note :- if you are using xampp then , file will be located at
C:\xampp\phpMyadmin\config.inc.php
It looks like this:
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'YOURPASSWORD';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
The error "Access denied for user 'root#localhost' (using password:NO)"
will be resolved when you set $cfg['Servers'][$i]['AllowNoPassword'] to false
If you priviously changed the password for 'root#localhost', then you have to do 2 things to solve the error "Access denided for user 'root#localhost'":
if ['password'] have a empty quotes like ' ' then put your password between quotes.
change the (using password:NO) to (using password:YES)
This will resolve the error.
Note: phpmyadmin is a separate tool which comes with wamp.
It just provide a interface to MySQL. if you change my sql root's password, then you should change the phpmyadmin configurations. Usually phpmyadmin is configured to root user.
Use mysql -u root -p
It will ask for password, insert password and enter.
I was getting the same error on OS X El captain.
Mysql version 5.7 . I was able to connect to mysql with root after executing these steps.
Stop the mysql server
sudo mysql.server stop
Start mysql in safe mode
sudo mysqld_safe --skip-grant-tables
Using mysqld, Change the database to mysql and update the details for user 'root'.
show databases;
use mysql;
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
exit;
After that kill the 'mysqld_safe' process and start mysql normally. You should be able to login to mysql using root and new password. SQL docs for more details
Simply edit my.ini file in C:\xampp\mysql\bin path. Just add:
skip-grant-tables
line in between lines of # The MySQL server [mysqld] and port=3306. Then restart the MySQL server.
Looks like:
For some information I've get error after changing password:
Access denied for user 'root'#'localhost' (using password: NO)
Access denied for user 'root'#'localhost' (using password: YES)
In both cases there was error.
But the thing is after that I've tried it with
mysql -uroot -ppassword instead of
mysql -u root -p password -> with spaces between -uroot and -ppassword so maybe if someone get trouble can try this way.
Make sure the MySQL service is running on your machine, then follow the instructions from MySQL for initially setting up root (search for 'windows' and it will take you to the steps for setting up root):
Securing the Initial MySQL Account
Another solution if someone gets the error The specified password for user account ‘root’ is not valid, or failed to connect to the database server also with the right password, is the follow
•In the Windows registry, delete the mysql_pwd reg key under HKCU\Software\Microsoft\WebPlatformInstaller
•Unistall older version of MySQL .NET connector
•Download and install the latest MySql .NET Connector.
Change the password from config.inc.php present in C:\xampp\phpMyAdmin.
Type mysql -u root -p in the command prompt.
You will be asked to enter the password. Enter that password which you updated in the config.inc.php.
In your code replace the 'root' with your Server username and password with your server password.
For example if you have DB and your php files on the server http://www.example.com
then obviously you would have to enter into this server site using your username and password.
For MySQL 5.7. These are the below steps:
Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.
Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables
Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.
Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Enter mysql and press enter.
You should now have the MySQL command prompt working. Type use mysql; so that we switch to the "mysql" database.
Execute the following command to update the password:
update user set authentication_string=password('1111') where user='root';
Some times it just happens due to installation of Wamp or changing of password options of root user.
One can use privilages-->root (user) and then set password option to NO to run the things without any password OR set the password and use it in the application.
If you are using XAMPP just go to C:\xampp\phpMyAdmin and then open config.inc.php find $cfg['Servers'][$i]['password'] = '' line and put your password there.
if you changed the port to non standard one, then you need to specify it:
$connection = mysqli_connect('localhost:3308', 'root', '', 'loginapp');
If the root account exists but has no password, connect to the server as root using no password, then assign a password. This was my situation when I encountered this issue.
Connect to the server as root using no password:
$> mysql -u root --skip-password
Assign a password:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'root-password';
I was able to solve my problem this way. Hope this helps someone who encounters a similar issue in the future. Cheers!
Reference: https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html
mysqladmin -u root -p password
enter your current password
then
enter your new password
It happens because of the security reason.
try with the following
mysql -u root -p
click enter and enter the password and try again