English 中文(简体)
Linking MySQL Workbench to my Remote Server
原标题:

I ve just downloaded MySQL Workbench.

But I don t quite understand how to syn this with the databases on my remote server.

Work bench asks for "hostname" so I provided the hostname of my remote server. I designate port 3306.

I then provide a username. This is the username I use when I log into PhpAdmin -- should I be using a different one?

Then I provide a password, again the same one I use for PhpAdmin.

But this doesn t work.

Oddly, the error always tells me my user name is: username@current_network_im_using_to_access_the_internet

But this doesn t seem right -- on phpAdmin my user name says username@localhost.

I m not quite sure what to do.

Can you help me?

最佳回答

MySQL treats logins as specific to the host they originate from. You can have a different password from your home machine than the one you use on the server itself, and you can have entirely different sets of permissions granted to the same username from different origin hosts.

On PHPMyadmin, the database is running on the same server as the web server, and therefore refers to itself as localhost, with IP 127.0.0.1. Your machine on which Workbench is installed must access MySQL with different credentials than your username@localhost. The server requires you to grant access to your username from any host you intend to connect from.

In PhpMyAdmin, you will need to grant access to your database from the remote host: (See also Pekka s answer for how to allow connections from any host)

GRANT ALL PRIVILEGES on dbname.* TO yourusername@your_remote_hostname IDENTIFIED BY  yourpassword ;

To see all the grants you currently have on localhost so that you can duplicate them for the remote host:

SHOW GRANTS FOR yourusername@localhost;

Additionally, the MySQL server needs to be setup to accept remote connections in the first place. This isn t always the case, especially on web hosting platforms. In the my.cnf file, the skip-networking line has to be removed or commented out. If there is no skip-networking line, you must comment out the line:

bind-address = 127.0.0.1 

...then restart MySQL.

问题回答

Your phpMyAdmin seems to run on the same server as the database itself.

Therefore, it can use username@localhost to connect to the server.

You would need to make mySQL accept connections from outside localhost by adding another user username@% (% meaning "any host").

Note however that this is not good practice - if you have a static IP, consider limiting access to that one address.

If you are planning to use MySQL workbench for managing MySQL databases and tables in a remote server, I am recommending connect over SSH. by following many articles and forums I tried many other ways by adding bind-address, adding a new user to MySql with uname@host with all privileges, etc. but in my case, all those steps were wasting of time, those steps will be useful if your server is so strict.

Follow the steps below.

  1. Click on the + button beside the MySql connections Title to add a new connection.
  2. Enter Connection Name(Whatever you need).
  3. Select connection method Standard TCP/IP over SSH.
  4. Enter the SSH details like Host(IP/Domain), Username, and Password. (SSH using Password Authorisation should be enabled in server)
  5. MySQL host details like Hostname(By Default localhost or 127.0.0.1), port(3306), MySQL username and password.
  6. Then click on test connection.

To get connected to MySQL Workbench installed on Windows 10, I found the above post written by Shihab and edited by Dharman useful to get connected instantly. But, here are the things that I did to connect via TCP/IP which was also useful for me to connect to MySQL via my code:

Step 1:Changing the bind address in MyMySQL On the Ubuntu machine (where my MySQL Community Server is installed) using Putty, I changed the mysqld.cnf file with the command "sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf". Using arrow keys, I scrolled down to the row with "bind-address" and I changed it from "127.0.0.1" to "0.0.0.0". I used ctrl+x to close and entered "Y" to save the file.

Step 2: Restart the MySQL Server You have to restart the MySQL server. To do that, you can restart using the command "sudo service mysql restart". If you are unable to restart, kill MySQL Process. First find the Process ID of MySQL using "ps ax | grep mysql" then kill the process using "sudo kill [process_id]"

