Chinaunix首页 | 论坛 | 博客
  • 博客访问: 299101
  • 博文数量: 22
  • 博客积分: 674
  • 博客等级: 上士
  • 技术积分: 792
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-19 00:48
文章存档

2013年(2)

2012年(20)

我的朋友

分类: Mysql/postgreSQL

2012-09-07 14:30:59

  最近在CentOS release 6.3上安装了mysql,但是mysqladmin -u root password 123456命令的时候,却出现如下的错误:

点击(此处)折叠或打开

  1. /usr/bin/mysqladmin -u root password 123456
  2. /usr/bin/mysqladmin: connect to server at 'localhost' failed
  3. error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
  4. Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
  发现可能的错误应该是mysqld服务守护进程没运行的原因,然后使用service mysqld status命令查看当前mysqld的服务状态,发现它确实是处于stopped状态,随后便想用service mysqld start命令启动守护进程,却又出现启动服务失败的信息:

点击(此处)折叠或打开

  1. service mysqld start
  2. MySQL Daemon failed to start.
  3. Starting mysqld: [FAILED]
  这下就头大了,启动服务竟然失败了。而且又没有任何相关的错误信息,所以只能查看它的错误日志,如下所示:

点击(此处)折叠或打开

  1. tail -n 20 /var/log/mysqld.log
  2. 120907 13:52:30 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
  3. 120907 13:52:30 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
  4. 120907 14:06:24 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
  5. /usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist
  6. 120907 14:06:24 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
  7. 120907 14:06:24 InnoDB: Initializing buffer pool, size = 8.0M
  8. 120907 14:06:24 InnoDB: Completed initialization of buffer pool
  9. InnoDB: Log scan progressed past the checkpoint lsn 0 37356
  10. 120907 14:06:24 InnoDB: Database was not shut down normally!
  11. InnoDB: Starting crash recovery.
  12. InnoDB: Reading tablespace information from the .ibd files...
  13. InnoDB: Restoring possible half-written data pages from the doublewrite
  14. InnoDB: buffer...
  15. InnoDB: Doing recovery: scanned up to log sequence number 0 44233
  16. 120907 14:06:24 InnoDB: Starting an apply batch of log records to the database...
  17. 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
  18. InnoDB: Apply batch completed
  19. 120907 14:06:24 InnoDB: Started; log sequence number 0 44233
  20. 120907 14:06:24 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
  21. 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服务后,一般需要执行数据库初始化操作 ,从而生成与权限相关的表,执行命令如下:

点击(此处)折叠或打开

  1. /usr/bin/mysql_install_db --user=mysql
  以上命令中的mysql_install_db与你安装的mysql服务位置有关,如果不知道在哪,可以使用find / -name mysql_install_db找到其位置,然后执行上面的命令
  然后在执行数据库服务启动操作,便可以设置你mysql数据库的用户及密码了:

点击(此处)折叠或打开

  1. service mysqld start
  2. Starting mysqld: [ OK ]
  3. [root@host usr]# mysqladmin -u root password 123456
  4. [root@host usr]# mysql -u root -p
  5. Enter password:
  6. Welcome to the MySQL monitor. Commands end with ; or \g.
  7. Your MySQL connection id is 3
  8. Server version: 5.1.61 Source distribution
  9. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  10. Oracle is a registered trademark of Oracle Corporation and/or its
  11. affiliates. Other names may be trademarks of their respective
  12. owners.
  13. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

阅读(3716) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~