最近在CentOS release 6.3上安装了mysql,但是mysqladmin
-u root password 123456命令的时候,却出现如下的错误:
- /usr/bin/mysqladmin -u root password 123456
- /usr/bin/mysqladmin: connect to server at 'localhost' failed
- error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
- Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
发现可能的错误应该是mysqld服务守护进程没运行的原因,然后使用service mysqld status命令查看当前mysqld的服务状态,发现它确实是处于stopped状态,随后便想用service mysqld start命令启动守护进程,却又出现启动服务失败的信息:
- service mysqld start
- MySQL Daemon failed to start.
- Starting mysqld: [FAILED]
这下就头大了,启动服务竟然失败了。而且又没有任何相关的错误信息,所以只能查看它的错误日志,如下所示:
- tail -n 20 /var/log/mysqld.log
- 120907 13:52:30 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
- 120907 13:52:30 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
- 120907 14:06:24 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
- /usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist
- 120907 14:06:24 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
- 120907 14:06:24 InnoDB: Initializing buffer pool, size = 8.0M
- 120907 14:06:24 InnoDB: Completed initialization of buffer pool
- InnoDB: Log scan progressed past the checkpoint lsn 0 37356
- 120907 14:06:24 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
- 120907 14:06:24 InnoDB: Starting an apply batch of log records to the database...
- InnoDB: Progress in percents: 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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
- 120907 14:06:24 InnoDB: Started; log sequence number 0 44233
- 120907 14:06:24 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
- 120907 14:06:24 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pi
从中发现出现一个致命的错误,
Can't open and lock privilege tables: Table 'mysql.host' doesn't exist!这样问题也就找到了,table ‘mysql.host’不存在的原因是新安装的mysql服务后,一般需要
执行数据库初始化操作 ,从而生成与权限相关的表,执行命令如下:- /usr/bin/mysql_install_db --user=mysql
以上命令中的
mysql_install_db与你安装的mysql服务位置有关,如果不知道在哪,可以使用find / -name mysql_install_db找到其位置,然后执行上面的命令。 然后在执行数据库服务启动操作,便可以设置你mysql数据库的用户及密码了:
- service mysqld start
- Starting mysqld: [ OK ]
- [root@host usr]# mysqladmin -u root password 123456
- [root@host usr]# mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 3
- Server version: 5.1.61 Source distribution
- Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
阅读(3760) | 评论(0) | 转发(0) |