So I have MySQL install via homebrew and have edited my.cnf to look like below. I've added mysql and mysql2 directories to /usr/local/var/ which hold the data for the databases and installed a second mysql server configured to use /usr/local/var/mysql2
[mysqld_multi]
mysqld = /usr/local/Cellar/mysql/5.6.24/bin/mysqld_safe
mysqladmin = /usr/local/Cellar/mysql/5.6.24/bin/mysqladmin
log = /var/log/mysqld_multi.log
user = root
password = password
[mysqld1]
socket = /tmp/mysql.sock1
port = 3306
pid-file = /usr/local/var/mysql/mysqld1.pid
datadir = /usr/local/var/mysql/
language = /usr/local/Cellar/mysql/5.6.24/share/mysql/english
user = root
[mysqld2]
socket = /tmp/mysql.sock2
port = 3308
pid-file = /usr/local/var/mysql2/mysqld2.pid
datadir = /usr/local/var/mysql2/
language = /usr/local/Cellar/mysql/5.6.24/share/mysql/english
user = root
The problem is that when I start the servers like so:
mysqld_multi start --user=root --password=password
I see that both of them are instantiated when i run
mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
When I individually start/stop 1/2 both start/stop and in /usr/local/var/mysql the .pid file is generated using my local username not mysqld1.pid and in /usr/local/var/mysql2 there is no .pid file created. I can connect to the database using:
mysql -h 127.0.0.1 -P 3306 -u root -ppassword
However I cannot connect on port 3308
running nmap tells me:
nmap -p 3308 127.0.0.1
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00011s latency).
PORT STATE SERVICE
3308/tcp closed unknown
Not sure what is going on here any help would be greatly appraciated.
My_print_defaults have to be executed as follows to produce any output:
my_print_defaults --defaults-file=/usr/local/Cellar/mysql/5.6.24/my.cnf client mysqld1
--socket=/tmp/mysql.sock1
--port=3306
--pid-file=/usr/local/var/mysql/mysqld1.pid
--datadir=/usr/local/var/mysql/
--language=/usr/local/Cellar/mysql/5.6.24/share/mysql/english
--user=root
my_print_defaults --defaults-file=/usr/local/Cellar/mysql/5.6.24/my.cnf client mysqld2
--socket=/tmp/mysql.sock2
--port=3308
--pid-file=/usr/local/var/mysql2/mysqld2.pid
--datadir=/usr/local/var/mysql2/
--language=/usr/local/Cellar/mysql/5.6.24/share/mysql/english
--user=root
Related
Server ip: 172.16.1.169
mysql user name: root
passwd: xxxxxxxxxx
database name: example
I'm trying to access a database from a client (ip 172.16.0.114). Both the server and client are running the Fedora distribution of Linux. What settings need to be configured, and what should they be set to, for both the server and client? How do I access a specific database (here, "example")? I tried but I got an error:
ERROR 2003 (HY000): Can't connect to MySQL server on '172.16.1.169'.
That error message is generated by the client (not the server) because a connection to the server has been attempted but the server could not be reached.
There are various possible causes to that:
1) check that mysqld is running on the server:
ps -ef | grep mysqld
should return something like:
root 2435 2342 0 15:49 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/var/ --user=mysql
mysql 2480 2435 0 15:49 pts/1 00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/var/ --user=mysql ...
To run the daemon service, run on redhat/fedora/centos:
service mysqld start
or on Fedora release >= 16, which relies on systemd:
systemctl start mysqld.service
and for enabling daemon auto-startup at system boot:
systemctl enable mysqld.service
2) check the port on which mysqld is running on the server:
netstat -lnp | grep mysql
should return:
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2480/mysqld
unix 2 [ ACC ] STREAM LISTENING 8101 2480/mysqld /tmp/mysql.sock
the latter is the socket for local connections, the first the tcp port for networking (default 3306). If the port is not the default port, you must set the connection port on the client. If using mysql client:
mysql dbname -uuser -ppasswd -P<port> ...
3) being on a different net address, check that the server listens for the net addrees your are connecting from: in file /etc/my.cnf search for the line:
bind_address=127.0.0.1
if the address is 127.0.0.1 only local connections are allowed; if it were 172.16.1.0, you could not connect from 172.16.2.xxx
4) check that on the server there is no firewall running and blocking connections to mysql port (3306 is the default port); if it's a redhat/fedora/centos run
service iptables status
Open MySQL config file
sudo vim my.cnf
Ensure that the following are commented out.
#skip-external-locking
#skip-networking
#bind-address = xx.xx.xx.xx
Save and exit
Restart mysql service
In MySQL config file (/etc/mysql/my.cnf) comment '#bind-address = 127.0.0.1'
Save and restart mysql service.
I think the destination mysql server might use a different port.
You have to find the correct port first.
Once you get the correct port you can connect to that mysql server by using this command:
mysql -h 172.16.1.169 -P (port) -u root -p (password)
I'm using AWS server (ubuntu) for backup my remote mysql db, using mysqldump command.
Since I changed the db password, I cannot connect anymore remotely from the machine using /etc/mysql/my.cnf configuration file.
When I'm using the command
mysql -u root -h 1.1.1.1 -p 123456
It's connects successfully, but when I'm trying to connect by using the mysql configuration file /my.cnf by typing just
mysql
I gets the error message :
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I restarted the db server (I don't need mysql service running on aws because I connected remotely)
I don't want to connect through any socket
my.cnf file content:
[client]
port = 3306
host = 1.1.1.1
user = root
password = 123456
[mysqld]
user = mysql
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
bind-address = 1.1.1.1
I don't know what have changed, except from the password, I didn't change anything neither in the db itself and in the config file, so I have no idea why it stopped working.
Add in the my.cnf the line protocol=tcp
[client]
port = 3306
host = 1.1.1.1
user = root
password = 12345
protocol = tcp
That force MySQL to use TCP and not the socket connection
I am trying to grant remote access to a mysql database. However I think I am missing a step somewhere.
Server is a VM - Ubuntu 12.04.5 - inet addr:134.226.38.147
mysql Ver 14.14 Distrib 5.5.38, for debian-linux-gnu (x86_64) using readline 6.2
Firstly I create the database on the remote server. I then grant wildcard access to all databases and tables for the user brendan. By using '%' I should have no problem connecting from my computer in college.
mysql> CREATE DATABASE foo;
mysql> GRANT ALL ON *.* TO 'brendan'#'%' IDENTIFIED BY 'mypassword';
I then open the port using
iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
iptables-save | tee /etc/sysconfig/iptables
From what I read the above should work, however when I try to test the connection from my desktop this is what I get
localhost:~ brendan$ mysql -u brendan -h 134.226.38.147 -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '134.226.38.147' (61)
localhost:~ brendan$
or
localhost:~ brendan$ echo X | telnet -e X 134.226.38.147 3306
Telnet escape character is 'X'.
Trying 134.226.38.147...
telnet: connect to address 134.226.38.147: Connection refused
telnet: Unable to connect to remote host
localhost:~ brendan$
What am I missing?
Any help is much appreciated.
EDIT
my.cnf
I was unsure If I should comment out the bind-address = 127.0.0.1 which was already there
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# 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
# ---- You added the below line ----------
bind-address = 134.226.38.147
I then restart with
sudo service mysql restart
Open your my.cnf file:
sudo vim /etc/mysql/my.cnf
Comment out the bind-address in your my.cnf.
like so: #bind-address = 127.0.0.1
Then restart mysql server so that the changes to the my.cnf file will take affect.
sudo service mysql restart
or
sudo /etc/init.d/mysql restart
You can read more here at DigitalOcean or rtcamp.
Now, a user will be able to connect to the Mysql database server remotely as long as they have proper user credentials.
When i access MySql from mysql bin folder command prompt then its working fine. but when go with cmd to access localhost:8080 then its not working properly. I use this command for it:
C:\wamp\bin\mysql\mysql5.6.12\bin> mysql -u root -p -h localhost:8080
Is mysql really listening on port 8080? Shouldn't it be 3306?
Take a look into my.ini and check the definition in the [mysqld] section:
[mysqld]
; ...
port = 3306
; ...
you need to change MySQL default port 3306 to 8080.Find the find MySQL configuration file, in general "my.ini" than edit the line:
[mysqld]
port = 3306
to
[mysqld]
port = 8080
Then restart MySQL service, it's done.
I have XAMPP running on my desktop and can connect to the MySQL server via phpMyAdmin. However, when I try to connect through Cygwin:
Error: Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)
I've tried connecting to MySQL on the same machine, my local dev server and my remote server, all failed.
mysql -h 127.0.0.1 -P <PORT> -u root -p
This is what worked for me. Make sure you check what is the correct port.
Check the mysqld PID with:
ps -sW | grep mysqld
And then find the PORT with:
netstat -nao | grep <PID>
Have fun!
you can also add the alias of itself.
alias mysql = 'mysql -u {user} -p{password} -h 127.0.0.1'