Mysql -h option not working - mysql

I am trying to connect mysql hosted onto a remote machine and everytime I provide the remote host with -h option it's still taking local machines hostname
example
mysql -u user-p pass -h "IP" -P 3306 -D DB
Enter password:
ERROR 1045 (28000): Access denied for user 'user'#'localhost' (using password: YES)
Not sure why it's ignoring the remote host name. It's showing localhost's hostname instead of the IP I am providing

You can't put a space between -p and the password.
mysql -u user -ppass -h IP -P 3306 -D DB
If there's nothing immediately after -p, it prompts for the password instead of getting it from the command line.
This error is causing the rest of the command line to be parsed incorrectly. It thinks -p is the last option, because the next word doesn't begin with -.

Related

DbDeployer - MySQL instance - Grants for new databases (or root user)

This question relates to 3rd party tool dbdeployer, located Dbdeployer at Github
The section in question:
Users:
root, with the default grants as given by the server version being installed.
I have an instance installed on port 5730 and port 5731 respectively. (Corresponds to MySQL 5.7.30 and 5.7.31).
I can connect like this:
mysql -u msandbox -p -h 127.0.0.1 -P 5730
mysql -u msandbox -p -h 127.0.0.1 -P 5731
mysql -u mycustomusername -p -h 127.0.0.1 -P 5730
I created a file for grants like shown in the article:
use the option --post-grants-sql-file to load the instructions.
> cat << EOF > orchestrator.sql
CREATE DATABASE IF NOT EXISTS orchestrator;
CREATE USER orchestrator IDENTIFIED BY 'msandbox';
GRANT ALL PRIVILEGES ON orchestrator.* TO orchestrator;
GRANT SELECT ON mysql.slave_master_info TO orchestrator;
EOF
$ dbdeployer deploy single 5.7 \
--post-grants-sql-file=$PWD/orchestrator.sql
This works fine for a new empty database deployed by the SQL script (and its grants), but I now have an existing instance, and want to create a new database from within the mysql instance.
The article claims that root should be available, but:
mysql -u root -p -h 127.0.0.1 -P 5731
Access denied for user 'root'#'localhost' (using password: YES)
I have the local instance installed on 3306, but this is not supposed to be the user I need to login with.
When I do this:
mysql -u root -p -h localhost -P 5731
I am able to login, _however this seems to ignore the port (when connecting as localhost) because I see different databases (those on port 3306 and not those from 5730/5731)!
This also confirms my suspicion that port gets ignored :
SHOW GRANTS FOR mycustomusername;
ERROR 1141 (42000): There is no such grant defined for user 'mycustomusername' on host '%'
SHOW GLOBAL VARIABLES LIKE '%port%';
.... truncated ....
port | 3306
I need to use root#host5731 and root#host5730 but there does not seem a way to use root here?
I need to do one (either) of the following:
Use root user at these ports,
Get a way to let msandbox or mycustomusername to be able to have ability to do GRANT ALL PRIVILEGES on a new database.
Why?
I cannot remove/recreate a new MySQL instance to add new databases (using the SQL file method) --post-grants-sql-file when I already have existing databases.
Dbdeployer instances and setup installed and configures the password for root to be the same password as the username specified (default username msandbox).
You cannot do this (even though some answers on the github repo claim you can)
dbdeployer deploy single 5.7.31 -u root -p somepassword
Rather what happens (and not clearly mentioned anywhere easily accessible) is that you can do the following:
dbdeployer deploy single 5.7.31 -u someuser -p somepassword
Dbdeployer setup then deploys this someuser AND root to have the same password (somepassword).
More information:
I found that I could do this:
cd /var/dbdeployer/instance/location/of/mysql.5.7.31/
./use -u root
(Not specifying the password here.)
Inspecting the ./use script, it greps the password from your configuration (which is the password for someuser.
This then gives us the ability to login via root to change grants:
mysql -u root -p -h 127.0.0.1 -P 5731
I have now changed the password from inside:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'new-password';
This prevents you from externally using ./use -u root as the password is now different than the other user.

MySQL client suddenly connects with external IP

After a while (weeks) not working with MySQL 5.5.41-0ubuntu0.14.04.1-log, now when I try to connect I get:
$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'DD.D.DDD.DDD' (using password: YES)
(D are the digits of my external IP)
I have no problem if I use
$ mysql -u root -p -h localhost
Why is it now using my external IP? I have no changes under /etc/mysql
left in a vacuum it guess since you did not specify -h host in first attempt. It marches down mysql.user and finds the first match for the wildcard. And your entered password did not match it.
running a select * from mysql.user might shed some light on it. You might find entries such as:
Host User
172.31.2.202 root
localhost root
% root
127.0.0.1 root
Edit:
Sometimes you need to do a:
CREATE USER 'root'#'www.xxx.yyy.zzz' IDENTIFIED BY 'new_password';
Followed by the necessary grants for that user. Above where I say root, it is just an example. I would not do root !
Also, do not put a space after -u, so it is not -u root, it is -uroot

error: 1045: Access denied for user 'user'#'123.10.123.123' (using password: NO) when trying to connect

I am trying to get a local snapshot of a database by running this command:
mysqldump --single-transaction --quick -u user -ppass -h somehost db_name | mysql -u user -ppass -h localhost db_name
Even though this has worked for me in the past, I am now getting this error back:
error: 1045: Access denied for user 'user'#'123.10.123.123' (using password: NO) when trying to connect
I can successfully log in with the username and password above:
mysql -u user -ppass -h localhost
and I have previously granted privileges to the user for the local database, e.g.
grant all on db_name.* to user;
I also find it strange that the error message is returning user#my_ip_address instead of user#localhost when I have specified localhost as the host. I'm also confused as to why it says using password: NO, as I've also provided a password.
It turns out that the remote host that I was attempting to download from had changed. Using the correct new hostname solved the problem.

mysql command line access denied error 1045

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.

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