How do I acces localhost MySQL through command line from another pc? - mysql

As a follow-up question on this one:
Accessing localhost (xampp) from another computer over LAN network - how to?
I can access localhost in my browser and MySQL but not from the command-line
I can not figure out how to get from there. From the command-line I use:
mysql -u root -h "IP of remote localhost"
And getting the following error "Error 2003(HY000): Can't connect to MySQL server on "

Basically you need to enable remote access.
This is for mysql workbench
Clicking the [+] icon from the home screen launches the Setup New Connection wizard. The wizard provides a MySQL connection form to create a new MySQL connection, and includes a Configure Server Management option as a step-by-step approach to creating a new MySQL server connection. This can also be executed later (on remote connections) when from the home screen by clicking the top right corner of a MySQL connection tile:
Executing this wizard is required to perform tasks requiring shell access to the host. For example, starting/stopping the MySQL instance and editing the configuration file.
And here is a tutorial where you can peform it step by step:
https://dev.mysql.com/doc/workbench/en/wb-getting-started-tutorial-create-connection.html
This is to do it over xamp
You need to open up the configuration it will look something like this:
# The MySQL server
[mysqld]
user=mysql
port=3308
socket =/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
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
And you will need to specify the IP adress:
bind-address=192.xxx.xxx.xxx

Related

Python MYSQL will not connect

I have been helping troubleshoot a process on an old UBUNTU 16 server. We cannot migrate a site to a new server until we understand how it works as we need to recreate and troubleshoot.
Basically its a python3 script that connects to a MYSQL database and reads some data, and updates data under a certain condition. It is basically linked to ZOHO hence the need for this programming language.
The error has been diagonsed as a mysql connection error. Error 111 connection refused. The database is localhost
I have 100% verified the access for the username, password and database visibiity and that port 3306 is open. I can login using a MYSQL command on the CLU and show the database and its tables.
The connector is 100% pulling in the correct variables from the config.py as I have added a print(HOST, DBASE, USER, PASSWORD) just before the connector and verified they are correct.
I have also tried 127.0.0.1 instead of localhost. I have also (dont shoot me) put in the root username and password to remove any permissions issues
I am wondering if its possible to expand on the mysql error in python so I can get a very clear message as to WHAT part is causing an issue. Is there any command in MYSQL that could have been issued to specifically block python.
I have disabled UFW just in case, made no difference, and the general logs for MYSQL dont appear to contain anything useful
Exact error:
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306' (111 Connection refused)
Note: The server is Ubuntu 16, running MYSQL 5.7.26-0ubuntu0.16.04.1 with localhost access only. Python is 2.7.12
As noted this is an old server, that I want to scrap ASAP but until I can prove that the zoho connector is fixable, we cant proceed as its a blocker.
As you can see in theexample below.
the port is separate from the host
import mysql.connector
cnx = mysql.connector.connect(
host='localhost',
database='import_test',
user='testuser',
password='password***',
port=3306
)
Turns out to be the most basic of all issues. On the old server we cloned from, everyting was open, zero lockdown including MYSQL listening to the world. On the new server, mysql had skip-networking was enabled.
Whereas the web instances were happily connecting directly to the socket, mysql was not activly listening on port 3306. I had changed my.cnf to enable networking but a different issue was stopping those changes taking place.
Once I had mysql working on port 3306 and I could see it listening, python now connected ok so some of the answers were correct. MYSQL was 'not working;' in a global sense.. HOWEVER this is a step backwards in terms of security. I did not want MYSQL open to the world
So I modified the code to use the unix socket of /var/run/mysqld/mysqld.sock, renenabled skip-networking and voila.. all is now fine with python, port 3306 is shutdown again and I have my first trial by fire of python complete
My config file defines DATABASE as local host, USER and PASSWORD but now has SOCKET as /var/run/mysqld/mysqld.sock and my code is
import mysql.connector
from models import ExportRecord
from config import HOST, USER, PASSWORD, DATABASE, SOCKET
def connect():
return mysql.connector.connect(host=HOST, user=USER, passwd=PASSWORD, database=DATABASE, unix_socket=SOCKET)

Permission denied only with Workbench

