Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set password error in MySQL

Tags:

mysql

I am trying to reset my root password using following command:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('test');

and it gives me following error:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PASSWORD('test')' at line 1

Please let me know what is it that I am doing wrong here.

like image 288
ddesai Avatar asked Apr 25 '15 14:04

ddesai


People also ask

How can I set password in MySQL?

In the mysql client, tell the server to reload the grant tables so that account-management statements work: mysql> FLUSH PRIVILEGES; Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use.

How do I find MySQL password?

In order to recover the password, you simply have to follow these steps: Stop the MySQL server process with the command sudo service mysql stop. Start the MySQL server with the command sudo mysqld_safe –skip-grant-tables –skip-networking & Connect to the MySQL server as the root user with the command mysql -u root.

What is default password for MySQL?

The default user for MySQL is root and by default it has no password. If you set a password for MySQL and you can't recall it, you can always reset it and choose another one.

How set MySQL root password?

Configuring a default root password for MySQL/MariaDB Use the following procedure to set a root password. To change the root password, type the following at the MySQL/MariaDB command prompt: ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyN3wP4ssw0rd'; flush privileges; exit; Store the new password in a secure location.


2 Answers

I know it is old but it can help.

I hade this error when i used PASSWORD() function:

SET PASSWORD FOR 'myuser@localhost' = PASSWORD('my_new_password');

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PASSWORD('basket8')' at line 1

Because in MySQL 5.7 and later it is not necessary to use the PASSWORD() function:

SET PASSWORD FOR 'myuser'@'localhost' = 'my_new_password';
Query OK, 0 rows affected (0.01 sec)
like image 137
Yacine Rouizi Avatar answered Nov 15 '22 16:11

Yacine Rouizi


You do not need to quote the user name and it should be as

mysql> set password for root@'localhost' = password('test');
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)

The other way of re-setting the password is Login to mysql as root and then update the mysql database User table

abhik@-N4010:~$ mysql -u root -p
Enter password: 

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set Password = password('test') where host='localhost' and User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
like image 37
Abhik Chakraborty Avatar answered Nov 15 '22 16:11

Abhik Chakraborty