[MySQL] Install difficulties : Can't connect to local MySQL server
through socket '/tmp/mysql.sock' (2)
Bill Hernandez
ms at mac-specialist.com
Sun Jun 24 15:08:02 PDT 2007
I seemed to have gotten mySQL installed and running, but after a
couple o start/stop events, now I am getting :
ERROR : Connection Failed : Can't connect to local MySQL server
through socket '/tmp/mysql.sock' (2)
and after a couple of days trying to solve this problem decided to
seek wisdom elsewhere...
Here's what I have done so far:
------------------------------------------------------
NOTES : Installation Log [ mysql ] ...
------------------------------------------------------
First find out where mysql_install_db lives ?
[2007.23.06](08:59AM) -> [joshua] ~
$ sudo find /opt/local/ -name mysql_install_db
/opt/local/lib/mysql5/bin/mysql_install_db
[2007.23.06](09:00AM) -> [joshua] ~
$ open /opt/local/lib/mysql5
Check to see if the mysql user exists ?
[2007.23.06](09:44PM) -> [joshua] ~
$ sudo nicl . -list /users | grep mysql
Password:
19 mysql
SEE :
[2007.23.06](09:44PM) -> [joshua] ~
$ bh_man adduser
If it does not exist, create it...
[2007.23.06](09:44PM) -> [joshua] ~
$ nidump passwd . | cut -d: -f3 | sort -n | tail -n 1
If the mysql user does not exist, create it...
# +--------+--------+--------+--------+--------+--------+--------
+--------+
# CREATE A NEW USER
$ echo 'mysql::552:552::0:0:PostgreSQL User:/Users/mysql:/bin/bash' |
sudo niload -v passwd /
# +--------+--------+--------+--------+--------+--------+--------
+--------+
Check to see if the mysql group exists ?
[2007.23.06](09:52PM) -> [joshua] ~
$ sudo nicl . -list /groups | grep mysql
54 mysql
SEE :
[2007.23.06](09:44PM) -> [joshua] ~
$ bh_man addgroup
If the mysql group does not exist, create it...
Check to see what the last gid assigned was ?
[2007.23.06](09:44PM) -> [joshua] ~
$ nidump group . | cut -d: -f3 | sort -n | tail -n 1
You can create the mysql group in one of two ways:
I am going to assign a gid = 551 for pgsql
I am going to assign a gid = 552 for mysql
# METHOD 1
# +--------+--------+--------+--------+--------+--------+--------
+--------+
# ( 1 ) ADD A USER TO A NON-EXISTENT GROUP
# CREATE THE GROUP AT THE SAME YOU ADD THE USER
[2007.23.06](09:44PM) -> [joshua] ~
$ echo 'mysql:*:552:mysql' | sudo niload -v group /
# +--------+--------+--------+--------+--------+--------+--------
+--------+
# METHOD 2
# +--------+--------+--------+--------+--------+--------+--------
+--------+
# ( 2-A ) OR JUST CREATE A NEW mysql GROUP
[2007.23.06](09:44PM) -> [joshua] ~
$ sudo nicl . -create /groups/mysql gid 552
# ( 2-B ) ADD THE NEW mysql USER TO THE NEW mysql GROUP
[2007.23.06](09:44PM) -> [joshua] ~
$ sudo nicl . -append /groups/mysql users mysql
# +--------+--------+--------+--------+--------+--------+--------
+--------+
THESE ARE GENERIC UNIX COMMANDS I FOUND AT:
http://dev.mysql.com/doc/refman/5.1/en/installing-binary.html
Basically MacPorts is installing a binary for all instense and
purposes...
The basic commands that you must execute to install and use a MySQL
binary distribution are:
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
Note: This procedure does not set up any passwords for MySQL
accounts. After following the procedure, proceed to Section 2.10,
“Post-Installation Setup and Testing”.
[2007.23.06](09:00AM) -> [joshua] ~
LIST ALL THE USERS
$ nidump passwd . | cut -d: -f1,3 | sort -t: -k2 -n | awk -F :
'{ printf("%6d %-20s\n",$2,$1); }'
LIST ALL THE GROUPS
$ nidump group . | cut -d: -f1,3 | sort -t: -k2 -n | awk -F :
'{ printf("%6d %-20s\n",$2,$1); }'
MAKE SURE ANOTHER VERSION OF mysql IS NOT RUNNING,
IF THERE IS ONE RUNNING, SHUT IT DOWN...
$ ps aux | grep mysql
$ open /opt/local/share/mysql5/
$ cd /opt/local/share/mysql5
$ sudo chown -R mysql:mysql .
$ open /opt/local/lib/mysql5
$ cd /opt/local/lib/mysql5
$ sudo chown -R mysql:mysql .
$ sudo ./bin/mysql_install_db
$ sudo chown -R root:mysql .
$ cd /opt/local/var/db
$ sudo chown -R mysql:mysql ./mysql5
[2007.23.06](10:42PM) -> [joshua] ~
$ cd /opt/local/share/mysql5
[2007.23.06](10:42PM) -> [joshua] /opt/local/share/mysql5
$ sudo chown -R mysql:mysql .
Password:
[2007.23.06](10:42PM) -> [joshua] /opt/local/share/mysql5
$ cd /opt/local/lib/mysql5
[2007.23.06](10:43PM) -> [joshua] /opt/local/lib/mysql5
$ sudo chown -R mysql:mysql .
[2007.23.06](10:46PM) -> [joshua] /opt/local/lib/mysql5
$ sudo ./bin/mysql_install_db
Installing MySQL system tables...
070623 22:46:54 [Warning] Setting lower_case_table_names=2 because
file system for /opt/local/var/db/mysql5/ is case insensitive
OK
Filling help tables...
070623 22:46:54 [Warning] Setting lower_case_table_names=2 because
file system for /opt/local/var/db/mysql5/ is case insensitive
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h my_hostname.local
password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h my_hostname.local
password 'my_password'
See the manual for more instructions.
You can start the MySQL daemon with:
cd /opt/local
sudo /opt/local/lib/mysql5/bin/mysqld_safe &
THE FILE "mysql-test-run.pl " DOES NOT EXIST, NEITHER DOES THE DIR
"mysql-test"
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the /opt/local/lib/mysql5/bin/
mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
[2007.23.06](10:46PM) -> [joshua] /opt/local/lib/mysql5
$ sudo chown -R root:mysql .
[2007.23.06](10:47PM) -> [joshua] /opt/local/lib/mysql5
$ cd /opt/local/var/db
[2007.23.06](10:51PM) -> [joshua] /opt/local/var/db
$ sudo chown -R mysql:mysql ./mysql5
[2007.23.06](10:51PM) -> [joshua] /opt/local/var/db
$ cd /opt/local/lib/mysql5
[2007.23.06](10:52PM) -> [joshua] /opt/local/lib/mysql5
$ ./bin/mysqld_safe --user=mysql &
[1] 8480
[2007.23.06](10:53PM) -> [joshua] /opt/local/lib/mysql5
$ sudo ./bin/mysqld_safe --user=mysql &
[1] 8506
[2007.23.06](10:53PM) -> [joshua] /opt/local/lib/mysql5
$ Starting mysqld daemon with databases from /opt/local/var/db/mysql5
[2007.23.06](10:54PM) -> [joshua] /opt/local/lib/mysql5
$ ps aux | grep mysql
joshua 8539 1.9 0.0 18052 152 p1 R+ 10:54PM 0:00.01
grep mysql
mysql 8523 0.0 0.3 43624 2824 ?? SNs 10:53PM
0:00.16 /System/Library/Frameworks/CoreServices.framework/Version
mysql 8525 0.0 1.3 66188 13200 p1 S 10:53PM
0:00.16 /opt/local/libexec/mysqld --basedir=/opt/local --datadir=
root 8506 0.0 0.1 27812 712 p1 S 10:53PM
0:00.07 /bin/sh ./bin/mysqld_safe --user=mysql
root 31 0.0 0.1 27884 680 ?? Ss 6:20AM
0:00.01 /opt/local/bin/daemondo --label=mysql5 --start-cmd /opt/l
[2007.23.06](10:54PM) -> [joshua] /opt/local/lib/mysql5
$
START MYSQL
[2007.23.06](11:27PM) -> [joshua] ~
$ sudo /opt/local/lib/mysql5/bin/mysqld_safe --user=mysql &
[1] 8945
[2007.23.06](11:27PM) -> [joshua] ~
$ Starting mysqld daemon with databases from /opt/local/var/db/mysql5
[2007.23.06](11:28PM) -> [joshua] ~
$ ps aux | grep mysql
mysql 8523 0.0 0.3 43624 2812 ?? SNs 10:53PM
0:00.18 /System/Library/Frameworks/CoreServ
root 8945 0.0 0.1 27812 716 p3 S 11:27PM
0:00.08 /bin/sh /opt/local/lib/mysql5/bin/m
mysql 8963 0.0 1.3 66188 13192 p3 S 11:27PM
0:00.16 /opt/local/libexec/mysqld --basedir
joshua 8977 0.0 0.0 27336 352 p3 R+ 11:28PM 0:00.01
grep mysql
STOP MYSQL
[2007.23.06](11:28PM) -> [joshua] ~
$ sudo /opt/local/share/mysql5/mysql/mysql.server stop
Shutting down MySQL.STOPPING server from pid file /opt/local/var/db/
mysql5/my_hostname.local.pid
SUCCESS!
070623 23:29:54 mysqld ended
[2007.23.06](11:29PM) -> [joshua] ~
$
$ ps aux | grep mysql
mysql 8523 0.0 0.3 43624 2812 ?? SNs 10:53PM
0:00.18 /System/Library/Frameworks/CoreServ
joshua 8999 0.0 0.0 27336 360 p3 R+ 11:30PM 0:00.01
grep mysql
[1]+ Done sudo /opt/local/lib/mysql5/bin/
mysqld_safe --user=mysql
[2007.23.06](11:30PM) -> [joshua] ~
$
MySQL WILL NO LONGER START, HERE's where I am now :
All the previous versions of mySQL that I have installed, have been
installed at /usr/local/mysql and for the most part have managed to
get them working without too much problem, but I am having a problem
getting theMacPorts mysql5 working.
I installed Apache, PHP, PostgreSQL, and MySQL.
So far I've gotten Apache, PHP, and PostgreSQL working and configured
exactly the way I wanted them., but for some reason cannot get mySQL
to work correctly. At first I thought it was a permissions problem,
but now I am not sure what is causing the problem.
MacPorts appears to use several directories, which probably all need
to have the correct ownership/permissions set correctly :
/opt/local/bin/mysql5
/opt/local/etc/mysql5
/opt/local/include/mysql5
/opt/local/lib/mysql5
/opt/local/share/mysql5
/opt/local/var/db/mysql5
/opt/local/var/run/mysql5
I am sure there is a great reason for the over-complicated hierarchy
which I do not see at this point, but the standard install where all
the mySQL stuff goes in one dir seems a lot easier to deal with, even
for browsing purposes. Although as a work-around I could create a
dummy directory with aliases to all these other directories in order
to simplify the process of becoming familiar with the distributed
contents.
Setting permissions for the installations at /usr/local/mysql was
fairly simple and only involved two sets of permissions, one for the
main directory, and a different one for the data dir :
/usr/local/mysql
/usr/local/mysql/data --> data file, which translates to --> /opt/
local/var/db/mysql5
I didn't find any documentation on this type of setup. All the docs I
found refer to the /usr/local/mysql self contained type of installation.
Even the docs at http://dev.mysql.com/doc/refman/5.0/en/index.html
refer to the simpler hierarchy, so I wasn't able to find help there.
Any ideas ?
Also, has anybody documented how they got this implementation working ?
Are there any step by step docs for this implementation ?
I seem to have a number of error messages:
I noticed that the /opt/local/var/db/mysql5/my_hostname.local.pid is
not being created which seems like it could be a permissions error.
ERROR : Connection Failed : Can't connect to local MySQL server
through socket '/tmp/mysql.sock' (2)
I found this article : http://www.tech-recipes.com/mysql_tips762.html
Thanks in advance,
Bill Hernandez
Plano, texas
[2007.24.06](08:39AM) -> [joshua] ~
$ ps aux | grep mysql
joshua 395 3.1 0.0 27376 428 p1 S+ 8:40AM 0:00.01
grep mysql
[2007.24.06](08:40AM) -> [joshua] ~
$ sudo /opt/local/lib/mysql5/bin/mysqld_safe --user=mysql &
[1] 399
[2007.24.06](08:40AM) -> [joshua] ~
$ ps aux | grep mysql
root 399 0.0 0.1 27456 656 p1 S 8:40AM 0:00.03
sudo /opt/local/lib/mysql5/bin/mysq
joshua 403 0.0 0.0 27812 8 p1 R+ 8:40AM 0:00.00
grep mysql
[2007.24.06](08:40AM) -> [joshua] ~
$ sudo /opt/local/share/mysql5/mysql/mysql.server stop
[2007.24.06](08:43AM) -> [joshua] ~
$ sudo echo
Password:
[2007.24.06](08:43AM) -> [joshua] ~
$ sudo /opt/local/lib/mysql5/bin/mysqladmin -u root -h
my_hostname.local password 'my_password'
/opt/local/lib/mysql5/bin/mysqladmin: connect to server at
'my_hostname.local' failed
error: 'Lost connection to MySQL server at 'reading initial
communication packet', system error: 61'
[2007.24.06](08:43AM) -> [joshua] ~
$ sudo /opt/local/lib/mysql5/bin/mysqladmin -u root -h localhost
password 'my_password'
/opt/local/lib/mysql5/bin/mysqladmin: connect to server at
'localhost' failed
error: 'Can't connect to local MySQL server through socket '/opt/
local/var/run/mysql5/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/opt/local/var/run/
mysql5/mysqld.sock' exists!
[2007.24.06](08:44AM) -> [joshua] ~
$ sudo /opt/local/lib/mysql5/bin/mysqladmin -u root -h 127.0.0.1
password 'my_password'
/opt/local/lib/mysql5/bin/mysqladmin: connect to server at
'127.0.0.1' failed
error: 'Lost connection to MySQL server at 'reading initial
communication packet', system error: 61'
[2007.24.06](08:44AM) -> [joshua] ~
$ sudo /opt/local/lib/mysql5/bin/mysqld_safe --user=mysql &
[2] 447
[2007.24.06](08:45AM) -> [joshua] ~
$ Starting mysqld daemon with databases from /opt/local/var/db/mysql5
STOPPING server from pid file /opt/local/var/db/mysql5/
my_hostname.local.pid
070624 08:45:58 mysqld ended
[2007.24.06](08:48AM) -> [joshua] ~
$ ps aux | grep mysql
root 399 0.0 0.1 27456 636 p1 S 8:40AM 0:00.03
sudo /opt/local/lib/mysql5/bin/mysq
mysql 464 0.0 0.3 43624 2816 ?? SNs 8:45AM
0:00.16 /System/Library/Frameworks/CoreServ
joshua 545 0.0 0.0 27336 364 p1 R+ 8:48AM 0:00.01
grep mysql
On my other machine where I have a /usr/local/mysql type of install
ps aux | grep mysql has several more lines, but I didn't look at them
closely yet.
# +--------+--------+--------+--------+--------+--------+--------
+--------+
PROBLEMS DURING STARTUP :
ERROR : Connection Failed : Can't connect to local MySQL server
through socket '/tmp/mysql.sock' (2)
After searching for several hours finally found the article shown below:
# +--------+--------+--------+--------+--------+--------+--------
+--------+
# http://www.tech-recipes.com/mysql_tips762.html
A frequent error message received when using the mysql command line
utility is: Can't connect to local MySQL server through socket '/tmp/
mysql.sock' While this error message can be frustrating, the solution
is simple.
When connecting to a MySQL server located on the local system, the
mysql client connects thorugh a local file called a socket instead of
connecting to the localhost loopback address 127.0.0.1.
For the mysql client, the default location of this socket file is /
tmp/mysql.sock. However, for a variety of reasons, many MySQL
installations place this socket file somewhere else like /var/lib/
mysql/mysql.sock.
While it is possible to make this work by specifying the socket file
directly in the mysql client command
mysql --socket=/var/lib/mysql/mysql.sock ...
it is painful to type this in every time. If you must do so this way
(because you don't have permissions to the file in the solution
below), you could create an alias in your shell to make this work
(like alias mysql="mysql --socket=/var/lib/mysql/mysql.sock"
depending on your shell).
To make your life easier, you can make a simple change to the MySQL
configuration file /etc/my.cnf that will permanently set the socket
file used by the mysql client. After making a backup copy of /etc/
my.cnf, open it in your favorite editor. The file is divided into
sections such as
[mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
[mysql.server]
user=mysql
basedir=/usr/local/mysql
If there is not currently a section called [client], add one at the
bottom of the file and copy the socket= line under the [mysqld]
section such as:
[client]
socket=/var/lib/mysql/mysql.sock
If there is already a [client] section in the my.cnf file, add or
edit the socket line as appropriate. You won't need to restart your
server or any other processes. Subsequent uses of the mysql client
will use the proper socket file.
# +--------+--------+--------+--------+--------+--------+--------
+--------+
I FOUND my.cnf, but elected not to install it until I got some
advice. All references are to "mysqld/mysqld.sock"
# +--------+--------+--------+--------+--------+--------+--------
+--------+
So I did a search for my.cnf and found the only one on the drive at :
# /opt/local/var/db/dports/sources/
rsync.rsync.darwinports.org_dpupdate_dports/databases/mysql4/files/
my.cnf
# /etc/mysql/my.cnf: The global mysql configuration file.
# This file can be simultaneously placed in three places:
# 1. /etc/mysql/my.cnf to set global options.
# 2. /var/lib/mysql/my.cnf to set server-specific options.
# 3. ~/.my.cnf to set user-specific options.
#
# One can use all long options that the program supports.
# Run the program with --help to get a list of them.
#
# The following values assume you have at least 32M RAM!
[client]
#password = my_password
port = 3306
socket = __PREFIX/var/run/mysqld/mysqld.sock
[safe_mysqld]
err-log = __PREFIX/var/log/mysql/mysql.err
pid-file = __PREFIX/var/run/mysqld/mysqld.pid
socket = __PREFIX/var/run/mysqld/mysqld.sock
[mysqld_safe]
err-log = __PREFIX/var/log/mysql/mysql.err
pid-file = __PREFIX/var/run/mysqld/mysqld.pid
socket = __PREFIX/var/run/mysqld/mysqld.sock
[mysqld]
#skip-networking
skip-innodb
user = mysql
pid-file = __PREFIX/var/run/mysqld/mysqld.pid
socket = __PREFIX/var/run/mysqld/mysqld.sock
port = 3306
log = __PREFIX/var/log/mysql/mysql.log
basedir = __PREFIX
datadir = __PREFIX/var/db/mysql
tmpdir = /tmp
language = __PREFIX/share/mysql/english
skip-locking
set-variable = key_buffer=16M
set-variable = max_allowed_packet=1M
set-variable = thread_stack=128K
[mysqldump]
quick
set-variable = max_allowed_packet=1M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
set-variable = key_buffer=16
# +--------+--------+--------+--------+--------+--------+--------
+--------+
More information about the macports-users
mailing list