mysql command line access denied error 1045 - mysql

I am trying to access mysql from the command line with:
mysql -u root --password password
but I get
Enter password: ERROR 1045 (28000): Access denied for user
'root'#'localhost' (using password: NO)
Why is it saying that I'm not using a password?

I use the following syntax:
mysql -h [host] -u [user] -p[password]
Notice that there's no space between the -pand the [password]
The correct syntax for what you're typing is:
mysql -h [host] -u [user] --password=[password]
(Check reference manual... it's section 4.5.1 for version 5.5)
If you're working on the same computer where MySQL is installed, you can skip the -h [host] piece, or type -h localhost.

I first tried to add C:\Program Files\MySQL\MySQL Server 8.0\bin into the path (env variable), didn't work out.
It might be another reason but in my case it was all about copying and pasting the password, typing it out manually solved the issue.

Related

I have ubuntu installed with mysql .the below error keeps showing up

linux#ubuntu:~$ mysql
ERROR 1045 (28000): Access denied for user 'linux'#'localhost' (using password: NO)
linux#ubuntu:~$ mysql -u -p
ERROR 1045 (28000): Access denied for user '-p'#'localhost' (using password: NO)
linux#ubuntu:~$
I have ubuntu 14. installed with mysql on a virtual machine vmware .
The above error keeps showing up and I only see the solution everywhere on the internet as :
use "mysql -u -p" but still the error occurs.
It should have space, try this:
mysql -u {username} -p
if you didn't configure mysql(setting password for user), then use just
mysql -uroot, You should mention username.
You can set password for default user root by
mysqladmin -uroot password yourpassword
after setting password run
mysql -uroot -pyourpassword

MySQL Access denied after typing 'mysql -proot'

I am new to MySQL. My issue is, is that after typing mysql -proot in the terminal I am receiving this error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I don't know what i am doing wrong. I did create a password. However I don't really know how to put it in, in combo with this command.
I am using CentOS 6 on my server
It's a typo on the syntax. You need a space between proot. It should be
mysql -p root
instead of
mysql -proot
mysql -proot this command is telling mysql to use root as the password, which I'm assuming is not the password. You need to put a space between the -p switch and the username to be get the interactive password prompt.
mysql -p root

Installing snort, having trouble with SQL root password

So I am installing snort currently on my ubuntu linux server. I am following this guide here.
At this point, I am at the part in the guide where I am installing Barnyard2 and i need to access my SQL database to save information. linux server is near fresh install with little else on it. When I try to do this part of the guide:
echo "create database snort;" | mysql -u root -p
mysql -u root -p -D snort < ~/snort_src/barnyard2-master/schemas/create_mysql
echo "grant create, insert, select, delete, update on snort.* to \
snort#localhost identified by 'MYSQLSNORTPASSWORD'" | mysql -u root -p
When I run the first line - if I don't enter anything, I get the error message that says:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
If I do enter something, I get a different error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I have tried using this in order to reset my password but the command mysql -u root or any form of command similiar results back in the same error, even when it says the password is probably not required for this command. Does anyone know a way in which I can get this to work?
Why don't you break that down into chunks?
First make the database:
$ mysql -u root -p -e 'CREATE DATABASE `snort`'
Import the barnyard schema
$ mysql -u root -p < ~/snort_src/barnyard2-master/schemas/create_mysql
Now create the user & assign permissions for the snort db to the barnyard user
$ mysql -u root -p -e 'GRANT CREATE, INSERT, SELECT, DELETE, UPDATE ON `snort`.* TO snort#localhost IDENTIFIED BY '[SNORT PASSSWORD]'
The commands in your question are running a local mysql client which assumes to connect to a local database by default. If your database is running on a neighbouring Windows box you will need to rethink your parameters.
mysql -u root -p -h 192.168.0.99

mysqldump: Got error: 1045 Access denied

I am logged into an AWS instance and trying to copy a mysql database to a .sql file. I am using the command:
mysqldump -u [username] -p [databasename] > [database].sql
Then entering the password and the following message comes up.
"mysqldump: Got error: 1045: Access denied for user '[username]'#'localhost' (using password: YES) when trying to connect."
I can login directly to mysql using the same credentials as above, but still get the same error.
I have tried a bunch of different ways for the command above, but it seems to be an issue with permissions or something similar. The user does have all privileges for the database when looking in phpmyadmin so I am not sure what is wrong? Any suggestions? Thanks
This works for me:
mysqldump -uroot -pxxxx dbname > dump.sql
or you can specify the host:
mysqldump -h localhost.localdomain -uroot -pxxxx dbname > dump.sql
Check to make sure you don't have different instances of mysql running
Thank you all for your input! It got me thinking about what else it could possibly be. I then tried using the -h parameter as well, which wouldn't work with "localhost". It finally worked when I used the Private IP Address for the AWS instance.
mysqldump -h [PrivateIPAdress] -u [UserName] -p [DatabaseName] > [Database].sql
mysqldump -u [username] -p
ENTER YOUR PASSWORD
USE [databasename]
SOURCE /path/to/[database].sql
I am not sure, but worth a try because you said you are able to login into that machine.

php can connect to remote sql server but command line can't

I'm using exactly the same credentials to connect to a remote mysql server.
host % is given to the user.
I can connect via my php application on localhost to remote mysql server
however whenever i do command line on localhost
mysql -u username -p'password' -h remoteserver.domain.com
it throws an error
ERROR 1045 (28000): Access denied for user 'username'#'10.50.2.4' (using
password: YES)
what am i missing here?
Your mysql command line is wrong. Mysql has the funky syntax of:
mysql -u username -ppassword -h remoteserver.domain.com
instead of
mysql -u username -p password -h remoteserver.domain.com
Note the p tag and password placement.
turns out that i should do away single quotes in my password for windows-based mysql command
instead of
mysql -u username -p'password' -h remoteserver.domain.com
this actually works
mysql -u username -ppassword -h remoteserver.domain.com
reason why i use single quotes because my password contains non-alpha characters which works in linux but not on windows based command line