I'm trying to install vanilla forums on my Mac, and for this I just created a database and a user from the MySQL command line:
mysql> CREATE DATABASE vanilla;
Query OK, 1 row affected (0.00 sec)
mysql> create user 'vanilla_user3'#'localhost' IDENTIFIED BY 'vanilla_password';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON * . * TO 'vanilla_user3'#'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
So I try to connect using the following code:
$con=mysqli_connect("localhost","vanilla_user3","vanilla_password","vanilla");
if (mysqli_connect_errno($con)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
but unfortunately, I get an error saying
Warning: mysqli_connect(): (HY000/2002): No such file or directory in /Users/kramer65/Sites/vanilla/info.php on line 3
Failed to connect to MySQL: No such file or directory
Any idea where I'm going wrong?
Alright, I just found the solution. The problem turned out to be that the host shouldn't have been localhost, but 127.0.0.1. I always thought localhost and 127.0.0.1 was the same, but it turned out to be different.
So maybe as a tip for future users, always use the ip when in doubt.
I had the same problem but the issue was something related to php.ini file.
I had to edit these two lines in /etc/php.ini (or wherever your php.ini is located):
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock
Restart apache server to make sure the changes are reflected.
sudo apachectl restart
If using docker use the mysql container name as host name of mysql. For example if this is the docker compose file:
mysqldb:
image: mysql:5.7.22
container_name: mysqlHost
ports:
- "33099:3306"
Host name will be mysqlHost and port will be 3306 and not 33099!
If you are not using docker compose, docker ps reveals the running container names.
On a different note, to connect mysql server on the host machine from docker, connect to host.docker.internal:
$conn = mysqli_connect("host.docker.internal", "mysqluser", "mysqlpass", "dbname");
Let's say your MAMP MySQL Port is set to 8889 like it is by default. Sometimes localhost alone is not enough in which case you have to put the MySQL port in there too so you would do localhost:8889 or localhost:{whatever your MySQL port number is}. I'm still new to MySQL so I don't know the reason why, but to anyone out there who recently got the message: Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in ... adding the MySQL port number onto localhost was the fix for me.
find php.ini file in /opt/lampp/etc/
then edit:
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock
after this in your DB connect file change from localhost to 127.0.0.1. everything will be ok. however, if you attempted the config.inc.php file, make sure its all set to 127.0.0.1, not localhost.
set port in host:
$con = mysqli_connect("localhost:**3306**","vanilla_user3","vanilla_password","vanilla");
Related
I'm trying to install vanilla forums on my Mac, and for this I just created a database and a user from the MySQL command line:
mysql> CREATE DATABASE vanilla;
Query OK, 1 row affected (0.00 sec)
mysql> create user 'vanilla_user3'#'localhost' IDENTIFIED BY 'vanilla_password';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON * . * TO 'vanilla_user3'#'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
So I try to connect using the following code:
$con=mysqli_connect("localhost","vanilla_user3","vanilla_password","vanilla");
if (mysqli_connect_errno($con)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
but unfortunately, I get an error saying
Warning: mysqli_connect(): (HY000/2002): No such file or directory in /Users/kramer65/Sites/vanilla/info.php on line 3
Failed to connect to MySQL: No such file or directory
Any idea where I'm going wrong?
Alright, I just found the solution. The problem turned out to be that the host shouldn't have been localhost, but 127.0.0.1. I always thought localhost and 127.0.0.1 was the same, but it turned out to be different.
So maybe as a tip for future users, always use the ip when in doubt.
I had the same problem but the issue was something related to php.ini file.
I had to edit these two lines in /etc/php.ini (or wherever your php.ini is located):
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock
Restart apache server to make sure the changes are reflected.
sudo apachectl restart
If using docker use the mysql container name as host name of mysql. For example if this is the docker compose file:
mysqldb:
image: mysql:5.7.22
container_name: mysqlHost
ports:
- "33099:3306"
Host name will be mysqlHost and port will be 3306 and not 33099!
If you are not using docker compose, docker ps reveals the running container names.
On a different note, to connect mysql server on the host machine from docker, connect to host.docker.internal:
$conn = mysqli_connect("host.docker.internal", "mysqluser", "mysqlpass", "dbname");
Let's say your MAMP MySQL Port is set to 8889 like it is by default. Sometimes localhost alone is not enough in which case you have to put the MySQL port in there too so you would do localhost:8889 or localhost:{whatever your MySQL port number is}. I'm still new to MySQL so I don't know the reason why, but to anyone out there who recently got the message: Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in ... adding the MySQL port number onto localhost was the fix for me.
find php.ini file in /opt/lampp/etc/
then edit:
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock
after this in your DB connect file change from localhost to 127.0.0.1. everything will be ok. however, if you attempted the config.inc.php file, make sure its all set to 127.0.0.1, not localhost.
set port in host:
$con = mysqli_connect("localhost:**3306**","vanilla_user3","vanilla_password","vanilla");
I'm trying to make a MySQL database on my Raspberry Pi 4, but it isn't going very well, using localhost instead works perfectly but I want to remote control it from my Windows 10 computer on the same internet. When I create a user with the address of 192.168.1.15 by doing this:
sudo mysql -u root
CREATE USER 'lasse'#'192.168.1.15' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'lasse'#'192.168.1.15';
FLUSH PRIVILEGES
exit
I try to login again using this:
mysql -u lasse -h 192.168.1.15 -ppassword // didnt work, error: ERROR 2002 (HY000): Can't connect to MySQL server on '192.168.1.15' (115)
mysql -u user -h 192.168.1.2 -P 3306 -ppassword // didnt work either, same error.
I have these packages installed:
mariadb-client
mariadb-server
default-mysql-server
In the file /etc/mysql/mariadb.conf.d/50-server.cnf (Raspi-os 2021-03-04 with MariaDB installed), you should replace the line "bind-address = 127.0.0.1" (localhost) by "bind-address = 0.0.0.0" (all). After, you should restart your MySQL server : $ sudo service mariadb restart
Error 115 is returned from socket operation (EINPROGRESS), which means that your client can't physically connect to the specified server and port.
The MariaDB database server is not configured correctly, since it doesn't accept remote connections. Please login locally and check the following variables:
SHOW VARIABLES LIKE 'skip_networking' (result should be off)
SHOW VARIABLES LIKE 'bind-address' (should not be 127.0.0.1)
Since these are read only variables, you need to change them (or comment them out with a #) in your my.cnf configuration file.
ERROR 2002 is "Can't connect" error. Check out /etc/my.cnf, look for listen line. It may be listening localhost or 127.0.0.1. You need to change it to listen 0.0.0.0.
There are three things
You need to set the bind-address to 0.0.0.0 (or 192.168.1.15 to be exact and specific)
You might need to set the firewall to allow port 3306 ( or iptables --flush as shortcut )
You need to create a global user (root#'%') in the mysql database or some user like 'root#192.168.1.15' with a password
when all conditions are fulfilled, you should be able to connect to mysql database on 192.168.1.15
What is most likely the case is that the server is not listening on port 3306. As in both lines you implicit or explicit use port 3306. As it is the only constant in the two lines most likely the culprit.
The default port for clients is specified in my.ini in the [client] section, the port used by the server is in the [mysqld] section. They don't necessarily have be the same so check both.
To make absolutely sure what is going on the server — assuming it is linux — use this to list all listening ports:
sudo netstat -tnlp
There, saved you a walk to the docs.
Login to the MariaDb server and edit the file /etc/mysql/my.cnf
Edit the row bind-address=YOUR_SERVER_IP
Restart the server using '/etc/init.d/mariadb restart' or 'systemctl restart mariadb.service'
MySQL 5.1.31 running on Windows XP.
From the local MySQL server (192.168.233.142) I can connect as root as follows:
>mysql --host=192.168.233.142 --user=root --password=redacted
From a remote machine (192.168.233.163), I can see that the mysql port is open:
# telnet 192.168.233.142 3306
Trying 192.168.233.142...
Connected to 192.168.233.142 (192.168.233.142).
But when trying to connect to mysql from the remote machine, I receive:
# mysql --host=192.168.233.142 --user=root --password=redacted
ERROR 1045 (28000): Access denied for user 'root'#'192.168.233.163' (using password: YES)
I have only 2 entries in mysql.user:
Host User Password
--------------------------------------
localhost root *blahblahblah
% root [same as above]
What more do I need to do to enable remote access?
EDIT
As suggested by Paulo below, I tried replacing the mysql.user entry for % with an IP specific entry, so my user table now looks like this:
Host User Password
------------------------------------------
localhost root *blahblahblah
192.168.233.163 root [same as above]
I then restarted the machine, but the problem persists.
You have to put this as root:
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'#'IP' IDENTIFIED BY 'PASSWORD' with grant option;
;
where IP is the IP you want to allow access, USERNAME is the user you use to connect, and PASSWORD is the relevant password.
If you want to allow access from any IP just put % instead of your IP
and then you only have to put
FLUSH PRIVILEGES;
Or restart mysql server and that's it.
I was getting the same error after granting remote access until I made this:
From /etc/mysql/my.cnf
In newer versions of mysql the location of the file is
/etc/mysql/mysql.conf.d/mysqld.cnf
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
(comment this line: bind-address = 127.0.0.1)
Then run service mysql restart.
By default in MySQL server remote access is disabled. The process to provide a remote access to user is.
Go to my sql bin folder or add it to PATH
Login to root by mysql -uroot -proot (or whatever the root password is.)
On success you will get mysql>
Provide grant access all for that user.
GRANT ALL PRIVILEGES ON *.* TO 'username'#'IP' IDENTIFIED BY 'password';
Here IP is IP address for which you want to allow remote access, if we put % any IP address can access remotely.
Example:
C:\Users\UserName> cd C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin
C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin>mysql -uroot -proot
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.27 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.25 sec)
This for a other user.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'testUser'#'%' IDENTIFIED BY 'testUser';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
Hope this will help
Paulo's help lead me to the solution. It was a combination of the following:
the password contained a dollar sign
I was trying to connect from a Linux shell
The bash shell treats the dollar sign as a special character for expansion to an environment variable, so we need to escape it with a backslash. Incidentally, we don't have to do this in the case where the dollar sign is the final character of the password.
As an example, if your password is "pas$word", from Linux bash we must connect as follows:
# mysql --host=192.168.233.142 --user=root --password=pas\$word
Do you have a firewall ? make sure that port 3306 is open.
On windows , by default mysql root account is created that is permitted to have access from localhost only unless you have selected the option to enable access from remote machines during installation .
creating or update the desired user with '%' as hostname .
example :
CREATE USER 'krish'#'%' IDENTIFIED BY 'password';
Try to flush privileges again.
Try to restart server to reload grants.
Try create a user with host "192.168.233.163". "%" appears to not allow all (it's weird)
In my case I was trying to connect to a remote mysql server on cent OS. After going through a lot of solutions (granting all privileges, removing ip bindings,enabling networking) problem was still not getting solved.
As it turned out, while looking into various solutions,I came across iptables, which made me realize mysql port 3306 was not accepting connections.
Here is a small note on how I checked and resolved this issue.
Checking if port is accepting connections:
telnet (mysql server ip) [portNo]
Adding ip table rule to allow connections on the port:
iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
Would not recommend this for production environment, but if your iptables are not configured properly, adding the rules might not still solve the issue. In that case following should be done:
service iptables stop
Hope this helps.
if you are using dynamic ip just grant access to 192.168.2.% so now you dont have to worry about granting access to your ip address every time.
I was struggling with remote login to MYSQL for my Amazon EC2 Linux instance. Found the solution was to make sure my security group included an inbound rule for MySQL port 3306 to include my IP address (or 0.0.0.0/0 for anywhere). Immediately could connect remotely as soon as I added this rule.
MySQL ODBC 3.51 Driver is that special characters in the password aren't handled.
"Warning – You might have a serious headache with MySQL ODBC 3.51 if the password in your GRANT command contains special characters, such as ! # # $ % ^ ?. MySQL ODBC 3.51 ODBC Driver does not support these special characters in the password box. The only error message you would receive is “Access denied” (using password: YES)" - from http://www.plaintutorials.com/install-and-create-mysql-odbc-connector-on-windows-7/
The user/host combination may have been created without password.
I was assuming that when adding a new host for an existing user (using a GUI app), the existing password would also be used for the new user/host combination.
I could log in with
mysql -u username -p PASSWORD
locally, but not from IPADDRESS with
mysql -u --host=HOST -p PASSWORD
(I could actually log in from IPADDRESS without using a password)
mysql -u --host=HOST
Setting the password allowed access:
set password for '<USER>'#'<IPADDRESS>' = '<PASSWORD>';
New location for mysql config file is
/etc/mysql/mysql.conf.d/mysqld.cnf
My case is absolutely simple.
You may have this problem in case if you type in WRONG password. No create user is needed (user already existed), no other permissions. Basically make sure that the password is correct. So make double-sure the password is correct
I'm getting connection refused every time I try to connect to MySQL server on Vagrant's ScotchBox.
I've doubled checked my username / password combinations but still no access.
I can't seem to find the problem.
First of all you should read the rules to get used to the site.
Regarding your problem: ScotchBox doesn't allow remote connections to MySQL server out of the box. You'll need to do the following steps:
Edit the /etc/mysql/my.cnf and comment the line 47 from:
bind-address = 127.0.0.1
to
#bind-address = 127.0.0.1
Update MySQL user table doing:
mysql> USE mysql;
mysql> UPDATE user SET host='%' WHERE user='root' AND host='127.0.0.1';
Restart MySQL service.
You should now be able to connect to MySQL server.
I know this type of question has been asked lots of times, but none answer my problem.
Please read carefully.
I was running my website on localhost using Wamp server normally. When today i decided to run an Acunetix scan for vulnerabilities on my localhost server.
Acunetix sent tons of commands to the mysql table in short period of time ( since it's localhost the commands went fast ) which cause my mysql server to crash with the error:
#1130 - Host 'localhost' is not allowed to connect to this MySQL server
What I've already tried:
Running mysql through mysqld --skip-grant-tables
I had access to mysql while on that, so I tried running
DROP USER 'root'#'127.0.0.1'; GRANT ALL PRIVILEGES ON . TO 'root'#'%';
But I got the error:
mysql> DROP USER 'root'#'127.0.0.1'; GRANT ALL PRIVILEGES ON . TO 'root'#'%';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables opt
ion so it cannot execute this statement
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'TO 'r
oot'#'%'' at line 1
I admit I do am a mysql noob but I did my homeworks and searched google, but was unable to find the solution.
Any help ?
I managed ti fix the issue by reinstalling wamp server and fully uninstalling, even with the mysql.
A simple Illustrated solution!
I had the same issue.
You can add skip-grant-tables to the my.ini file for the [mysqld] tag, under # The MySQL server, and restart the mysql server.
You can now open phpmyadmin and go to the user table in the mysql database. Make sure that the value of the password attribute is empty and that the value of host attribute is localhost. I was facing the second error. PHPMyAdmin was trying to connect with host value as 'localhost' and the table contained the value 127.0.0.1.
Remove skip-grant-tables from my.ini and restart the mysql server. This should work.
When your server is running with --skip-grant-tables, you disable all MySQL security so you're not allowed GRANT commands. What you can do, is access the "mysql" database and directly SELECT and UPDATE the rows you need to change. In your case it will be the user table.
GRANT ALL PRIVILEGES ON *.* TO 'root'#'127.0.0.1';
http://dev.mysql.com/doc/refman/5.1/en/adding-users.html
EDIT.
this because your mysql server is on read_only option. to turn it off
connect to the server with root user:
mysql-h localhost-u root-p
and run the command:
mysql> set GLOBAL read_only = false;
mysql> FLUSH TABLES WITH READ LOCK;
mysql> UNLOCK TABLES;
EDIT2;
you must have stop the server and run this
mysqld_safe --skip-grant-tables due to root pwd chg
so stop the server and start it normal with a start
Click on config show in image
Click my.ini show in image
add skip-grant-tables after [mysqld] and save show in image. (*edited spelling issue here)
Now restart mySQL. that's all
I solved the issue by reinstalling the server.
The new configuration (my.ini) does not contain the --skip-grant-tables option and I am able to connect to the server as expected.
Don't forget to backup your databases before you do the new installation.