mysql: Ligação no socket unix: Permissão negada

3

Não é possível iniciar o mysql com:

sudo /usr/bin/mysqld_safe  --datadir=/srv/mysql/myDB --log-error=/srv/mysql/logs/mysqld-myDB.log --pid-file=/srv/mysql/pids/mysqld-myDB.pid --user=mysql  --socket=/srv/mysql/sockets/mysql-myDB.sock --port=3700


120222 13:40:48 mysqld_safe Starting mysqld daemon with databases from /srv/mysql/myDB
120222 13:40:54 mysqld_safe mysqld from pid file /srv/mysql/pids/mysqld-myDB.pid ended

/srv/mysql/logs/mysqld-myDB.log:

120222 13:43:53 mysqld_safe Starting mysqld daemon with databases from /srv/mysql/myDB
120222 13:43:53 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Table 'plugin' is read only
120222 13:43:53 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
120222 13:43:53  InnoDB: Completed initialization of buffer pool
120222 13:43:53  InnoDB: Started; log sequence number 32 4232720908
120222 13:43:53 [ERROR] Can't start server : Bind on unix socket: Permission denied
120222 13:43:53 [ERROR] Do you already have another mysqld server running on socket: /srv/mysql/sockets/mysql-myDB.sock ?
120222 13:43:53 [ERROR] Aborting

120222 13:43:53  InnoDB: Starting shutdown...

Uma instância do mysqld está em execução:

$ ps aux | grep mysql
mysql     1093  0.0  0.2 169972 18700 ?        Ssl  11:50   0:02 /usr/sbin/mysqld
$

A porta 3700 está disponível:

$ netstat -a | grep 3700
$

Diretório com soquetes está vazio:

$ ls /srv/mysql/sockets/
$

Existem todas as permissões:

$ ls -l /srv/mysql/
total 20
drwxrwxrwx  2 mysql mysql 4096 2012-02-22 13:28 logs
drwxrwxrwx 13 mysql mysql 4096 2012-02-22 13:44 myDB
drwxrwxrwx  2 mysql mysql 4096 2012-02-22 12:55 pids
drwxrwxrwx  2 mysql mysql 4096 2012-02-22 12:55 sockets
drwxrwxrwx  2 mysql mysql 4096 2012-02-22 13:25 version

Configuração do Apparmor:

$cat /etc/apparmor.d/usr.sbin.mysqld
# vim:syntax=apparmor
# Last Modified: Tue Jun 19 17:37:30 2007
#include <tunables/global>

