操作系统的环境:Ubuntu 12.10
之前数据库是好的,因为我想把它设置远程连接数据库
具体是执行了GRANT ALL PRIVILEGES ON *.* TO root @'%' IDENTIFIED BY 'mysql';
后面把数据库重启,运行 mysql -uroot -pmysql,报错如下:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
/var/run/mysqld目录下是不存在mysqld.sock文件的,整个盘符下都没有这个文件。
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
#socket = /tmp/mysql.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
#socket = /tmp/mysql.sock
nice = 0[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
#socket = /tmp/mysql.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
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
#
# Error log - should be very few entries.
#
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.   

    >sudo /etc/init.d/mysql start
    Rather than invoking init scripts through /etc/init.d, use the service(8)
    utility, e.g. service mysql startSince the script you are attempting to invoke has been converted to an
    Upstart job, you may also use the start(8) utility, e.g. start mysql
    start: Job failed to start不晓得怎么就启动不了了,看报错日志也看不懂
    error.log文件:130416  9:39:03 [Note] Plugin 'FEDERATED' is disabled.
    130416  9:39:03 InnoDB: The InnoDB memory heap is disabled
    130416  9:39:03 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    130416  9:39:03 InnoDB: Compressed tables use zlib 1.2.7
    130416  9:39:03 InnoDB: Using Linux native AIO
    130416  9:39:03 InnoDB: Initializing buffer pool, size = 128.0M
    130416  9:39:03 InnoDB: Completed initialization of buffer pool
    InnoDB: The first specified data file ./ibdata1 did not exist:
    InnoDB: a new database to be created!
    130416  9:39:03  InnoDB: Setting file ./ibdata1 size to 10 MB
    InnoDB: Database physically writes the file full: wait...
    130416  9:39:03  InnoDB: Log file ./ib_logfile0 did not exist: new to be created
    InnoDB: Setting log file ./ib_logfile0 size to 5 MB
    InnoDB: Database physically writes the file full: wait...
    130416  9:39:03  InnoDB: Log file ./ib_logfile1 did not exist: new to be created
    InnoDB: Setting log file ./ib_logfile1 size to 5 MB
    InnoDB: Database physically writes the file full: wait...
    InnoDB: Doublewrite buffer not found: creating new
    InnoDB: Doublewrite buffer created
    InnoDB: 127 rollback segment(s) active.
    InnoDB: Creating foreign key constraint system tables
    InnoDB: Foreign key constraint system tables created
    130416  9:39:04  InnoDB: Waiting for the background threads to start
    130416  9:39:05 InnoDB: 1.1.8 started; log sequence number 0
    130416  9:39:05  InnoDB: Starting shutdown...
    130416  9:39:06  InnoDB: Shutdown completed; log sequence number 1595675
    130416  9:39:06 [Note] Plugin 'FEDERATED' is disabled.
    130416  9:39:06 InnoDB: The InnoDB memory heap is disabled
    130416  9:39:06 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    130416  9:39:06 InnoDB: Compressed tables use zlib 1.2.7
    130416  9:39:06 InnoDB: Using Linux native AIO
    130416  9:39:06 InnoDB: Initializing buffer pool, size = 128.0M
    130416  9:39:06 InnoDB: Completed initialization of buffer pool
    130416  9:39:06 InnoDB: highest supported file format is Barracuda.
    130416  9:39:06  InnoDB: Waiting for the background threads to start
    130416  9:39:07 InnoDB: 1.1.8 started; log sequence number 1595675
    130416  9:39:07  InnoDB: Starting shutdown...
    130416  9:39:08  InnoDB: Shutdown completed; log sequence number 1595675
    130416  9:39:08 [Note] Plugin 'FEDERATED' is disabled.
    130416  9:39:08 InnoDB: The InnoDB memory heap is disabled
    130416  9:39:08 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    130416  9:39:08 InnoDB: Compressed tables use zlib 1.2.7
    130416  9:39:08 InnoDB: Using Linux native AIO
    130416  9:39:08 InnoDB: Initializing buffer pool, size = 128.0M
    130416  9:39:08 InnoDB: Completed initialization of buffer pool
    130416  9:39:08 InnoDB: highest supported file format is Barracuda.
    130416  9:39:08  InnoDB: Waiting for the background threads to start
    130416  9:39:09 InnoDB: 1.1.8 started; log sequence number 1595675
    ERROR: 1064  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALTER TABLE user ADD column Show_view_priv enum('N','Y') CHARACTER SET utf8 NOT ' at line 1
    130416  9:39:09 [ERROR] Aborting130416  9:39:09  InnoDB: Starting shutdown...
    130416  9:39:10  InnoDB: Shutdown completed; log sequence number 1595675
    130416  9:39:10 [Note] /usr/sbin/mysqld: Shutdown complete130416  9:39:10 [Note] Plugin 'FEDERATED' is disabled.
    130416  9:39:10 InnoDB: The InnoDB memory heap is disabled
    130416  9:39:10 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    130416  9:39:10 InnoDB: Compressed tables use zlib 1.2.7
    130416  9:39:10 InnoDB: Using Linux native AIO
    130416  9:39:10 InnoDB: Initializing buffer pool, size = 128.0M
    130416  9:39:10 InnoDB: Completed initialization of buffer pool
    130416  9:39:10 InnoDB: highest supported file format is Barracuda.
    130416  9:39:10  InnoDB: Waiting for the background threads to start
    130416  9:39:11 InnoDB: 1.1.8 started; log sequence number 1595675
    130416  9:39:11  InnoDB: Starting shutdown...
    130416  9:39:12  InnoDB: Shutdown completed; log sequence number 1595675
    130416  9:39:12 [Note] Plugin 'FEDERATED' is disabled.
    130416  9:39:12 InnoDB: The InnoDB memory heap is disabled
    130416  9:39:12 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    130416  9:39:12 InnoDB: Compressed tables use zlib 1.2.7
    130416  9:39:12 InnoDB: Using Linux native AIO
    130416  9:39:12 InnoDB: Initializing buffer pool, size = 128.0M
    130416  9:39:12 InnoDB: Completed initialization of buffer pool
    130416  9:39:12 InnoDB: highest supported file format is Barracuda.
    130416  9:39:12  InnoDB: Waiting for the background threads to start
    130416  9:39:13 InnoDB: 1.1.8 started; log sequence number 1595675
    ERROR: 1050  Table 'plugin' already exists
    130416  9:39:13 [ERROR] Aborting130416  9:39:13  InnoDB: Starting shutdown...
    130416  9:39:14  InnoDB: Shutdown completed; log sequence number 1595675
    130416  9:39:14 [Note] /usr/sbin/mysqld: Shutdown complete130416  9:39:14 [Note] Plugin 'FEDERATED' is disabled.
    130416  9:39:14 InnoDB: The InnoDB memory heap is disabled
    130416  9:39:14 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    130416  9:39:14 InnoDB: Compressed tables use zlib 1.2.7
    130416  9:39:14 InnoDB: Using Linux native AIO
    130416  9:39:14 InnoDB: Initializing buffer pool, size = 128.0M
    130416  9:39:14 InnoDB: Completed initialization of buffer pool
    130416  9:39:14 InnoDB: highest supported file format is Barracuda.
    130416  9:39:15  InnoDB: Waiting for the background threads to start
    130416  9:39:16 InnoDB: 1.1.8 started; log sequence number 1595675
    130416  9:39:16 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
    130416  9:39:16 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
    130416  9:39:16 [Note] Server socket created on IP: '127.0.0.1'.
    130416  9:39:16 [Note] Event Scheduler: Loaded 0 events
    130416  9:39:16 [Note] /usr/sbin/mysqld: ready for connections.
    Version: '5.5.29-0ubuntu0.12.10.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)
    130416 10:23:37 [Note] /usr/sbin/mysqld: Normal shutdown130416 10:23:37 [Note] Event Scheduler: Purging the queue. 0 events
    130416 10:23:38  InnoDB: Starting shutdown...
    130416 10:23:39  InnoDB: Shutdown completed; log sequence number 47858427
    130416 10:23:39 [Note] /usr/sbin/mysqld: Shutdown complete
      

  2.   

    ps -ef | grep mysql取的进程号  然后kill -9掉
    然后重启mysql 然后别用socket登陆  mysql -h127.0.0.1登陆