Have a question that I can't seem to find an answer for. I am trying to connect to a remote database. I type in the following to my shell:
mysql -u test -h host.name.com -p
mysql asks for my password and then outputs the following:
ERROR 2005 (HY000): Unknown MySQL server host 'host.name.com' (1)
but when I try with the ip address for that hostname
mysql -u test -h xxx.xxx.xxx.xx -p
it works fine
Workaround
Your DNS-settings for host.name.com do not resolve to the correct ip address on the server that runs MySQL and/or the server that you're calling from.
You can add the ip-address to /etc/hosts (for linux)
or c:\windows\system32\drivers\etc\hosts (for windows)
Permanent solution
If that works, see if you can get your DNS-server to resolve correctly, but that's more of a question for Serverfault.
Related
I have two users set up, one is testuser#localhost and one is testuser#111.111.11.111 for example. When I do the following command from ubuntu 20.04 prompt:
mysql -u testuser -p it prompts me for a password and logs me on to testuser#localhost. If I try something like mysql -u 'testuser'#'111.111.11.111' -p it assumes it is localhost and gives an error message Access denied for user 'testuser#111.111.11.111'#'localhost'. How do I specify and log on as a non localhost user?
I found the command, it is mysql -h 111.111.11.111 -u testuser -p. For some reason I am not able to logon with the user with the ip address specified. I keep getting a 2003 error which indicates some kind of configuration issue. Can't connect to MySQL server on ' server ' (10061) indicates that the network connection has been refused.
Let me edit this to make more sense in what I am trying to do. Eventually there will be two mysql servers, say one on ip address 111.111.11.111 and one on 111.111.11.112 for example. I want to be able from a php script running on 111.1111.11.111 be able to access data from a table on 111.111.11.112 for example. I am just now first trying to logon to the first server which is running a mysql database using the user name and ip address of the host.
I will post the answer to the original question which is to include a host parameter in the logon command as follows:
mysql -h 111.111.11.111 -u testuser -p
I am trying to connect my gcloud VM to a mySQL instance also on the cloud, and keep getting this errror:
ERROR 2005 (HY000): Unknown MySQL server host '[10.0.0.1]' (0)
I have followed the instructions from google's documentation here https://cloud.google.com/sql/docs/mysql/connect-admin-ip#connect-ssl and have not found any reasons as to why this could be happening after a lot of searching. I have double checked that the static IP of the VM is authorized, and that I have the right IP for the SQL database. I have tried two ways to connect, using these IP addresses and SSL.
mysql --host=[10.0.0.1] --user=root --password=
and
mysql --ssl-ca=server-ca.pem --ssl-cert=client-cert.pem --ssl-
key=client-key.pem --host=[10.0.0.1] --user=root --password=ms
Both return the same error and I am at a loss as to where to look. Has anyone seen this before, or is more experienced in SQL? This is my first time using a SQL database on google cloud...
Thanks!
In the documentation you pointed to, the example" mysql --host=[INSTANCE_IP] --user=root --password is to imply that the "[INSTANCE_IP]" should be substituted for the IP of your MySQL instance. However, in the snippets above it appears, you may have substituted only the inner content of the braces (i.e. [10.0.0.1]), so try re-running your commands without the braces around your IP:
mysql --host=10.0.0.1 --user=root --password
dnt add the semicolon after the connection command like this
---> bin>mysql -u root -p -h localhost;(here) is the semicolon you just need to remove it and try it like this way..
bin>mysql -u root -p -h localhost
I have a remote mysql instance (not on the local machine, but on the same subnet as my testing platform) that I'm using for testing. So that I can mimic the real database in the application, I've modified /etc/hosts with the following two entries:
192.168.1.249 macduff
192.168.1.249 dc2-mysql-01.kattare.com
Everything works fine when I attempt to access the database remotely using
mysql -h 192.168.1.249 -u myusername -pThePassword
and
mysql -h macduff -u myusername -pThePassword
However, when I use
mysql -h dc2-mysql-01.kattare.com -u myusername -pThePassword
The mysql monitor seems to connect, but it then hangs. It prints the usual password warning but doesn't print the Welcome to the MySQL monitor message, for example. The monitor also doesn't respond to any input. I'm assuming that I've got the user set up properly, given that I can access the instance using the IP address and the single-word alias. I have a single % as the host name associated with the user. If it matters, I'm using a Homebrew install of mysql 5.7.12 on a mac running El Capitan on both the local and remote machines.
MORE INFO:
Just tried creating a user with the dc2... address listed explicitly as a host, but that didn't help (which seems to imply that this isn't a CREATE USER or GRANT issue). I let mysql run for a while, and eventually something timed out and I got a
ERROR 2003 (HY000): Can't connect to MySQL server on
'dc2-mysql-01.kattare.com' (60)
Which implies a DNS problem, but the dc2... address works fine in the browser, so it appears to be something mysql related. DNS in mysql is enabled (it recognizes the single-word alias macduff without difficulty).
Any idea what's going on?
Apparently, I cannot connect to SQL server using the mysql.exe
I logged in as the root user and typed the following
mysql -u root -p
mysql> CONNECT TO 127.0.0.1:3306;
I receive the folling error.
ERROR 2005 (HY000): Unknown MySQL server host '127.0.01:3306' (2)
Unknown MySQL server host '127.0.0.1:3306' (2)
However it connects justs fine using MySQL Workbench with the same parameters.
Host:127.0.0.1
Port:3306
User: root
pass:[empty]
I have the easyphp MySQL module installed. Could this be the reason?
EDIT: TYPO with 127.0.0.1 sorry
According to the documentation, the syntax of the connect command is:
connect [db_name host_name]], \r [db_name host_name]]
Reconnect to the server. The optional database name and host name arguments may be given to specify the default database or the host where the server is running. If omitted, the current values are used.
Therefore your command CONNECT TO 127.0.0.1:3306 is attempting to connect to a database called TO on a host called 127.0.0.1:3306. The error message you receive in return unsurprisingly complains that the host does not exist.
However, it is more usual to specify the hostname and database on invoking mysql (whereupon one can also specify the port if one wishes - see this page for a full list of command line options):
mysql -u username -p -h <hostname> -P <port> db_name
Also note that if the hostname and port are not specified, they default to localhost and 3309 - therefore in your case you can omit all of the above and just go with:
mysql -u username -p db_name
To do what you're currently doing (not specifying the database name on the command-line), you must call the USE command at the mysql> prompt to select a database after you've connected:
mysql -u username -p
mysql> USE db_name;
127.0.01 is explicitly misspelled. 127.0.0.1 is correct
127.0.01:3306 IS NOT 127.0.0.1:3306
You forgot the dot.
Have a question that I can't seem to find an answer for. I am trying to connect to a remote database. I type in the following to my Ubuntu shell:
mysql -u test -h mysql.domain.com -p
mysql asks for my password and then outputs the following:
ERROR 1045 (28000): Access denied for user 'test'#'externalit.domain.com' (using password: YES)
The problem is that I am not on externalit. I am on a completely different host. I think that the server I am on was cloned from externalit, but I didn't set the server up. My question: does mysql have a conf file or other setting that may be automatically entering an incorrect hostname? Can I change this?
That's the name that the server thinks goes with your IP address. It could be do to a DNS setting (it's trying a reverse-DNS), or something in the /etc/host file (mapping that IP to that host).
You need to make sure the reverse DNS on the machine you are connecting from matches the address for the user.
If you are on a shared IP or can't control the reverse DNS then change the permissions on the user to 'test'#'%' this will allow anyone from any ip address connect as long as they have the correct username/password pair. of course this opens up some security issues.
You can prevent mysql from doing reverse lookups and then use 'test'#'123.123.123' as the user/host but unless you are on a fixed IP that could cause issues.
DC
Try adding a protocol option:
mysql -u test -h mysql.domain.com --protocol=tcp -p
and/or try adding a port explicitly:
mysql -u test -h mysql.domain.com -P3306 --protocol=tcp -p
(see: http://dev.mysql.com/doc/refman/5.1/en/mysql-command-options.html#option_mysql_protocol)