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.
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 to MySQL database from MySQL shell on windows.
No matter what I type in MySQL shell, it keeps giving me error : 'Not connected'.
Query eg 1 : mysql --host=localhost --port=3306 --user=root -p;
Query eg 2 : mysql -u root -p
O/P : ERROR: Not connected
I have MySQL server installed on my machine. Also MySQL service is running in the background.
Also, I was able to connect from MySQL workbench.
ERROR MESSAGE
MySQL Workbench Connection
My temporary workaround is that I make use of ssl protocol to connect to MySQL server :
MySQL> \connect root#localhost
MySQL localhost:33060+ ssl SQL > show databases;
The first step is that you need to check if you are in the MYSQL Shell SQL mode or JS mode.
Then if you are in SQL mode then you are good to go else you need to switch to SQL mode by this command
\sql
The next step is to connect using this command
\connect root#localhost
In your case, you might have given the privilege as the IP address so you need to check your localhost IP which can be done by this command in your command prompt.
ipconfig and then just check the IP address and put it in place of localhost in the previous command. If this still doesn't works then put 127.0.0.1:3306.
After this, it will prompt to add or save the password , enter a unique password there.
After this you are good to go and check the user and localhost after this by this command
SELECT user, host FROM mysql.user;
Try mysql -u root -p
I haven't used MySQL shell, I typically use gitbash and it works just fine
I had faced the same issue on my Windows 10 machine with MySQL 5.7 and the following commands helped me:
mysqlsh.exe - to open mysql shell; then
\sql - to start working with SQL;
finally:
\connect root#127.0.0.1:3306
You can use:
mysql -uroot -hlocalhost -P3306 -p
or
mysql -uroot -h127.0.0.1 -P3306 -p
or
mysql -uroot -p
This is not a issue, just a curiosity which I couldn't find any answer for on mysql's reference or googling:
First of all I know that to connect to a database I would run on bash:
mysql -h myhost -u myusername -p
But if I just run the mysql command without parameters I have the mysql> prompt and on the help I can see that there's a 'connect' command. But you can't set the user or password, just the database and host so it will always deny the access naturally.
I also tried to run mysql with just the username and password parameters from bash (to specify the db and host later) but that don't work either. So, does the connect command work only if you ran mysql with the username and pass which are the same for another host? Or does it have more uses?
This is not secured but you can set mysql password on Unix shell as:
export MYSQL_PWD=secret
# then run mysql client to connect
mysql
mysql> connect somedb localhost
mysql> show tables
See MySQL Manual for list of environment variables
PS: mysql will use your unix user as mysql user for connecting. Alternatively you can set env variable USER on Windows or NetWare.
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.
I have mysql 5.1 set up and running.
I need to connect to:
location: comm.eng.bxg.com
name: amntxy
user: username
pswd: password
I have tried using
mysql -h amntxy -u username -p
Also tried: use amntxy and use comm.eng.bxg.com/amntxy
But I am unable to connect.
I get the following error:
ERROR 2005 (HY000): Unknown MySQL server host
I also tried mysql_connect but keep getting the error : mysql_connect is not recognized as internal or external command
But I do not understand hwo I can connect here.
Please help.
Thank you
mysql -h comm.eng.bxg.com -u username -p
After this it will ask for a password.
Optionally you can also directly specify the database name that you want:
mysql -h comm.eng.bxg.com -u username -p db_name
But again, this is 100% optional. You will be able to select or change it after with the command USE db_name.