Why is 'localhost' the default host used when trying to connect to MariaDB? - host

I have recently installed MariaDB on Fedora 19 in VirtualBox on Windows 7.
When I run:
MariaDB [(none)]> SELECT user, host, password FROM mysql.user;
I get:
+------+----------------------+-------------------------------------------+
| user | host | password |
+------+----------------------+-------------------------------------------+
| root | localhost | ***************************************** |
| root | my.hostname | ***************************************** |
| root | 127.0.0.1 | ***************************************** |
| nusr | my.hostname | ***************************************** |
+------+----------------------+-------------------------------------------+
my.hostname is the hostname I changed the default hostname to in Fedora.
I created the user 'nusr' with:
CREATE USER 'nusr'#'my.hostname' IDENTIFIED BY 'my_password';
When I try and connect to MariaDB with:
[me#my ~]$ mysql -u nusr -p
Enter password:
I get:
ERROR 1045 (28000): Access denied for user 'nusr'#'localhost' (using password: YES)
I am guessing this is because it is referring to 'nusr'#'localhost' instead of 'nusr'#'my.hostname'.
Why is 'localhost' the default host used when trying to connect to MariaDB?
Do the host's 'localhost' and '127.0.0.1' need to be kept?
As a context to this question, I am not really sure what the terms 'host' and 'hostname' mean, I just wanted to 'customise' my experience of learning MariaDB commands, so perhaps I have gone awry by completing the steps above.

Very old question but..
ERROR 1045 (28000): Access denied for user 'nusr'#'localhost' (using password: YES)
I am guessing this is because it is referring to 'nusr'#'localhost' instead of 'nusr'#'my.hostname'.
YES.
Why is 'localhost' the default host used when trying to connect to MariaDB?
Because the assumption is that you will connect to the database from the same machine the database is in (localhost).
If you define the user as being #my.hostname it means the connection to the database will be made from another machine, called my.hostname.
Do the host's 'localhost' and '127.0.0.1' need to be kept?
Only if you want to be able to access the database from there..
In that setup, if you delete root user #localhost and #127.0.0.1 then you will not be able to log into the database from inside the virtualbox where the database resides. And you will only be able to access if you connect from a machine called my.hostname. But for that to work you must make sure that the database environment knows my.hostname.

The MariaDB server (also MySQL) treats localhost in a special way. Where other software treat it like an alias of the loopback address 127.0.0.1, MariaDB will interpret it as a UNIX domain socket connection to the server. By default this socket file is located in /var/lib/mysql/mysql.sock.
To connect via the network to the local server, use the -h 127.0.01 parameter. This tells the mysql client to connect via the loopback network interface instead of the socket.
Regardless of other grants, MariaDB will always translate localhost to a local socket connection. If you want to prevent this and only allow access via the network, drop the users that have localhost as their host.
You can view all users in the database by executing the following query:
SELECT * FROM mysql.user

You must create properly user on system Fedora 19:
[root#localhost ~]# useradd nusr
[root#localhost ~]# passwd nusr
Changing password for user fedora.
New UNIX password:# set password
Retype new UNIX password:# confirm
passwd: all authentication tokens updated successfully.
[root#localhost ~]# exit # logout
So, a database didn't find user nusr and it will not to handle user nusr because isn't created on system wide.
Hostname is from IP address named as "mydomain.com", but "host" can be IP address or name lookup host "mydomain.com".

Related

Connect to Progress database without knowing user and password

Setup: Progress 11.5 databases sitting on Linux (CentOS) server, with proenv available.
I'm trying to connect to Progress database through proenv and sqlexp. I'm unable to, since I don't know the user and password. There's no way I can obtain it from someone else, as nobody knows these credentials. I have root access on this server.
How can I connect to this database so that I can later create another account to use through ODBC?
What I've tried already is:
Being on root account, opening up proenv by
/dlcloc/dlc-11.5/bin/proenv
which brings up proenv, and then when I try
sqlexp -db rep -H localhost -S 2502 {-user ?? -password ??}
given that there's a db within
/dbloc/prod/rep/
with files like rep.db, rep.lg, rep.b1, rep.d1 and some other files avilable on localhost under port 2502 (confirmed through ps aux | grep rep)
I get an error even without user and password
Error: [DataDirect][OpenEdge JDBC Driver][OpenEdge] Access denied(Authorisation failed). (8933)
Which is obvious from my side, but there's no way to get user and password. How can I go around this given my environment to be able to establish a successfull connection?
Additional note: There's a special user called progressuser under which database is created, but impersonating that user from root as su progressuser and going through the same process yields the same results.
You could try accessing the database using the native 4GL broker. And possibly try this solution:
https://knowledgebase.progress.com/articles/Article/P9483
First run that proenv-script, it will set paths and environment variables.
Then identify on which port the 4GL broker runs. If you dont know: check your database log file (rep.lg). Look for something like:
[YYYY/MM/DD#HH:MM:SS.sss+TZ] P-XXXX T-YYYY I BROKER 0: (4262) Servicename (-S): NNNN.
The Ns will be your port. It might possibly be a service name to check in /etc/services
Then access the Progress Editor with a connected database:
pro -db rep -H <IP-address/domain name> -S <port number/service name>
You should see a rudimentary editor. To run something you press Ctrl+X or F1. To access the menu F3. To exit something F4.
Access the Menu using F3 and arrow-key your way to Tools -> Datadictionary. Now you should be able to follow the steps in the link provided above.
Perhaps its a good idea to make sure you have a valid backup before you start messing around with the users...

How to connect to laravel forge database via SSH tunnel using HeidiSQL

I'm trying to do the above. HeidiSQL has a load of settings and I have a load of possible values, but I'm not sure exactly what goes where. Here are the different places I can put values
Settings screen
SSH screen
And the values I have are as follows:
The IP address of the database (v)
The port the database uses (w)
The database username and password (x)
My ssh private key (y)
The port I'm going to use on my computer (z)
I've tried many combinations, but generally get the response:
PLink exited unexpected. Command line was: C:\Program Files\PuTTY\plink.exe -ssh [ip address] -P [database port] -i [private key location] -N -L [my port]:[id address]:[database port]
Thank you for your time.
I've now found the answer to this.
The information required was as follows and this is where it goes. Be really careful that you have actually put in all these values.
Settings:
Hostname (A2) - the name of this database It might be fine for this to be 127.0.0.1
User (A5) - Database username
Password (A6) - Database password
Port (A7) - The port the mySQL will be found at (e.g. 3306)
SSH:
SSH Host (B2) + Port (B3) - Your database IP and port number (ie 23.5.4.3 22)
Username (B4) - The username for your SSH login
Plink timeout (B6) - You may need to increase this (to perhaps 15)
Private key - Location of your private key file. Note that sometimes you might have a passphrase. If this is the case you'll probably have to use pageant which is downloaded with Putty
Local port - Which port you want your computer to use for SSH tunnel. eg 3306
These are some articles I found useful.
An article on similar topic
if you are stuck you could try and ssh in without heidi
Info about pageant
It seems the problem with Plink has been solved, can you give it a chance again?

Unable to connect to oracle database 11g R2

Till yesterday everything was working perfectly. There was an automatic windows update and after that I have been getting the error while trying to connect to my database from sqlplus:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Process ID: 0
Session ID: 0 Serial number: 0
I tried using the EM and there i got this:
Database Instance
Host
abc-PC
Port
1521
SID
mydb
Oracle Home
D:\app\abc\product\11.2.0\dbhome_1
Listener
Status
Down
Host
abc-PC
Port
1521
Name
LISTENER
Oracle Home
D:\app\abc\product\11.2.0\dbhome_1
Location
D:\app\kaos\product\11.2.0\dbhome_1\NETWORK\ADMIN
Details Although a Listener with name "LISTENER", is running on this host at port: "1521", it was not started using this target's "LISTENER.ORA" file.
CORRECTIVE ACTION: To monitor this "EM Listener Target" with its present configuration, you must stop the currently running listener process, and start it again using the Listener Parameter file: D:\app\kaos\product\11.2.0\dbhome_1\NETWORK\ADMIN/listener.ora .
Alternatively, you can update this target's "LISTENER.ORA Location" parameter with the location of the currently running Listener, which was started using: D:\app\abc\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora
What am I supposed to do to fix this?
Maybe update somehow remove ORACLE_SID environment variable. Check My Computer -> Properties -> Environment variables -> ORACLE_SID

Allow remote mysql access on linux (through webmin or shell)

Spec:
Ubuntu 14.04
webmin/virtualmin 1.791
I am using following code to test remote mysql database connection:
<?php
$db_host = "123.456.789";
$db_name = "database";
$db_user = "user";
$db_pass = "password";
$db_table_prefix = "prefix_";
GLOBAL $errors;
GLOBAL $successes;
$errors = array();
$successes = array();
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);
GLOBAL $mysqli;
if(mysqli_connect_errno()) {
echo "Conn Error = " . mysqli_connect_error();
exit();
}
?>
I keep getting this error:
No connection could be made because the target machine actively
refused it.
Research shows this means the server is "not listening". Before I ran the above script I've already tried to allow remote mysql access through webmin gui. What I did is editting "database manage->host permissions" and make it as follows:
This was supposed to allow remote mysql access but it doesn't work. Also I read from somewhere else that to allow remote mysql access I need to edit /etc/mysql/my.cnf; I have thought that after I edit the "host permissions" in webmin this file would be changed, but it was not. On the other hand, I couldn't find the lines I was supposed to edit in my.cnf, so I am stuck here.
Any help is appreciated.
You can do this via webmin too,
Create your user account for remote access
Webmin > Servers > MySQL Database Server > User permissions
Allow the MySQL server to listen to remote requests
Webmin > Servers > MySQL Database Server > MySQL Server Configuration
MySQL server listening address - set it to any
Restart MySQL using service mysql restart or directly from webmin.
Allowing MySQL to listen to any port is not a good idea , unless you are the only one who can access that network ,
Don't leave it like this afterwards , Its better to Allow certain hosts on certain domains , like your IP , Or simply just dont listen on all ports if its not required i.e when you are finished with your session.
You can also do this via /etc/mysql/my.cnf
Just add a binding adress of your choice instead of localhost
I have got it to work, however not through webmin at all.
First I need to comment out the following line in /etc/mysql/my.cnf:
#bind-address = 127.0.0.1
I guess instead of simply commenting it out, I can also change 127.0.0.1 to my local IP address. Many google results stop here, but this is not enough. The next step is to grant the local user privileges: On remote server, I need to run the following commands:
$ mysql -u root -p
Enter password:
mysql> use mysql
mysql> GRANT ALL ON . to user#'localIP' IDENTIFIED BY
'password';
mysql> FLUSH PRIVILEGES;
Actually I have seen this when I was doing google search before I asked the question here, but I just ignored it because I thought I've done it. It turns out I not only need to grant privileges on server side but also need to do it for "local user".
Feel free to comment here if there's still something I missed out or you know how to do it throught webmin(I am still wondering what editting "host permissions" in webmin does).

createuser could not connect to database postgres

Please don't move this question to askubuntu as I think this question is not OS-specific.
When I invoke the createuser postgres command (for now it doesn't matter if I provide any parameters or not), I'm getting this error:
createuser: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Normally it means that the postgres server is down but not this time:
pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
9.4 main 5432 online postgres /var/lib/postgresql/9.4/main /var/log/postgresql/postgresql-9.4-main.log
sudo service postgresql status
9.4/main (port 5432): online
But it's true that there is no /tmp/.s.PGSQL.5432 file because my configuration file (/etc/postgresql/9.4/main/postgresql.conf) has this line:
unix_socket_directories = '/var/run/postgresql'
So I don't really understand why createuser whants to access /tmp/.s.PGSQL.5432? Can this path can be hardcoded into the createuser binary? I don't see any command line argument to specify the settings file location for createuser...
Have you started the service?
service postgresql start
The postgresql.conf file is read by the database server, but not by client applications (such as createuser, psql, ...). (In fact, the server configuration file cannot be read by client applications because the client would have to connect to the server, which could be halfway across the world, before it could possibly know where that configuration file lives).
Instead, you have to tell your client application where to find the socket directory.
If your client application (createuser) is connecting to the local host (which is must be because you are not specifying a different host), you use the host parameter to specify the name of the socket directory.
For example:
createuser -h /var/run/postgresql newusername
See http://www.postgresql.org/docs/devel/static/libpq-connect.html#LIBPQ-CONNECT-HOST
Hope that helps.

Resources