2016-04-13 64 views
1

我已經在遠程RHEL機器上安裝了XAMPP。假設這臺機器的IP地址是10.120.42.70。我已配置文件/opt/lampp/etc/my.cnf進行遠程訪問,並已將此文件移動到/etc/my.cnf,以便此文件中的設置現在是mysql服務器的全局選項。無法從本地Windows連接到RHEL上的遠程MySQL服務器

這裏是我的/etc/my.cnf文件

# Example MySQL config file for medium systems. 
# 
# This is for a system with little memory (32M - 64M) where MySQL plays 
# an important part, or systems up to 128M where MySQL is used together with 
# other programs (such as a web server) 
# 
# You can copy this file to 
# /etc/my.cnf to set global options, 
# mysql-data-dir/my.cnf to set server-specific options (in this 
# installation this directory is /opt/lampp/var/mysql) or 
# ~/.my.cnf to set user-specific options. 
# 
# In this file, you can use all long options that a program supports. 
# If you want to know which options a program supports, run the program 
# with the "--help" option. 

# The following options will be passed to all MySQL clients 
[client] 
#password = your_password 
port  = 3306 
socket  = /opt/lampp/var/mysql/mysql.sock 

# Here follows entries for some specific programs 

# The MySQL server 
[mysqld] 
user = mysql 
port=3306 
socket  = /opt/lampp/var/mysql/mysql.sock 
#skip-external-locking 
key_buffer = 16M 
max_allowed_packet = 1M 
table_open_cache = 64 
sort_buffer_size = 512K 
net_buffer_length = 8K 
read_buffer_size = 256K 
read_rnd_buffer_size = 512K 
myisam_sort_buffer_size = 8M 
bind-address = 0.0.0.0 


# Where do all the plugins live 
plugin_dir = /opt/lampp/lib/mysql/plugin/ 

# Don't listen on a TCP/IP port at all. This can be a security enhancement, 
# if all processes that need to connect to mysqld run on the same host. 
# All interaction with mysqld must be made via Unix sockets or named pipes. 
# Note that using this option without enabling named pipes on Windows 
# (via the "enable-named-pipe" option) will render mysqld useless! 
# 
# commented in by xampp security 


# Replication Master Server (default) 
# binary logging is required for replication 
# log-bin deactivated by default since XAMPP 1.4.11 
#log-bin=mysql-bin 

# required unique id between 1 and 2^32 - 1 
# defaults to 1 if master-host is not set 
# but will not function as a master if omitted 
server-id = 1 

# Replication Slave (comment out master section to use this) 
# 
# To configure this host as a replication slave, you can choose between 
# two methods : 
# 
# 1) Use the CHANGE MASTER TO command (fully described in our manual) - 
# the syntax is: 
# 
# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>, 
# MASTER_USER=<user>, MASTER_PASSWORD=<password> ; 
# 
# where you replace <host>, <user>, <password> by quoted strings and 
# <port> by the master's port number (3306 by default). 
# 
# Example: 
# 
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306, 
# MASTER_USER='joe', MASTER_PASSWORD='secret'; 
# 
# OR 
# 
# 2) Set the variables below. However, in case you choose this method, then 
# start replication for the first time (even unsuccessfully, for example 
# if you mistyped the password in master-password and the slave fails to 
# connect), the slave will create a master.info file, and any later 
# change in this file to the variables' values below will be ignored and 
# overridden by the content of the master.info file, unless you shutdown 
# the slave server, delete master.info and restart the slaver server. 
# For that reason, you may want to leave the lines below untouched 
# (commented) and instead use CHANGE MASTER TO (see above) 
# 
# required unique id between 2 and 2^32 - 1 
# (and different from the master) 
# defaults to 2 if master-host is set 
# but will not function as a slave if omitted 
#server-id  = 2 
# 
# The replication master for this slave - required 
#master-host  = <hostname> 
# 
# The username the slave will use for authentication when connecting 
# to the master - required 
#master-user  = <username> 
# 
# The password the slave will authenticate with when connecting to 
# the master - required 
#master-password = <password> 
# 
# The port the master is listening on. 
# optional - defaults to 3306 
#master-port  = <port> 
# 
# binary logging - not required for slaves, but recommended 
#log-bin=mysql-bin 


# Point the following paths to different dedicated disks 
#tmpdir  = /tmp/  
#log-update  = /path-to-dedicated-directory/hostname 

# Uncomment the following if you are using BDB tables 
#bdb_cache_size = 4M 
#bdb_max_lock = 10000 