Step 3:Changing the Firewall Settings of Ubuntu To allow outside connections, you should change the settings of the firewall. I used UFW (Uncomplicated FireWall) to change the settings. Start the UFW if it is not yet enabled using the command "sudo ufw enable". Check the status using "sudo ufw status". Now, enable connections to the MySql port 3306 (default) from a particular IP address using the command "sudo ufw allow from [ip_address] to any port 3306" or you can allow all connections to the port from any IP address is your IP address keeps changing using the command "sudo ufw allow mysql"

Step 4: Creating a user in MySQL I created a user in MySQL to avoid logging in using the root using the command "CREATE USER user_name @ your_IP_Address IDENTIFIED BY password ;

Step 5: Connect via the MySQL workbench

  1. Click Database
  2. Click Connect to Database
  3. In the Connection Method field, select "Standard TCP/IP"
  4. In the Hostname, enter your server IP address
  5. In the Server Port, leave as it is "3306" unless you have changed the port of MySql in your server
  6. In the Username, enter your server user name
  7. In the Password, enter your server password
  8. Click Ok

Step 6: If you are still not able to connect

  1. On your server, disable the firewall and check if you are able to connect
  2. If you are able to connect, reset the firewall with the command "sudo ufw reset" (Make sure you take a copy or screenshot of all the connections in the firewall. You can get all the ports with the command "sudo ufw status"). If you are unable to connect go to step 9.
  3. Now allow each and every port that was earlier present with the command "sudo ufw allow 80", "sudo ufw allow mysql", etc.
  4. Disable and enable the firewall using the commands "sudo ufw disable" and "sudo ufw enable" respectively.
  5. Check if you are able to connect via the workbench
  6. If you are still not able to connect, just restart the server using the command "sudo reboot"
  7. Once the reboot is complete, you should be able to connect to the MySQL server.
  8. If you are still not able to connect, use something like nmap software to check for all the open ports and see if you can see 3306. If you can t see the port, you have to debug what is stopping the firewall from blocking your MySQL connections.
  9. Check your MySQL privileges with the command "show grants for user_name @ localhost ;". If you are able to see the grants, that means your IP address is not allowed. Try to update the grants with your IP address with the following command "GRANT ALL PRIVILEGES ON database.* TO user @ yourremotehost IDENTIFIED BY newpassword ;" or GRANT ALL PRIVILEGES ON database.* TO user @ yourremotehost IDENTIFIED BY newpassword ; (To allow connections from everywhere)

If the above steps don t work and still you want to connect via a quick hack Premium Hack Step: Logging in using MySQL Workbench via SSH

  1. Click Database
  2. Click Connect to Database
  3. In the Connection Method field, select "Standard TCP/IP over SSH"
  4. In the SSH Hostname, enter your server IP address
  5. In the SSH Username, enter your server user name
  6. In the SSH Password, enter your server password
  7. In the SSH Key file, don t do anything
  8. In the MySQL Hostname, leave it as it is "127.0.0.1"
  9. In the Server Port, leave as it is "3306" unless you have changed the port of MySQL in your server
  10. In the Username, enter your MySQL username that you created in the previous step
  11. In the Password, enter your MySQL password that you created in the previous step
  12. Click Ok Now, you should be able to enter your MySQL Workbench

Other useful commands:

  1. To check if MySQL is running: systemctl status mysql
  2. Entering MySQL: sudo mysql -u [username] -p (Default username is root and password is nothing (just press enter key))
  3. To check the status of ufw: sudo ufw status
  4. To check the ufw status numbered for deleting a port access: sudo ufw status numbered
  5. To delete a ufw port access: sudo ufw delete [number_of_the_port_to_be_deleted_from_previous_command]
  6. To start MySQL service: sudo service mysql start
  7. To update all packages: sudo apt update
  8. To uninstall MySQL: sudo apt-get remove mysql*
  9. To install MySQL Step 1: sudo apt update Step 2: sudo apt install mysql-server Step 3: sudo systemctl start mysql.service Step 4 (if something is broken during installation): sudo apt --fix-broken install




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签