/usr/sbin/mysqld flags=(complain) {
  #include <abstractions/base>
  #include <abstractions/nameservice>
  #include <abstractions/user-tmp>
  #include <abstractions/mysql>
  #include <abstractions/winbind>

  capability dac_override,
  capability sys_resource,
  capability setgid,
  capability setuid,

  network tcp,

  /etc/hosts.allow r,
  /etc/hosts.deny r,

  /etc/mysql/*.pem r,
  /etc/mysql/conf.d/ r,
  /etc/mysql/conf.d/* r,
  /etc/mysql/*.cnf r,
  /usr/lib/mysql/plugin/ r,
  /usr/lib/mysql/plugin/*.so* mr,
  /usr/sbin/mysqld mr,
  /usr/share/mysql/** r,
  /var/log/mysql.log rw,
  /var/log/mysql.err rw,
  /var/lib/mysql/ r,
  /var/lib/mysql/** rwk,
  /var/log/mysql/ r,
  /var/log/mysql/* rw,
  /{,var/}run/mysqld/mysqld.pid w,
  /{,var/}run/mysqld/mysqld.sock w,

  /srv/mysql/ r,
  /srv/mysql/** rwk,

  /sys/devices/system/cpu/ r,

  # Site-specific additions and overrides. See local/README for details.
  #include <local/usr.sbin.mysqld>
}

Alguma sugestão?

UPD1:

$ touch /srv/mysql/sockets/mysql-myDB.sock
$ sudo chown mysql:mysql /srv/mysql/sockets/mysql-myDB.sock
$ ls -l /srv/mysql/sockets/mysql-myDB.sock
-rw-rw-r-- 1 mysql mysql 0 2012-02-22 14:29 /srv/mysql/sockets/mysql-myDB.sock
$ sudo /usr/bin/mysqld_safe --datadir=/srv/mysql/myDB --log-error=/srv/mysql/logs/mysqld-myDB.log --pid-file=/srv/mysql/pids/mysqld-myDB.pid --user=mysql --socket=/srv/mysql/sockets/mysql-myDB.sock --port=3700
120222 14:30:18 mysqld_safe Can't log to error log and syslog at the same time.  Remove all --log-error configuration options for --syslog to take effect.
120222 14:30:18 mysqld_safe Logging to '/srv/mysql/logs/mysqld-myDB.log'.
120222 14:30:18 mysqld_safe Starting mysqld daemon with databases from /srv/mysqlmyDB
120222 14:30:24 mysqld_safe mysqld from pid file /srv/mysql/pids/mysqld-myDB.pid ended
$ ls -l /srv/mysql/sockets/mysql-myDB.sock
ls: cannot access /srv/mysql/sockets/mysql-myDB.sock: No such file or directory
$

UPD2:

$ sudo netstat -lnp | grep mysql
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1093/mysqld
unix  2      [ ACC ]     STREAM     LISTENING     5912     1093/mysqld         /var/run/mysqld/mysqld.sock

$ sudo lsof | grep /srv/mysql/sockets/mysql-myDB.sock
lsof: WARNING: can't stat() fuse.gvfs-fuse-daemon file system /home/sears/.gvfs
      Output information may be incomplete.

UPD3:

$ cat /etc/mysql/my.cnf
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
#
# * Basic Settings
#

#
# * IMPORTANT
#   If you make changes to these settings and your system uses apparmor, you may
#   also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#

user            = mysql
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 127.0.0.1
#
# * Fine Tuning
#
key_buffer              = 16M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1

log_error                = /var/log/mysql/error.log

# Here you can see queries with especially long duration
#log_slow_queries       = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
#log_bin                        = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem



[mysqldump]
quick
quote-names
max_allowed_packet      = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
key_buffer              = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
    
por Alex 22.02.2012 / 11:55

3 respostas

5

Can't start server : Bind on unix socket: Permission denied
Do you already have another mysqld server running on socket: /srv/mysql/sockets/mysql-myDB.sock ?

Parece que o AppArmor é o culpado. Tente mudar isso:

/{,var/}run/mysqld/mysqld.pid w,
/{,var/}run/mysqld/mysqld.sock w,

para:

/srv/mysql/pids/mysqld-myDB.pid w,
/srv/mysql/sockets/mysql-myDB.sock w,
    
por 13.09.2012 / 04:39
0

Eu tentaria apenas criar o socket e reiniciar o mysqlserver para ver se aquele chute começa.

touch mysql-myDB.sock

Verifique se é de propriedade do mysql.

    
por 22.02.2012 / 12:23
0

Você está tentando executar duas instâncias do mysql ao mesmo tempo?

120222 13:43:53 [ERROR] Can't start server : Bind on unix socket: Permission denied
120222 13:43:53 [ERROR] Do you already have another mysqld server running on socket: /srv/mysql/sockets/mysql-myDB.sock ?
120222 13:43:53 [ERROR] Aborting

Isto significa que existe outro processo do servidor mysql sendo executado e escutando no soquete unix. Para confirmar, você pode usar:

sudo netstat -lnp | grep mysql
sudo lsof | grep /srv/mysql/sockets/mysql-myDB.sock

O mysql-myDB.sock é um arquivo de soquete. Não é um arquivo normal. Você não deve criá-lo usando touch . Você deve obter uma saída semelhante:

khaled@khaled-pc$ ls -l  ls -l /var/run/mysqld/mysqld.sock
srwxrwxrwx 1 mysql mysql 0 2012-02-22 09:55 /var/run/mysqld/mysqld.sock

Veja o primeiro caractere s (socket) em ls -l output. Você tem - , o que denota um arquivo normal.

    
por 22.02.2012 / 12:27

Tags