MySQL Remote Connection Issues - mysql

I've just learnt the basics of MySQL to allow me to upload tables onto my Wordpress site through wpdatatables. However, I can't for the life of me work out how to get a remote access connection working. There is plenty of literature and forum posts out there to help with this and I've tried a number of way but I haven't had any success.
I've created privileges for a user called morts81 using the code below:
GRANT ALL PRIVILEGES ON *.* TO 'morts81'#'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Then I've opened up the my.cnf file to ensure that the bind.address line is removed, however, I don't have a bind.address line so I imagine that isn't an issue.
# The MySQL server
[mysqld]
user = mysql
port=3306
socket = /Applications/XAMPP/xamppfiles/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
Then finally I try and check the connection from inside the wpdatatable plug-in for Wordpress and I get the following error:
I've also tried replacing localhost in the wpdatatables input with 127.0.0.1 which seems to be recommended on some forums but I get a separate error then:
Would appreciate any help on what I'm doing wrong here.

The socket you specified is different in your config file to start the mysql server. If you can connect to the socket as shown in first error message, use the below socket configuration
socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
For the 2nd error, see if your mysql server is accessible from the server/service datatables is running on.

Related

Could not start the Mysql service on Local Computer "Error 3: The system cannot find the path specified"

I'm trying to install "MYSQL -5.5.62-win32" on windows XP manually.
The existing MYSQL is MySQL 4.1.22-community-nt. It works like a breeze!
I have done the following:-
Stopped mysql server
my.ini
Renamed "my.ini" on c:/windows =>"my_old.ini"
Copied "my-medium.ini" from "mysql-5.5.62-win32" folder to c:/windows
Renamed "my-medium.ini" => "my.ini" on c:/windows
mysql folder
Renamed "mysql" folder on c:/ =>"mysql_old"
Copied "mysql-5.5.62-win32" to c:/
Renamed "mysql-5.5.62-win32" =>"mysql"
Now, when I try to restart the mysql server, the following error message is displayed:
Could not start the Mysql service on Local Computer
Error 3: The system cannot find the path specified
Please note:-
Unlike the previous "my.ini" file, the new "my.ini" file doesn't include any reference to the location of the "MYSQL" server.
This is the content of old "my.ini"
[mysqld]
basedir = C:/mysql/
datadir = C:/public_html/db/
[WinMySQLadmin]
Server=C:/mysql/bin/mysqld-nt.exe
user=[username]
password=password]
This is the content of the new "my.ini"
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 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
Please note that I couldn't find "mysql.sock" anywhere on the desktop. I am told that there is no need for the line:-
socket = /tmp/mysql.sock
MYSQL worked without it.
Please help!
Bill's suggestion,"MySQL 5.5", would have been OK, but it needed a lot of work.
In the end, I tried "mysql-5.0.20-win32". It does the job and everyone is happy now.

Yii2 Remote Database Connection Issue

