用户登录
用户注册

分享至

Centos系统安装mysql服务错误解决

  • 作者: 我就想取个名字
  • 来源: 51数据库
  • 2020-08-31
最近在CentOS release 6.3上安装了mysql,但是mysqladmin -u root password 123456命令的时候,却出现如下的错误:
view sourceprint?
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 <a 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命令启动守护进程,却又出现启动服务失败的信息:
view sourceprint?
1.service mysqld start
2.<a Daemon failed to start.
3.Starting mysqld: [FAILED]

这下就头大了,启动服务竟然失败了。而且又没有任何相关的错误信息,所以只能查看它的错误日志,如下所示:
www.it165.net
view sourceprint?
01.tail -n 20 /var/log/mysqld.log 
02.120907 13:52:30 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
03.120907 13:52:30 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
04.120907 14:06:24 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
05./usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist
06.120907 14:06:24 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
07.120907 14:06:24 InnoDB: Initializing buffer pool, size = 8.0M
08.120907 14:06:24 InnoDB: Completed initialization of buffer pool
09.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服务后,一般需要执行数据库初始化操作 ,从而生成与权限相关的表,执行命令如下:
view sourceprint?
1./usr/bin/mysql_install_db --user=mysql

以上命令中的mysql_install_db与你安装的mysql服务位置有关,如果不知道在哪,可以使用find / -name mysql_install_db找到其位置,然后执行上面的命令。
  然后在执行数据库服务启动操作,便可以设置你mysql数据库的用户及密码了:
view sourceprint?
01.service mysqld start
02.Starting mysqld: [ OK ]
03.[root@host usr]# mysqladmin -u root pass<a target="_blank" class="keylink">word</a> 123456
04.[root@host usr]# mysql -u root -p
05.Enter pass<a  target="_blank"class="keylink">word</a>: 
06.Welcome to the MySQL monitor. Commands end with ; or \g.
07.Your MySQL connection id is 3
08.Server version: 5.1.61 Source distribution
09. 
10.Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
11. 
12.Oracle is a registered trademark of Oracle Corporation and/or its
13.affiliates. Other names may be trademarks of their respective
14.owners.
15. 
16.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

软件
前端设计
程序设计
Java相关