使用windows-SQLyog連接linux-mysql


      嘿嘿,最近又清閑了一點,重新安裝了mysql去學習。  

-----博客園-邦邦醬好

 

系統環境:

1. 主機為windows系統,安裝了SQLyog。

2. 主機上還安裝了虛擬機,系統為centos6.4,里面安裝了mysql5.0.95。

 

連接步驟:

1. 打開虛擬機的centos系統,登陸mysql,以啟動mysql服務。

登陸方法大概如下:

[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.95-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

印象中可以設定某些文件,讓它每天定時自啟動的,沒仔細了解,就不細說了。

 

2. 檢查數據庫“mysql”的“user”表,看看root對應的host是否設置正確。

mysql> use mysql
Database changed
mysql> select user,password,host from user;
+---------+-------------------------------------------+------+
| user    | password                                  | host |
+---------+-------------------------------------------+------+
| root    | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | %    | 
| tester1 | 123                                       | %    | 
+---------+-------------------------------------------+------+
2 rows in set (0.00 sec)

mysql> 

注意:

(1)上文中root的host已經是%,意思是所有不同主機都可以連接到此處的mysql來,記得設置過表內容后,再接着在update語句下輸入:mysql> FLUSH PRIVILEGES命令來更新表內容,否則SQLyog是感受不到數據庫的改變的。

(2)其實%是不大安全的,理論上可以把host設置為主機win7系統的IP地址,這樣就只有本機可以連接它了,但是我試了,發現不能連上,提示如下,我也搞不懂了。

                         

(3)host在這里不能被設為localhost,因為主機的IP地址和虛擬機中系統的IP地址是不一樣的。可以使用ifconfig命令查看centos系統的IP地址,這里的我centos系統IP地址為:192.168.254.129。

[root@localhost ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:FE:DE:02  
          inet addr:192.168.254.129  Bcast:192.168.254.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fefe:de02/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:21330 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12326 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:28364229 (27.0 MiB)  TX bytes:757142 (739.3 KiB)
          Interrupt:19 Base address:0x2024 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:12 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:720 (720.0 b)  TX bytes:720 (720.0 b)

(4)如果把host設為localhost,那是因為mysql跟SQLyog是在同一個系統上安裝的,所以才行。

 

3. 在SQLyog里新建一個連接

注意:

(1)Saved Connects是你設定的連接名稱,可以隨意設定。

(2)MySQL Host Address是要連接的mysql所在的IP地址,如果mysql跟SQLyog安裝在同一個系統上,那就可以寫為:localhost。

(3)輸入登錄mysql所用的用戶名,密碼。

(4)其他信息默認即可。

 

4. 點擊連接connect,如果成功,即可看到如下數據庫結構:

左右對比可見連接后看到的數據庫名稱,跟服務器上的數據庫名稱是一樣的~~~

 

5. 如果還是連接失敗,提示:error no2003:can't connect to MYSQL SERVER 192.168.***(10060)

那有可能是由於mysql服務端的防火牆禁止了3306端口。

這時需要這樣做:
vi /etc/sysconfig/iptables 添加下面這一行數據:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306-j ACCEPT  

再重啟防火牆服務:service iptables restart 


ps:  iptables設置
1) 重啟后生效 
開啟: chkconfig iptables on 
關閉: chkconfig iptables off 

2) 即時生效,重啟后失效 
開啟: service iptables start 
關閉: service iptables stop

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM