mysql无法启动(Table 'mysql.plugin' doesn't exist)

151226 17:49:20 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
/usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist
151226 17:49:20 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
151226 17:49:20  InnoDB: Initializing buffer pool, size = 8.0M
151226 17:49:20  InnoDB: Completed initialization of buffer pool
InnoDB: Log scan progressed past the checkpoint lsn 0 37356
151226 17:49:20  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 0 44233
151226 17:49:20  InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 
InnoDB: Apply batch completed
151226 17:49:21  InnoDB: Started; log sequence number 0 44233
151226 17:49:21 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
151226 17:49:21 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

因为/etc/my.cnf
里面设置字符集的时候顺手写了个utf-8,然后初始化数据库的时候就报错了。utf-8之间的一横是不能加的。加了之后就不对了,提示这个

151226 17:45:28 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
^G/usr/libexec/mysqld: Character set 'utf-8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
151226 17:45:28 [ERROR] Aborting

151226 17:45:28 [Note] /usr/libexec/mysqld: Shutdown complete

151226 17:45:28 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

然后就只有删除数据库了

rm -rf /var/lib/mysql

很不巧的是我cd到了/var/lib/mysql
然后重启的时候

[root@xuegod83 mysql]# service mysqld restart
shell-init: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
chdir: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
停止 mysqld:                                              [确定]
正在启动 mysqld:                                          [确定]

就提示了这个错误,以为是mysql配置文件哪里写错了。查了下才知道因为把/var/lib/mysql 删除了,导致当前所在位置已经不存在了。删除这个文件夹也是为了解决那个初始化的时候的错误。之前看这个文件夹是有东西,删除了之后重新的时候的时候没报错,但这个文件夹也没生成东西了,不知道会不会出问题。

紧着着连接数据库的时候就报错了

[root@xuegod83 ~]# mysql -uroot -pwangjun1009
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

我就手动创建了原来删除的/var/lib/mysql 然后改权限

[root@xuegod83 ~]# mkdir /var/lib/mysql
[root@xuegod83 ~]# chown mysql:mysql -R /var/lib/mysql/ 

然后重启服务

[root@xuegod83 ~]# service mysqld restart
停止 mysqld:                                              [确定]
初始化 MySQL 数据库: WARNING: The host 'xuegod83' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
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:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h xuegod83 password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [确定]
正在启动 mysqld:                                          [确定]

不出所料,这才是初始化了数据库

[root@xuegod83 ~]# ll /var/lib/mysql/
总用量 20488
-rw-rw---- 1 mysql mysql 10485760 1226 18:06 ibdata1
-rw-rw---- 1 mysql mysql  5242880 1226 18:06 ib_logfile0
-rw-rw---- 1 mysql mysql  5242880 1226 18:06 ib_logfile1
drwx------ 2 mysql mysql     4096 12月 26 18:06 mysql
srwxrwxrwx 1 mysql mysql        0 12月 26 18:06 mysql.sock
drwx------ 2 mysql mysql     4096 12月 26 18:06 test

你可能感兴趣的:(服务搭建)