I am trying to get my web server to connect to my remote database (Mysql).
The connection is happening in my web application which is built on yii2.
I have created all user details, GRANTED all privileges and allowed connections from ALL hosts (%) (Progressively in troubleshooting this).
Now I can connect from home using HeidiSQL or using Mysql Workbench without issue.
I have even created a blank yii2 site at home and it works instantly, but uploading the site to the web server instantly gives the same issue.
Database Exception – yii\db\Exception
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '46.105.111.111' (110)
↵
Caused by: PDOException
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '46.105.111.111' (110)
in /home/xxxxxxx/xtest.xxxxxxxx.tv/vendor/yiisoft/yii2/db/Connection.php at line 602
I have run netstat on the db server:
I have been through the etc/mysql/my.cnf
<pre>[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 7999
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#bind-address = *
key_buffer = 16M
max_allowed_packet = 64M
thread_stack = 192K
thread_cache_size = 8
myisam-recover = BACKUP
query_cache_limit = 1M
query_cache_size = 16M
expire_logs_days = 10
max_binlog_size = 100M
max_connections = 65535
open-files-limit = 65535
max_connect_errors = 65535
innodb_buffer_pool_size = 1G
table_open_cache = 1000
innodb_flush_log_at_trx_commit = 0
innodb_flush_method = O_DIRECT
tmp_table_size = 256M
max_heap_table_size = 256M
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
[isamchk]
key_buffer = 16M</pre>
I have looked at the iptables:
I am totally bedazzled as having read about 20 pieces of information about mysql security, i get the feeling its a permissions issue.
I have even tried using my own PDO Wrapper, so i a, 99% sure its not a Yii2 issue, would really appreciate any help.
Hopefully I have provided enough info as I got a downvote previously.
many thanks for the help.
It turns out that the web host was actually blocking the outgoing port for the connection.
The output error from yii being database error, nievly led me to think the issue was at the database end.
Simple logic when you read back the question.
I would say to anyone that finds this question, remember with a connection issue that communication is two way, check both ends of the connection.

How to connect to MAMP MySQL Server using DataGrip

DataGrip doesn't connect to my local MySQL server that comes with MAMP Pro server. However, when I try connecting with PHP or the mysql command, it works perfectly. Can anyone help?
MAMP Pro -> Mysql Tab -> Check "Allow network access to Mysql" -> Save -> Profit!
I found a solution. I had to edit my.cnf (You must edit the template here: Mamp PRO -> File -> Edit Template -> MySQL my.cnf)
I commented out MAMP_bind-address_MAMP and added a new line bind-address = 0.0.0.0 to allow incoming connections from all IPs.
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
# MAMP_bind-address_MAMP
bind-address = 0.0.0.0
Hope it helps anyone who has the same problem.

I can't set a new variable on mysql

I want to increase max_allowed_packet variable on my server and I don't know why, when I add the sentence in /etc/my.cnf, it doesn't work!! This is the line I added:
max_allowed_packet=62M
But when I check the current value through mysqladmin variables, it shows 10M!! I've even restarted my server! And nothing happens!
What happens here?
The settings file will normally have several sections (what MySQL calls groups). You're possibly disregarding that fact:
# The following options will be passed to all MySQL clients
[client]
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M

[Warning]: PDO::__construct(): MySQL server has gone away - wait_timeout not the cause?

I am hoping that someone on here can help with an issue I am having on a webserver. Currently the server hosts a web application which we have purchased for helpdesking. Every 8 hours when someone navigates to the page they will be presented with this error:
[Warning]: PDO::__construct(): MySQL server has gone away (Database/class.SWIFT_Database.php:334)
I have tried setting the wait_timeout to the max value in the /etc/my.cnf file ie;
wait_timeout=31536000
Also from the mysql I have set the global wait_timeout to this value and set the session wait_time out to the same.
I have noticed some strange behaviour, when you restart the mysql service, the wait timeout resets to the 28800 default, despite it being set in the my.cnf. I can't find any other config files for mysql though happy to look if someone can point me in the direction.
Also this morning when I logged into the server and ran the following command, the session wait_timeout value had reverted!
mysql> select ##global.wait_timeout, ##session.wait_timeout;
+-----------------------+------------------------+
| ##global.wait_timeout | ##session.wait_timeout |
+-----------------------+------------------------+
| 31536000 | 28800 |
+-----------------------+------------------------+
1 row in set (0.00 sec)
I see that this is an issue for a lot of people online with various webapps running on mysql, but no one seems to have a fix. A lot of advice online points to the wait_timeout but it doesn't seem to be changing the bug that I am seeing. I have tried out the fixes on the mysql manual about this issue, but still no luck (link: http://dev.mysql.com/doc/refman/5.0/en/gone-away.html)
Any advice would be greatly appreciated. Server details and product versions below:
Server: OpenSuse 11.4
MySql Version: 5.1.53
Many Thanks In Advance!
While not very elegant, the following snippet has helped me get rid of the timeouts and keep persistent connections. It will throw the exception if the connection fails $limit times in a row, though if the problem is timeouts you will only need 1 retry at most.
$db = null;
$limit = 10;
$counter = 0;
while (true) {
try {
$db = new PDO('mysql:host=' . db_host . ';dbname=' . db_name, db_user, db_pass);
$db->exec( "SET CHARACTER SET utf8" );
$db->setAttribute( PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC );
$db->setAttribute( PDO::ATTR_PERSISTENT, true );
break;
}
catch (Exception $e) {
$db = null;
$counter++;
if ($counter == $limit)
throw $e;
}
}
This article on Drupal.org may be helpful in your situation:
MySQL comes with a default configuration of the resources it is going to use, specified in "my.cnf" (Linux) or "my.ini" (Windows) during the installation of MySQL.
In Linux this file is located at /etc/my.cnf to set global options, or /usr/local/var/mysql-data-dir/my.cnf to set server-specific options.
In Windows this file is located by default at C:\Program Files\MySQL\MySQL Server X.Y\my.ini.
Resources allowed by the default configuration are normally insufficient to run a resource-intensive application. You must modify the following resource specifications if they are available in your original configuration file, or add them to the configuration file if they are not already specified (because some are not present by default) :
Important: Remember to keep backup files before you do anything! You will also have to reload the MySQL service after making changes to these configuration files.
MyISAM specifications:
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer = 384M
max_allowed_packet = 64M
table_cache = 4096
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 64M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
InnoDB specifications:
innodb_buffer_pool_size = 384M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 10M
innodb_log_buffer_size = 64M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 180
Note: It is assumed here that you are using the InnoDB database tables, as Drupal is a resource intensive application. If you are not using the InnoDB database tables try to change this, in view of the fact that you are getting the Warning: MySQL server has gone away - apparently meaning that your setup is resource intensive.
There are various reasons that a connection gets closed.
Reference:
https://dev.mysql.com/doc/refman/5.0/en/gone-away.html
I too faced the similar problem on using PDO where the hosting administrator kills the connection if it sleeps more than a minute. Hence I came up with my own class which will wrap the PDO class. This will detect whether a connection is closed and will try to reconnect on query execution.
Answer Below
PDO: MySQL server has gone away