To connect to our database, we need to use port forward to connect to the remote instance.
ssh -i [ssh Key] -f -N -L [local port]:[host]:[remote port] [user]#[remote ip]
Afterwards, I can then use this command to access the remote database.
mysql -h 127.0.0.1 -P [local port] -u [database user] -p
If I use the local settings in something like SQLAlchemy or DbVisualizer however, I get
Access denied for user [user]#'10.0.1.70' (using password:
YES)
I know the password is correct, so what am I missing in my understanding? What is the difference here between the cli and these other interfaces?
For DbVisualizer, have you tried specifying Database Server as "localhost", as described here:
http://confluence.dbvis.com/display/UG100/Using+an+SSH+Tunnel
Best Regards
Hans Bergsten (DbVisualizer developer)
Related
I have a problem connecting to a docker mysql DB through the Intellij UI.
I am able to connect using the following command through the terminal:
mysql -h localhost -P 3306 --protocol=tcp -u root -p db_name --password=password
Note the user of the --protocol flag, without this I could not connect. In addition, I assume that since I can connect through the terminal to the docker DB then setup is correct, i.e. the port is exposed and I am able to connect.
In Intellij I use the following connection settings - I am not sure where you specify the protocol of the connection, in case this resolved the issue. I've also tried using 127.0.0.1 instead of localhost which as I read will use the tcp protocol. But no luck.
I've tried the latest MYSQL Driver (8) for the connection as well as the MySQL for 5.1 version.
The error I get is the following(though the password and username are triple checked, and I am able to connect through the terminal):
The specified database user/password combination is rejected:
[28000][1045] Access denied for user 'root'#'localhost' (using
password: YES)
Any help or guidance would be much appreciated.
i have a problem with our new database. The only way to access the database is throw a SSH tunnel. But it doesn't work...
I use following commands:
sshpass -p <PASSWORD> ssh <USER>#<DOMAIN> -p <PORT> -L 3306:localhost:3306 -f -N
I think the ssh tunnel works and is established.
Now I want to connect via Shell-File the database.
deposit=`mysql -h localhost --port=3306 -u <DATABASEUSER> --password=<DATABASEPASSWORD> --skip-column-names -e "<MYSQLSYNTAX>"`
But there is always folowing error:
ERROR 1045 (28000): Access denied for user '<DATABASEUSER>'#'localhost' (using password: YES)
Do you have any ideas or am I doing something wrong?
Thank you very much!
Assuming all your permissions are okay, it may be worth swapping localhost for 127.0.0.1.
As per the MySQL docs: http://dev.mysql.com/doc/refman/5.5/en/connecting.html
On Unix, MySQL programs treat the host name localhost specially, in a
way that is likely different from what you expect compared to other
network-based programs. For connections to localhost, MySQL programs
attempt to connect to the local server by using a Unix socket file.
This occurs even if a --port or -P option is given to specify a port
number. To ensure that the client makes a TCP/IP connection to the
local server, use --host or -h to specify a host name value of
127.0.0.1, or the IP address or name of the local server.
As I understand you are trying to create a tunnel between your computer and a remote computer that's running SQL server. In your ssh command substitute 3306:localhost:3306 with the remote computer IP address. Note this should be its internal local IP address if you are not in the same local network as the remote computer. Check your SQL Database permissions, username and password as well.
I have a server with Rackspace. I want to access the database from my local machine command line.
I tried like:
mysql -u username -h my.application.com -ppassword
But it gives an error:
ERROR 2003 (HY000):
Can't connect to MySQL server on 'my.application.com' (10061)
What causes this error and how can I connect to the remote database?
To directly login to a remote mysql console, use the below command:
mysql -u {username} -p'{password}' \
-h {remote server ip or name} -P {port} \
-D {DB name}
For example
mysql -u root -p'root' \
-h 127.0.0.1 -P 3306 \
-D local
no space after -p as specified in the Using Options on the Command Line documentation
It will take you to the mysql console directly by switching to the mentioned database.
simply put this on terminal at ubuntu:
mysql -u username -h host -p
Now hit enter
terminal will ask you password, enter the password and you are into database server
edit my.cnf file:
vi /etc/my.cnf:
make sure that:
bind-address=YOUR-SERVER-IP
and if you have the line:
skip-networking
make sure to comment it:
#skip-networking
don't forget to restart:
/etc/init.d/mysqld restart
For Mac, use the following command:
mysql -u app -h hostaddress -P port -D dbname -p
and then enter the password when prompted.
If you want to not use ssh tunnel, in my.cnf or mysqld.cnf you must change 127.0.0.1 with your local ip address (192.168.1.100) in order to have access over the Lan. example bellow:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Search for bind-address in my.cnf or mysqld.cnf
bind-address = 127.0.0.1
and change 127.0.0.1 to 192.168.1.100 ( local ip address )
bind-address = 192.168.1.100
To apply the change you made, must restart mysql server using next command.
sudo /etc/init.d/mysql restart
Modify user root for lan acces ( run the query's bellow in remote server that you want to have access )
root#192.168.1.100:~$ mysql -u root -p
..
CREATE USER 'root'#'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
If you want to have access only from specific ip address , change 'root'#'%' to 'root'#'( ip address or hostname)'
CREATE USER 'root'#'192.168.1.100' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'192.168.1.100' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Then you can connect:
nobus#xray:~$ mysql -h 192.168.1.100 -u root -p
tested on ubuntu 18.04 server
Try this command mysql -uuser -hhostname -PPORT -ppassword.
I faced a similar situation and later when mysql port for host was entered with the command, it was solved.
try telnet 3306. If it doesn't open connection, either there is a firewall setting or the server isn't listening (or doesn't work).
run netstat -an on server to see if server is up.
It's possible that you don't allow remote connections.
For more details see:
How Do I Enable Remote Access To MySQL Database Server?
I assume you have MySQL installed on your machine. Execute the command below after filling missing details:
mysql -uUSERNAME -pPASSWORD -hHOSTNAME -P3306
mysql servers are usually configured to listen only to localhost (127.0.0.1), where they are used by web applications.
If that is your case but you have SSH access to your server, you can create an ssh tunnel and connect through that.
On your local machine, create the tunnel.
ssh -L 3307:127.0.0.1:3306 -N $user#$remote_host
(this example uses local port 3307, in case you also have mysql running on your local machine and using the standard port 3306)
Now you should be ale to connect with
mysql -u $user -p -h 127.0.0.1 -P 3307
There is simple command.
mysql -h {hostip} -P {port} -u {username} -p {database}
Example
mysql -h 192.16.16.2 -P 45012 -u rockbook -p rockbookdb
you can use the following code to connect to a remote MY SQL database
mysql -u {database_user} -p{db_password} -h {host_name} -P {port_number}
mysql -u admin -p'your_password' -h your-company.aws.com -P 3306
Must check whether incoming access to port 3306 is block or not by the firewall.
this solution worked for me:
On your remote machine (example: 295.13.12.53) has access to your target remote machine (which runs mysql server)
ssh -f -L 295.13.12.53:3306:10.18.81.36:3306 user#295.13.12.53
Explained:
ssh -f -L your_ssh_mashine_ipaddress:your_ssh_mashine_local_port:target_ipaddress:target_port user#your_ip_address -N
your_ssh_mashine_ipaddress - it is not local ip address, it is ip address
that you ssh to, in this example 295.13.12.53
your_ssh_mashine_local_port -this is custom port not 22, in this example it is 3306.
target_ipaddress - ip of the machine that you trying to dump DB.
target_port - 3306 this is real port for MySQL server.
user#your_ip_address - this is ssh credentials for the ssh mashine that you connect
Once all this done then go back to your machine and do this:
mysqldump -h 295.13.12.53 -P 3306 -u username -p db_name > dumped_db.sql
Will ask for password, put your password and you are connected.
Hope this helps.
Try this, Its working:
mysql -h {hostname} -u{username} -p{password} -N -e "{query to execute}"
This one worked for me in mysql 8, replace hostname with your hostname and port_number with your port_number, you can also change your mysql_user if he is not root
mysql --host=host_name --port=port_number -u root -p
Further Information Here
You should put your password with 'p'
mysql -u root -u 1.1.1.1 -p'MyPass'
I was too getting the same error.
But found it useful by creating new mysql user on remote mysql server ans then connect. Run following command on remote server:
CREATE USER 'openvani'#'localhost' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'openvani'#'localhost WITH GRANT
OPTION;
CREATE USER 'openvani'#'%' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'openvani'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Now you can connect with remote mysql with following command.
mysql -u openvani -h 'any ip address'-p
Here is the full post:
http://openvani.com/blog/connect-remotely-mysql-server/
If you are on windows, try Visual Studio Code with MySQL plugins, an easy and integrated way to access MySQL data on a windows machine. And the database tables listed and can execute any custom queries.
If port is default, some version required data base name which you trying to connect.
mysql -u <<your username>> -h <<your host>> <<your db name >> -p
This will prompt password Then type your password. If port is not default 3306
Then:
mysql -u <<your username>> -h <<your host>> -P <<your port>> <<your db name >> -p
I want to connect to remote MySQL via ssh tunnel with user that has 'localhost' access.
I use this to make a tunnel:
ssh -f -N -L 33306:localhost:3306 user#remote-host
and this to connect to host:
mysql -h 127.0.0.1 -P 33306 -uuser -ppassword
The error i get is:
ERROR 1045 (28000): Access denied for user 'user'#'remote-host' (using password: YES)
The problem is that user 'user'#'remote-host' (or 'user'#'%') does not exist, only 'user'#'localhost' does.
Is there a way to force remote host, without server-side modifications into thinking that i come from localhost? That's the only reason I would do the connection via ssh tunnel anyway.
Note:
If I want to connect with this command:
mysql -h localhost -P 33306 -uuser -ppassword
I get this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Additional data:
On remote server in /etc/hosts the values are like this:
127.0.0.1 localhost
remote-ip remote-host
The simple way to create MySQL Tunnel to REMOTE HOST:
$ ssh -fNL TEMP_PORT:localhost:MYSQL_SERVER_PORT USER#SERVER_NAME
Test:
$ mysql -u root -p -h 127.0.0.1 -P TEMP_PORT
Please note that localhost and 127.0.0.1 are treated differently in mysql on unix.
Quoting:
On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file
http://dev.mysql.com/doc/refman/5.7/en/connecting.html:
Furthermore, mysql client would silently try to use a socket file even if you explicitly specify -P on your command line:
This occurs even if a --port or -P option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server, use --host or -h to specify a host name value of 127.0.0.1
Effectively, using this command
mysql -h localhost -P 33306 -uuser -ppassword
you're simply trying to connect to your local mysqld which is missing
Considering this, your question boils down to connecting to a remote server available over a domain socket.
If installing additional software meets your requirements 'without server-side modifications' you could use socat as described here:
https://www.debian-administration.org/users/dkg/weblog/68.
Tailored for mysql, it could work as follows:
install socat on both ends
socat "UNIX-LISTEN:your_local_path/mysql.sock,reuseaddr,fork" EXEC:'ssh user#remote-host socat STDIO UNIX-CONNECT\:/your_server_path/mysql.sock"
mysql -S your_local_path/mysql.sock -u user
I got a database server failure, says host is blocked because of many connection errors. It ask me to unblock with 'mysqladmin flush-hosts'
how and where should I run this command to our amazon rds database server?
thank you
For normal MySQL, just connect as the 'root' administrative super user, and issue the command:
FLUSH HOSTS
Even in the case of too many connections, MySQL should be keeping a connection in reserve so that a super user can connect.
The mysqladmin client generally connects as root anyway and issues the above SQL.
Login to any other EC2 instance you have that has access to the RDS instance in question and has mysqladmin installed and run
mysqladmin -h <RDS ENDPOINT URL> -P 3306 -u <USER> -p flush-hosts
you will be prompted for your password
When an Amazon RDS instance is blocked because the value of max_connect_errors has been exceeded, you cannot use the host that generated the connection errors to issue the "flush hosts" command, as the MySQL Server running on the instance is at that point blocking connections from that host.
You therefore need to issue the "flush hosts" command from another EC2 instance or remote server that has access to that RDS instance.
mysqladmin -h [YOUR RDS END POINT URL] -P 3306 -u [DB USER] -p flush-hosts
If this involved launching a new instance, or creating/modifying security groups to permit external access, it may be quicker to simply login to the RDS user interface and reboot the RDS instance that is blocked.
I fixed this error on my RDS instance by rebooting it from the AWS management console. HTH
[edit: lol downvotes]
On Amazon RDS FLUSH HOSTS; can be executed from default user ("Master Username" in RDS info), and it helps.
Since the hosts is blocked. try connect it from other host and execute the mysqladmin flush-hosts command.
mysqladmin -h <RDS ENDPOINT URL> -P <PORT> -u <USER> -p flush-hosts
You will have to connect your RDS through a computer which as mysql installed on it
I used one of my hosting VPS using SSH
After i was logged in my VPS ( i used putty ) It was simple, in the prompt i entered the following command:
mysqladmin -h [YOUR RDS END POINT URL] -P 3306 -u [DB USER] -p flush-hosts
You can restart the database on RDS Admin.
You can flush hosts local MySQL using following command:
mysqladmin -u [username] -p flush-hosts
**** [MySQL password]
or
mysqladmin flush-hosts -u [username] -p
**** [MySQL password]
Though Amazon RDS database server is on network then use the following command as like as flush network MySQL server:
mysqladmin -h <RDS ENDPOINT URL> -P <PORT> -u <USER> -p flush-hosts
mysqladmin -h [YOUR RDS END POINT URL] -P 3306 -u [DB USER] -p flush-hosts
In additional suggestion
you can permanently solve blocked of many connections error problem by editing
my.ini file[Mysql configuration file]
change variables max_connections = 10000;
or
login into MySQL using command line -
mysql -u [username] -p
**** [MySQL password]
put the below command into MySQL window
SET GLOBAL max_connect_errors=10000;
set global max_connections = 200;
check veritable using command-
show variables like "max_connections";
show variables like "max_connect_errors";
got this error today on a customer rds while they were using Heidi Sql client.
We simply used 'mysqlroot' on the ec2 that talks to the rds in question to connect, followed by issuing the 'flush hosts;' cmd.