MySQL client suddenly connects with external IP - mysql

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

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 -h option not working

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 -.

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

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.

How can I fix the MySQL 'access denied' errors after db restore?

I exported all databases of a MySQL server by:
mysqldump -u root -p --all-databases > /tmp/dbs.sql
Then I copied the file (by scp) on another server, which has the same MySQL version, and imported it with:
mysql -u root -p < dbs.sql
I can access to MySQL only as root. With other users, I obtain:
~$ mysql -u jag -p
Enter password:
ERROR 1045 (28000): Access denied for user 'jag'#'localhost' (using password: YES)
However, selecting all users in mysql.user table, I can see that all user accounts where imported. So, how can I overcome this problem, without resetting all user passwords?
You need to specify username and password, you can try this:
mysql -u USERNAME -pPASSWORD -h HOSTNAMEORIP DATABASENAME
Note that there is no space between -p parameter and password!
You can check this: http://dev.mysql.com/doc/refman/5.0/en/connecting.html
After following all the similar answers for this issue, I've solved it in CentOS with this:
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
please make sure to grant privileges to that user u want to restore with, in this case 'jag'