I am using "mysql -u root -p" command to start mysql but I am getting error as:
Access denied for user 'root'#localhost''
I always have to use sudo to to launch it. Other applications start normally. How do I get around it? I am doing jdbc connection (java). Mysql doesn't give access to database in java. I think requiring sudo command is the problem.
System:
Ubuntu 18.04 LTS dual booted with Windows 10.
I always have to use sudo to to launch it
No. You need to use sudo to get the client to authenticate against the server.
The reason for this is that recent versions of MySQL (and MariaDB, PerconaDB) use SO_PEERCRED to very that the username asserted in the connection string (root) is the same user as started the client (this makes use of a password somewhat redundant).
Since SO_PERRCRED only works on filesystem sockets (AF_UNIX) you may be able to bypass the constraint by connecting via a network socket, e.g.
mysql -h 127.0.0.1 -u root -p
But do be aware that MySQL typically has separate user records for connections via network (host != 'localhost') and filesystem (host='localhost') sockets.
But as per the question #Ciarambola flagged, 'root' is a special case and should not be used for routine access - you should create a new user.
Mysql doesn't give access to database in java
You should never use an admin account as the embedded credentials in an application. If you make that account with the same name as your user you won't need to use sudo when you connect to 'localhost'.
Related
I have a ubuntu 16.04 on which I run 3 servers from virtualbox (a webserver, a home file server and a mysql server).
In this mysql server I naturally have an internal ip (192.168....) and an external one.
However when I try to connect remotely to this mysql server from mysql shell, workbench or .NET connector (eg. mysql -u root -p -h 172.241.442.12) using the external IP of this virtual machine I always get ERROR: Not connected.
My question is whether to connect I have to enable port forwarding in my router (3306), just as I would do enabling 80/8080 in a webserver to make it accessible from the internet.
I never did it before and haven't find any clear tutorial either. My main purpose is to connect to this db in a vb.net application.
Thanks!
Yes, if you intend to access it in this manner you will need to forward a port. You will also need to grant access to MySQL for a user that is allowed remote access.
GRANT ALL ON somedb.* TO `user`#`123.123.123.123` IDENTIFIED BY 'somePassword'
The IP address can be a hostname, or % to match everything.
That said, unless you really need a permanant external connection to MySQL you should not expose it like this, the better option would be to tunnel the port through SSH.
ssh -N user#dbserver -L12345:localhost:3306 &
mysql -u root -h localhost -P 12345
I would like couple things clarified.
(I have mysql client installed on my remote VM running on Ubuntu 16.04, goal is to access the database from within R but I have been trying so far with mysql as such: mysql -u root -p -h fe80::883f:XXXX:XXX:XXXXX -P 3306 where for "XXX" I tried every ip address I get in windows command line when the command ipconfig is issued.
To narrow down my troubleshooting I want couple pointers:
Do I need to give the IP address for my remote(cloud) instance in the mysql config file (thus find my.cnf or its equivalent in windows in dir where mysql server is installed and bind the address for the remote/cloud VM I am trying to access the db on my laptop from).
2 SSL, is this something that needs to be enabled?
Additionally, from Bash on Ubuntu on Windows (WSL) I am able to log into mysql server with `mysql -u root -p'xxx' -h ' i.e. the ip address from windows command line ipconfig output called "Link-local IPv6 Address". After going over several posts and using my imagination(which gets me in trouble with troubleshooting), I feel like in some config file in MySQL server dir is have to "bind the address" for the remote VM (which I access via putty from my laptop), am thinking along the right path?
As for the privileges for the root user in mysql server I believe I have given root every privilege (show below):
enter image description here
If you're going to use the RJDBC package, you have to stick with JDBC. ODBC might be "one letter off", but it's not the same thing.
You need a few things to be in place:
The database on your Windows machine has to be running, visible from the Linux machine, and have a JDBC driver JAR available that will let you connect to it. If you tell me your database is Microsoft Access, you're done. There are no free JDBC drivers for Access.
You have to have the JDBC driver JAR for your database on the Linux machine, in the CLASSPATH that R will use to find it.
You need a JDK installed on the Linux machine. I recommend that you install nothing older than version 8.
Once this is in place it should be easy. I've done it.
I solved my issue and can access MySQL sever on my laptop from remote ression(that I access with putty as follows:
in putty first used 3307 as source, checked the remote radio buttons, set destination to localhost:3306 and at Bash prompt in VM:
mysql -u root -p -h '127.0.0.1' -P 3307
Or from Linux (I use WSL) Bash prompt:
# access the remote VM from Windows Linux subsystem(WSL)
ssh -R 3307:localhost:3306 blsingh#149.165.169.21
## access MySQL server on my laptop from Bash prompt on in WSL
mysql -u root -p -h'127.0.0.1' -P 3307
From here its not difficult to figure out how to access it in R; we have a remote port forward and we use the same parameters in R.
☼
Current situation is as follows:
I have succesfully installed OpenProject on Ubuntu 14.04 server using the guide from the official website (https://www.openproject.org/open-source/download/packaged-installation-guide/). When configuring for the first time I let the configuration manager install MySQL and create the appropriate database(s).
Now I'm trying to migrate and for this to happen, I need outside access to the information_schema (schema) and database. This is supposedly done using the openproject user but I cannot seem to be able to login using this user on the commandline.
Just to be sure, I just statement below:
mysql -u openproject -D openproject -p
Then I entered the right password and press enter. It gets the default ERROR 1045.
I am however able to login using root user and debian-sys-maint user which was created on the initial install step. The password I used for these accounts were found in the file under "/etc/openproject/installer.dat". I am absolutely positive I use the correct password, for the application runs fine under said user.
Is there a setting in mysql that I am missing that would block users from making connection using the commandline utility?
Figured it out. In MySQL the host 127.0.0.1 and localhost are essentially different. User OpenProject by default gets assigned to host 127.0.0.1, so naturally connecting openproject#localhost did not work, though root account has different user profiles (4 to be exact) allowing it to connect to both localhost and 127.0.0.1 .
TLDR version:
Use the statement as follows:
mysql -u openproject -h 127.0.0.1 -p
Should do the trick.
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?
I am trying to install drupal on remote mysql server. I have created the user in mysql and granted the the privileges.
I am able to connect through command line from my web server like this "mysql -u xxxx -h 10.xxx.yy.zz3 -p".
But when I tried to install drupal I get "SQLSTATE[28000] [1045] Access denied for user 'xxxx'#'localhost'". I have given the privileges for "xxxx"#"10.xxx.yy.zz3" but drupal appends localhost instead of IP to user name. I have changed settings.php to mysql server IP.
What am I missing?
Instead of editing the settings.php file, try the following:
The third screen during installation (Database configuration) let you set up the database on a remote MySQL server. To do so, expand Advanced options and enter the database host.
I cannot guarantee that this will work, but this is how I set up Drupal to use a remote MySQL server, and I have never had this problem. Btw, I always use the canonical domain name (e.g. mysql.example.org) and not the IP-address.