Error on trying to change password in mysql - mysql

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

Related

SQL syntax error on first password setting (docker, wsl2)

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!

How to create the tables and import the data to sql in MariaDb? [duplicate]

This question already exists:
Why am I getting the error 1064 (42000) while importing using MariaDB/“mysql shell”?
Closed 5 years ago.
Whenever type mysql -u username [-p password] database_name < tatoeba_database.sql
I get
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'mys
ql -u root tatoeba < tatoeba_database.sql' at line 1
MariaDB [tatoeba]>
Is there another way to do such thing Am I missing something?
P.S. I'm following this article: https://github.com/Tatoeba/tatoeba2/wiki/How-to-install-Tatoeba
Remove [-p password]
mysql -u username -p database_name < tatoeba_database.sql
and enter the password manually
It appears that you type your command in MariaDB prompt (that is, you start mysql client first and then use the command above). It's incorrect. You either need to execute it from the shell prompt, or, if you want to start mysql client first, lose the whole thing and run instead
source tatoeba_database.sql

MySQL Set Password Via Command-Line Variable

I need a one-liner to provision users in my databases. I'm running MySQL 5.6. Here is what I'm setting the password as a variable so that I can pass it dynamically (obviously it won't always be 'password').
mysql_password="password"
mysql -u ted -e "SET PASSWORD FOR 'ted'#'localhost' = PASSWORD($mysql_password);"
I'm getting the following error when I run this:
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 'password)' at line 1
What is wrong with the statement? Can it be corrected or is another solution available so I accomplish this via Bash?
You need to surround the variable by single quotes:
mysql -u root -e "SET PASSWORD FOR 'ted'#'localhost' = PASSWORD('$mysql_password');"

MySQL.exe, cannot login to gain access, 1064 ERROR with Syntax

This is the command I am typing into the MySQL interpreter, according to the docs:
mysql --user=user_name --password=your_password
So my version is:
mysql --user=root --password=something
I get a 1064 Syntax error saying I typed it wrong. I don't know what to do! I can log into phpMyAdmin correctly and all!
mysql -uroot -psomething
Would do it
you are already in mysql console, and this is not mysql command.
You should run this command in system shell, telling mysql client to use given username and password. But I guess you don't need it since default login and no password works.

Unable to create mysql database dump

I am unable to create mysql database dump. I have tried all the commands in the below question
https://stackoverflow.com/questions/24858436/unable-to-create-mysql-dump-in-mysql-server-5-6-19
But every time I get similar error which asks me to check manual
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
dump -u root -pmysqlmysql hospital_management -r "c:\hosp.sql"' at line 1
I am trying these commands in Mysql command line and NOT on Windows command prompt. Also I am trying these commands before entering any database in mysql.
mysql> mysqldump -u root -pmysqlmysql hospital_management > hosp.sql
This was the first command I tried, which did not work
mysqldump is an executable, you should not run it in the MySQL command line.
Try the command
mysqldump -uroot -pmysqlmysql hospital_management > "C:\hosp.sql"
By reading the documentation, I assume that when using -r, the file must already exist.