I'm currently setting a docker to run a mysql container on my computer. ( I'm a windows user, so I downloaded Docker Desktop, and installed wsl2 with ubuntu diro and it runs ).
The problem is the following : when I try to change the 'root' user password of my localhost, I see
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 'IDENTIFIED BY 'any-pwd' at line 1
Here is the command line I try to execute : mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'any-pwd';
I've been following this tutorial from the official mysql documentation : https://dev.mysql.com/doc/mysql-installation-excerpt/8.0/en/docker-mysql-getting-started.html
I also tried to "flush priviliege", but I'm still facing an error : You must SET PASSWORD before executing this statement, (I know, that's what I'm trying to do!)
But the "set password" seemed to be a sql piece of code so I tried the following :
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('password');
And you know what, it works! I had this problem because I use the docker mysql image with 5.6 tag, and so I got to use the last sql command, not the first.
Well there is no question, but I post it here if it can help someone one day!
Related
This question already has answers here:
MySQL: How to reset or change the MySQL root password?
(36 answers)
Closed 2 years ago.
This seems like a simple question but has caused me endless hours of frustration. It is only a small box inside the house that I am using for playing around.
I've tried the skip-grant-tables version and used the authentication_string field rather than the password version that is still knocking around. I've also tried the init-file method but no joy.
If I use the skip-grant-tables version and use the line:
update user set authentication_string=password('whywontitwork') where user='root';
The result I get is:
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 '('whywontitwork') where user='root'' at line 1
I don't understand (at all) what is wrong with the syntax. It is driving me mad for what should be a tiny little issue (I think). Does anybody have any ideas? Thanks in advance.
MySQL Ver 8.0.21-0ubuntu running on Ubuntu 20.04.
Function PASSWORD() is not working in MySql 8.0. You can use other encryption functions: LINK
How to reset root password in MySQL > 8.0: LINK
try with
ALTER USER 'root'#'localhost' IDENTIFIED BY 'NewPassword';
you can also create mysql-init file and apply this command by file
mysqld --init-file=/home/me/mysql-init &
I forgot the password for mysql, so i was trying to change it using following steps -
1) Stop Mysql server
2)Start server in safe mode by using sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
3) Open mysql command line using sudo /usr/local/mysql/bin/mysql -u root
4) Update password using UPDATE mysql.user SET authentication_string=PASSWORD('NewPassword') WHERE User='root';
But on this step i am getting the following error message -
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 '('NewPassword') WHERE User='root'' at line 1
Can someone tell how to resolve this error?
On 8.0.15 (maybe already before that version) the PASSWORD() function does not work, as mentioned in the comments below. You have to use:
UPDATE mysql.user SET authentication_string='password' WHERE User='root';
Original answer here
As problem states clearly, its incorrect syntax.
You should be using official MYSQL procedure to reset password, that includes create text file with command and then restarting the mysqld with text file input with mysqld --init-file=/home/me/mysql-init &' command.
Refer official root password reset options for unix [here][1].
[1]https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
I am using mysql version 8.0
From mysql cli I am trying to call the function PASSWORD. So I have used the following command :
mysql > select PASSWORD('123');
But I get the following error in this case :
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 '('123')' at line 1
I have also tries the following :
mysql > select PASSWORD("123");
mysql > select PASSWORD(`123`);
But each one give the same error. I have also googled a lot but could not find any solution for this.
How can I solve this
Regards,
Tanvir
As mysql documentation on the password() function says:
This function was removed in MySQL 8.0.11.
As mysql documentation says, you should use alter user statement to change the password:
ALTER USER syntax is the preferred statement for account alterations, including assigning passwords. For example:
ALTER USER user IDENTIFIED BY 'auth_string'
PASSWORD() was deprecated in 5.7 and removed in version 8. Far more secure ways of handling passwords are available, and you should consider using one.
Updating the ACL system tables directly (or any system tables for that matter) is not a very sustainable practice.
Why would you need to execute
UPDATE mysql.user SET password = hash('clear-text-password') WHERE host = 'foo' and user = 'bar'
followed by a FLUSH PRIVILEGES (!)
when you can just do:
ALTER USER foo#bar IDENTIFIED BY 'clear-text-password' ?
mysql -u root -paaum corpdb < /home/aaum/Videos/sp_getNOnAirDetails1.sql
ERROR 1064 (42000) at line 1: 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 '' at line 4
i think so there is some problem with my sql file
Try the commands as shown below :
Login into your mysql console and run :
mysql> use corpdb;
mysql> source /home/aaum/Videos/sp_getNOnAirDetails1.sql;
If your dump file is executed perfectly then the issue is not with the file.
It's about how you are trying to import the file.
The command which you have provided is absolutely fine. But I see that probably you might be executing the command from MySQL console.
mysql> mysql -u root -paaum corpdb < /home/aaum/Videos/sp_getNOnAirDetails1.sql
Not a right way to import, try to import the file from terminal.
If you still see any errors then please post them here.
i finally bugged the problem. i forget to assign delimeter .
I'm a MySQL/WAMP newbie attempting to set up timezones so that I could follow along with a course on the topic, but then I started having troubles when the instructions I was being given didn't correspond to the info on the MySQL page from which I was to download the setup file, http://dev.mysql.com/doc/refman/5.7/en/mysql-tzinfo-to-sql.html.
Can anyone tell me why, when I attempt to run this command from the mysql command prompt:
mysql -u root mysql < C:/timezone_posix.sql;
I get this 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 'mysql
BTW, I've tried that with both forward and backward slashes, with and without quotes, etc., from my WAMP 5.6.17, MySQL command prompt, and the file in question is the posix (not isam) version that corresponds to the MySQL version on a windows machine.
You should be running that from the regular command prompt, not inside the mysql program, since it runs the mysql program. So it should be at the C:\ prompt.
Or you could use the mysql source command to read from a file:
mysql> use mysql
mysql> source 'C:/timezone_posix.sql'