I have installed MariaDB 10.5.5 in Ubuntu 20.04 server. Right now I try to change the default port of the database to let say 12345. When I look into /etc/mysql/my.cnf and /etc/mysql/mariadb.conf.d/50-server.conf there is no port options, then I add port = 5505 inside /etc/mysql/mariadb.conf.d/50-server.conf under [mysqld], then I restart the mariadb-server using sudo systemctl restart mysql & sudo systemctl restart mariadb. But when I connect the mariadb server using mysql -uusername -p, it's just connected. The expected behavior is mysql client will reject the connection. I also try to use mysql -uusername -p -P123222, but still connected. My questions is how can I can change the port and prevent this strange behavior to happen?
Unless you don't specify a hostname, the default hostname "localhost" will be assumed, so the connection will be established via unix_socket and not via TCP/IP.
To connect via port use e.g.
mysql -h127.0.0.1 -P12345 -uusername -p
There are 2 places, at least, where you may find the
port = 3306
Make sure you are changing them all, but specifically the one under the section [mysqld]
[mysqld]
port = 3307
It is this one that tells the deamon which port to use.
My guess is you changed the one under [client]
So change both :)
Related
I have 2 mysqld.exe, one from phpMyAdmin and one from MySQL server. I use the command line command "mysql -u root -p" to connect, how do i get this command to connect to MySQL server (port 3307) by default, instead of phpMyAdmin (port 3306). It is fine to add "-P 3307", but I only want to use the command "mysql -u root -p". This command("mysql -u root -p") used to connect to port 3307, i don't know what made it change.
How can i connect to port 3307 by default.
Edit my.cnf and add port 3307 (or the one you want to be defaulted), then restart the service and you should be good.
on my.cnf be sure to have this:
port=3307
to find my.cnf file in linux or windows bash use:
sudo find / -name "my.cnf"
OS: Linux
I'm trying to start mysql on port 1561 on the localhost using this command:
/appl/mysql/5.6.14/bin/mysqld_safe
--defaults-file=/appl/mysql/5.6.14/my.cnf --ledir=/appl/mysql/5.6.14/bin/ --socket=/tmp/mysql.sock
I already have port=1561 defined on my.cnf but somehow, the mysql service defaulted to 3306. Per checking on netstat command, mysql listens on port 3306 instead of 1561.
We managed to fix this by using below command, but I want to know the chances of the above scenario happening again and how we can avoid it.
command used to fix:
./mysql.server stop
./mysql.server start
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'
The followings are commands which I have executed on Ubuntu.
$ mysql -u root -p
mysql>GRANT ALL ON my_database.* TO user#'MY_REAL_IP' IDENTIFIED BY 'passwd';
$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
#bind-address = 127.0.0.1
$ sudo ufw enable
$ sudo ufw allow 3306
$ service mysql restart
But when I use another computer on Ubuntu to access mysql on MY_REAL_IP type:
$ mysql -u user -p -h MY_REAL_IP
Can't connect to MySQL server on 'MY_REAL_IP'
how to fix it? thx
I guess bind-address should be 0.0.0.0. If you would like to access this server with real IP address. Or, you can access MySQL with simply localhost.
Would you please change bind-address = 0.0.0.0, and restart MySQL ?
EDIT
It looks there is no network connectivity. Please find the way to connect server with port 3306. How to make sure that firewall is off?
You may misunderstand the grand command, user#host means the user can login from host, which in your case, should be another computer's ip, or just use * for all ips
Exact path on Ubuntu 16.04
/etc/mysql/mysql.conf.d/my.cnf
bind-address = 0.0.0.0
service mysql restart
MySQL remote access
I have a mysql database, running on Ubuntu Server 12.04 that I need to access remotely. For some reason this is become much more of a chore than I think it should be.
I have been through countless threads trying to resolve this issue with no luck what so ever. I do not have another linux box to test my connection. I am only using the MySQL Workbench from a Window 7 machine.
Here is what I have done so far:
set the iptables to accept
set the my.cnf to have the bind address of the server
created a user for both localhost and %
grant all to those users
restarted mysql
verified the user has all priv
verified mysql is listening on 3306
give the correct setting to Workbench and I get
"Your connection attempt failed for user 'USER' from your host to server at x.x.x.x:3306:
Can't connect to MySQL server on 'x.x.x.x' (10061)"
EDIT: I did notice that it show 'localhost and NOT the ipaddress when I run this cmd, but i'm not sure how to change that, or if it is even the issue. Thoughts?
# lsof -i -P | grep :3306
mysqld 5775 mysql 10u IPv4 154265 0t0 TCP localhost:3306 (LISTEN)
vim /etc/mysql/my.cnf
Change the following line to reflect as below:
(bind-address = 127.0.0.1)
bind-address = 0.0.0.0
Close the file then and restart mysql
To verify that mysql port 3306 is listening on all interfaces:
netstat -lnt | grep 3306
You should see this:
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
Find mysql config file (/etc/mysql/)
comment out the following line by putting a hash character in front of it as shown -> #bind-address = 127.0.0.1
-> Restart the server: sudo service mysql restart