SSH tunnel to use RMySQL with RStudio - mysql

I’m newbie to R with RStudio using Mac(OS X).
I successfully use sequel Pro to see DB with like this.
I use dbConnect with RMySQL and DBI(below code) with RStudio.
library(DBI)
library(RMySQL)
con <- dbConnect(RMySQL::MySQL(),
username = "username",
password = "password",
host = "hostname-xxx.ap-northeast-1.rds.amazonaws.com",
port = 3306,
dbname = "dbname"
)
but I've got below error.
Error in .local(drv, ...)
Failed to connect to database: Error: Access denied for user 'username'#'yyyyyyyyyyymarunouchi.tokyo.ocn.ne.jp' (using password: YES)
So ssh tunnel like this using terminal.
ssh -f sshuser#xx.xxx.xx.xx -i ~/.ssh/ssh_key -L 3306:hostname-xxx.ap-northeast-1.rds.amazonaws.com:3306 -N
and successfully logined.
after that, in order to confirm, executed below command(in terminal) but failed after entering correct password.
mysql -h 127.0.0.1 -p -u username dbname
with error code
ERROR 1044 (42000): Access denied for user 'username'#'localhost' to database 'dbname'
(other machine with same username successfully login. I didn't know why...)
and dbConnect(RMySQL with RStudio) is showing same above error.
Anyone same situation? Please tell me what to do.
Thank you.

This is just a matter of database credentials. You need to set up a user in your DBMS who has permission to access the DB that you login to and then use that account + password to login. This may not be the same as the account that you use to login to the server.
CREATE USER 'newuser'#'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'#'localhost';
FLUSH PRIVILEGES;
If this gives you any trouble then instead of granting ALL PRIVILEGES grant each permission one at a time. This is rare but it happens, especially with other DB's like Hive.

Related

Have phpmyadmin and apache, but need to log in to database (Linux Mint)

I am new to linux but learning it pretty well. I have apache working on localhost, I installed mysql through this package: mysql-server 8.0.19-obuntu5
But I need to create a user that works with phpmymadmin and mysql and has access to all the databases. I'm getting these error with root (would post photo but the photos are causing post problems):
Cannot log into mysql server then
mysqli_real_connect(): (HY000/1698): Access denied for user 'root'#'localhost'
Connection for controluser as defined in your configuration failed.
mysqli_real_connect(): (HY000/1698): Access denied for user 'root'#'localhost'
See my config here, without the dollar sign char for vars and colins:
dbuser 'root'
dbpass 'Edited Out For This Post'
basepath ''
dbname 'phpmyadmin'
dbserver 'localhost'
dbport '3306'
dbtype 'mysql'
What should I do to get me logged into all my dbs. Willing to make new user.
Many versions of phpmyadmin disallows root login. Hence, run the following to login as root (in console)
sudo mysql -p -u root
then create a new user (say pmauser) with
CREATE USER 'pmauser'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password_here';
then grant this user the permission
GRANT ALL PRIVILEGES ON *.* TO 'pmauser'#'localhost';
Now try login phpmyadmin by pmauser

mysql not able to establish remote connection

Could not able to connect to the remote mysql server using mysql workbench or direct command line.
When trying it resolves different hostname
When trying directly through command line
mysql --host=10.37.1.92 --port=3306 --user=root --password=password
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'#'myaapvm.local' (using password: YES)
Tried, with password and without password, no luck.
I tried to connect to 10.37.1.92 server but my mysql client try to connect to different server. The only way I can try now is directly login to the machine and do the change in my DB. I have disabled firewall in my mysql DB. Does anyone faced this issue please help.
This server running with maria DB installation.
By default root is not allowed to access the database by using a remote connection. I recommend that you create a new user that will be used for remote connections. You can do that by using the following SQL commands:
CREATE USER 'myuser'#'localhost' IDENTIFIED BY 'mypass';
CREATE USER 'myuser'#'%' IDENTIFIED BY 'mypass';
GRANT ALL ON *.* TO 'myuser'#'localhost';
GRANT ALL ON *.* TO 'myuser'#'%';
FLUSH PRIVILEGES;
You also need to modify your my.cnf if you didn't do that already.
#Replace xxx with your IP Address
bind-address = xxx.xxx.xxx.xxx

Mysql - Unable to enable remote access

I'm having trouble logging in remotely to mysql.
I've set up a user (open_user) without a password and I want to be able to connect with it to my db (open_db) from any remote server (yes I know its a security nightmare but I'm testing something out).
I can log in successfully from the local server:
mysql -openuser open_db
And when I view the grants for this user:
show grants for openuser
- I get this:
GRANT USAGE ON *.* TO 'openuser'#'%'
GRANT ALL PRIVILEGES ON `open_db`.* TO 'openuser'#'%'
My understanding is that this user should be able to log in from any server.
However when I try this:
mysql -uopenuser -hmyserver open_db
I get this:
ERROR 1045 (28000): Access denied for user 'openuser'#'xxx.xxx.xxx.xxx' (using password: NO)
I've also tried setting bind-address in /etc/mysql/my.cnf:
bind-address = 0.0.0.0
Any ideas?
Follow this steps
Open Database Users for MySQL
Edit your user(openuser)
Write to Host %
This will give permission for all IP address for your user.
you can use this,
mysql -h host -u username -p password

mysql is not reading the .mylogin.cfg file correctly

I have created the .mylogin.cfg file with below commands and then tried to connect to mysql with the --login-path option but unable to connect to it. any suggestion are really useful.
mysql_config_editor set --login-path=test --host=10.219.39.121 --user=vidya --password
mysql_config_editor print --all
[test]
user = vidya
password = *****
host = 10.219.39.121
while connecting it is showing error on different IP address as shown below
mysql --login-path=test
ERROR 1045 (28000): Access denied for user 'vidya'#'10.219.39.122' (using password: YES)
Here my concern is why it is showing different IP address and why it is not able to connect even the password is correct. I am using mysql 5.6.6-m9-alpha60.1-log Percona Server.

mysqldump throwing error in perl script , but running fine outside script

I have a script where i take backups through perl script , which is throwing error as mentioned below
mysqldump: Got error: 1045: Access denied for user 'root'#'localhost'
(using password: YES) when trying to connect
I have the root user with with localhost mentioned as % , as per documentation all the host are allowed .
And interesting point is the mysqldump command is running fine outside script ,i.e in shell prompt
Any ideas ????
Run this command to check if root has permissions to connect from localhost
SELECT user,host
FROM mysql.user
WHERE user = 'root'
If you do not have an entry with localhost in the host column, then root is NOT allowed to connect from localhost. You should allow root to connect from locolhost by issuing a GRANT.