I have a database located on a server and it is working correctly. I can access it from the local server and using phpmyadmin from any server connected to the network.
I would want to use Workbench in order to use its functions but I have tried a lot of possibilities and I'm not able to connect from it.
I have found a lot of solutions but anyone could not help me. For this reason, I'm trying to find someone who can help me with this.
First of all, I want to explain that this database is accessible from phpmyadmin (as I said before) and from webserver (I use database in my web application) so, the trouble of denied remote access is discarded. (with user root)
Furthermore I have looking for the problem and in the log of database server I have could find this:
error: connect to 127.0.0.1 port 3306 failed: Permission denied
channel_by_id: 0: bad id
I have tried to use Workbench with TCP/IP with the IP of the database server by port 3306 and with SSH connecting to webserver (this step is running correctly) and connecting to database with local IP and port 3306.
Furthermore, I have checked if port 3306 was closed and it is opened.
The config (my.cnf) is this:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
max_allowed_packet=1024M
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
I know that this config is not usual but I have not installed it and I would not want to touch a lot because it is working now and a lot of people is using it.
I have tried too to edit hosts.allow adding the line mysqld: all but it did not work.
What can be the problem? Thanks for your help.
(I have checked Stackoverflow's posts too and I have not been able to find a solution)
you need to configure your mysql to allow remote login. then you can either specified your ip or wildcard * to allow all ip to access the mysql database.
this is the command to grant remote access.
Log in to the database server.
Connect to the MySQL database as the root user.
Enter the following command:
GRANT ALL ON <local database name>.* TO <remote web node username>#<remote web node server ip address> IDENTIFIED BY '<database user password>';
For example,
GRANT ALL ON magento_remote.* TO dbuser#192.0.2.50 IDENTIFIED BY 'dbuserpassword';

Connect to MySQL on my laptop from Raspberry pi

I have a MySQLdb running on my Ubuntu Laptop. I have created a database.
I need to access this database on my laptop from my Raspberry pi.
I have installed PyMySQL on my raspberry pi. I have also configured the mysqld.conf file in my laptop and commented out the bind address line.
But eherytime i use the following command on my RPi
conn = pymysql.connect(host='192.168.10.7', port='3306', user='root', passwd='password', db='temps')
192.168.10.7 is my laptop ip address. This IP address can be pinged from my RPi.
but i get error
pymysql.err.InternalError: (1130, "Host '192.168.10.7' is not allowed to connect to this MSQL server")
Do I need to make anymore changes in the configuration? If yes, can you please guide me?
By default MySQL Server on Ubuntu run on the local interface, This means remote access to the MySQL Server is not Allowed. To enable remote connections to the MySQL Server you need to change value of the bind-address in the MySQL Configuration File.
Open the /etc/mysql/mysql.conf.d/mysqld.cnf file (/etc/mysql/my.cnf in Ubuntu 14.04 and earlier versions).
Under the [mysqld] Locate the Line,
bind-address = 127.0.0.1
And change it to,
bind-address = 0.0.0.0
Then, Restart the Ubuntu MysQL Server.
systemctl restart mysql.service
Now Ubuntu Server will allow remote access to the MySQL Server, But still you need to configure MySQL users to allow access from any host.
For example, when you create a MySQL user, you should allow access from any host.
CREATE USER 'username'#'%' IDENTIFIED BY 'password';

Need mysql remote access with my system IP

I have been using ubuntu 14.04 LTS OS and now i want to give permission of my local mysql server for my colleague system in my network. I need the answes for the following question,
How to bind my system IP address to mysql server. If i execute the command line "mysql -uroot -proot -h192.168.1.198", then received the error message below
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.198' (111)
Then how to give permission to other system user to access my local mysql server.
Your MySQL service is bound to serve localhost only (interface binding). This is the default for security reasons. If you really need to access it directly from other hosts, there is a nice How to enable remote access to MySQL on Ubuntu which you could follow:
as root, open your /etc/mysql/my.cnf with your favorite editor
look for the [mysqld] section, and in there for the bind-address keyword. This usually is set to 127.0.0.1 -- change that to match your "normal" IP-address
save the file, and reload the service (e.g. using service mysql restart)
Remember you must enable your remote users to access their database(s) from remote, by setting the appropriate GRANTs -- e.g.
GRANT ALL ON mydb.* TO remoteuser#'%' IDENTIFIED BY 'SomePASSWORD';
Note the #'%', which means "from any host".
Try to telnet MySql server from that PC
telnet 192.168.1.198 3306
If that fails there are two cases:
You have not properly opened MySql Server required ports (default: 3306)
Go to my.ini (or my.cnf) and comment out bind-address and change it to 0.0.0.0 (to listen to all available interfaces) or perhaps the server's LAN IP (192.168.1.XYZ).

Allowing Remote Access on my Xampp MySQL DB

Okay I apologize in advance if this seems to be a trivial question but I am new to databases and such so here's my problem.
I have installed xampp and using their MySQL database service. I also able to connect to my database remotely in my network yet I would like to access the database that i have created from another computer out side my LAN. So far i have created a user named "Lester" with all privileges enabled and the host set to "%". In the config file i have it set as follows
# The MySQL server
[mysqld]
user=mysql
port=3308
socket =/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
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
How do i go about connecting outside of my network..
Please specify your ip address in the bind address
bind-address=192.168.1.100
Try and let me know if you are facing any problems.
Goto
http://localhost/phpmyadmin -> user accounts -> Edit privileges -> change login information
change Host drop down to Any host
then restart mysql
reference Link
https://www.hacking-tutorial.com/tips-and-trick/how-to-make-xampp-mysql-database-accessible-by-network/#sthash.11j7Xjht.dpbs