# Comment the following if you are using InnoDB tables 
#skip-innodb 
innodb_data_home_dir = /opt/lampp/var/mysql/ 
innodb_data_file_path = ibdata1:10M:autoextend 
innodb_log_group_home_dir = /opt/lampp/var/mysql/ 
# You can set .._buffer_pool_size up to 50 - 80 % 
# of RAM but beware of setting memory usage too high 
innodb_buffer_pool_size = 16M 
# Deprecated in 5.6 
#innodb_additional_mem_pool_size = 2M 
# Set .._log_file_size to 25 % of buffer pool size 
innodb_log_file_size = 5M 
innodb_log_buffer_size = 8M 
innodb_flush_log_at_trx_commit = 1 
innodb_lock_wait_timeout = 50 

[mysqldump] 
quick 
max_allowed_packet = 16M 

[mysql] 
no-auto-rehash 
# Remove the next comment character if you are not familiar with SQL 
#safe-updates 

[isamchk] 
key_buffer = 20M 
sort_buffer_size = 20M 
read_buffer = 2M 
write_buffer = 2M 

[myisamchk] 
key_buffer = 20M 
sort_buffer_size = 20M 
read_buffer = 2M 
write_buffer = 2M 

[mysqlhotcopy] 
interactive-timeout 

!include /opt/lampp/mysql/my.cnf  

你可以看到skip-external-locking被註釋掉並沒有skip-networking線。 bind-address設置爲0.0.0.0,以便服務器將接受來自任何IP地址的連接。

我能夠使用這個從RHEL機器內登錄到MySQL服務器

mysql -h localhost -u root -p 
mysql -h 10.120.42.70 -u root -p 

上述兩個指令的正常工作,使我登錄到服務器

當我嘗試連接到從我的本地Windows計算機服務器這樣的:

mysql -h 10.120.42.70 -u root -p 

它要求的密碼,我給的密碼,但我得到的錯誤:

ERROR 2003 (HY000): Can't connect to MySQL server on '10.120.42.70' (10060 "Unknown error")

我已經授予用戶`root'的權限。我仍然得到同樣的錯誤。

在我的RHEL遠程機器上,我跑netstat,我得到這個:

sudo netstat -lntp | grep 3306 
    tcp  0  0 0.0.0.0:3306   0.0.0.0:*     LISTEN  16323/mysqld 

因此,MySQL服務器3306,無疑會聽取所有IP地址。我想知道爲什麼我仍然無法遠程訪問它。

+0

你是否得到了這個解決方案,因爲它聽起來類似於我遇到的問題? – Mathew

回答

0

您授予用戶'root'@'localhost'的權限嗎?如果是這樣,請嘗試將它們授予'root'@'%'。 MySQL用它的用戶名和主機名標識用戶。如果從另一臺計算機連接,您的root用戶將被標識爲root @ somehost而不是root @ localhost。

+1

這個答案不適用於OP的問題。 ''10.120.42.70''無法連接到MySQL服務器意味着與網絡相關的問題。對於你的情況,它會說一些關於權限。 – rkosegi

+0

我做到了。這是我使用的SQL查詢,它執行沒有任何錯誤 授予所有特權* * *'根'@'%'IDENTIFIED BY'我的密碼' – technOslerphile

1

如果您可以從Windows客戶端ping RHEL服務器,那麼我幾乎可以肯定這是一個防火牆問題。

MSDN

10060 Connection timed out.

A connection attempt failed because the connected party did not properly respond after a period of time, or the established connection failed because the connected host has failed to respond.

嘗試臨時禁用防火牆。

對於RHEL 6:

service iptables stop 

對於RHEL 7:

systemctl stop iptables 

systemctl stop firewalld 

是否有幫助,提供詳細信息有關哪些防火牆命令幫助,我可以點你如何將規則添加到防火牆,以便您可以再次啓用

UPDATE

可能解決方法是使用TCP隧穿通過SSH(如果允許由遠程SSH服務器)。

ssh [email protected] -L 5000:127.0.0.1:3306

這將轉發來自本地客戶機端口5000連接到遠程的本地主機端口3306

然後連接到MySQL服務器這樣的:mysql -uroot -h localhost:5000 -p

您可以選擇類似的本地端口,而不是的5000

+0

嗯,我檢查了sudo服務iptables狀態,它顯示'防火牆是沒有運行「。所以我猜這不是問題。無論如何,我試圖阻止iptables服務,然後嘗試從我的本地連接到MySQL服務器。它仍然給我同樣的錯誤 – technOslerphile

+0

@technOslerphile:你可以從任何其他客戶端連接到MySQL?你可以在Windows上從RHEL連接到SSH嗎? – rkosegi

+0

是的,我可以。我使用ssh進行所有服務器配置編輯和所有 – technOslerphile