无法使用以下命令启动 mysql:
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...
一个实例 mysqld 正在运行:
$ ps aux | grep mysql
mysql 1093 0.0 0.2 169972 18700 ? Ssl 11:50 0:02 /usr/sbin/mysqld
$
端口 3700 可用:
$ netstat -a | grep 3700
$
带有套接字的目录是空的:
$ ls /srv/mysql/sockets/
$
有全部权限:
$ 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
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>
}
有什么建议么?
更新1:
$ 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
$
更新2:
$ 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.
更新3:
$ 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/
答案1
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 ?
看起来 AppArmor 是罪魁祸首。尝试更改此设置:
/{,var/}run/mysqld/mysqld.pid w,
/{,var/}run/mysqld/mysqld.sock w,
到:
/srv/mysql/pids/mysqld-myDB.pid w,
/srv/mysql/sockets/mysql-myDB.sock w,
答案2
您是否尝试同时运行两个 mysql 实例?
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
这意味着有另一个 mysql 服务器进程正在运行并监听 unix 套接字。要确认,您可以使用:
sudo netstat -lnp | grep mysql
sudo lsof | grep /srv/mysql/sockets/mysql-myDB.sock
这mysql-myDB.sock
是一个套接字文件。它不是常规文件。您不应使用 创建它touch
。您应该得到类似的输出:
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
查看输出s
中的第一个字符 (socket) 。 你看到的是 ,它表示一个常规文件。ls -l
-
答案3
我将尝试创建套接字并重新启动 mysqlserver 以查看是否能启动它。
touch mysql-myDB.sock
检查它是否归 mysql 所有。
答案4
还要尝试检查以确保 mysqld.service 脚本没有阻止套接字写入。MariaDB 和其他可能默认具有:
PROTECTSYSTEM=TRUE
这将阻止将数据写入 /usr /boot 和 /etc 目录。