CentOS 6.5 下安装配置 mysql
使用yum安装,具体过程参见最下边的参考文章。
安装之后启动失败:
[root@localhost ~]# service mysqld start
Starting mysqld: [ FAILD ]
启动失败,查看出错原因(记录在/var/log/mysqld.log 文件里):
[root@localhost ~]# cat /var/log/mysqld.log
190425 13:56:00 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
/usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist
190425 13:56:00 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
190425 13:56:00 InnoDB: Initializing buffer pool, size = 8.0M
190425 13:56:00 InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 50331648 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
190425 13:56:00 [ERROR] Plugin 'InnoDB' init function returned error.
190425 13:56:00 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
190425 13:56:00 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
190425 13:56:00 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
190425 13:58:07 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
190425 13:58:07 InnoDB: Initializing buffer pool, size = 8.0M
190425 13:58:07 InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 50331648 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
190425 13:58:07 [ERROR] Plugin 'InnoDB' init function returned error.
190425 13:58:07 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
190425 13:58:07 [Note] Event Scheduler: Loaded 0 events
190425 13:58:07 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.73' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
# 注意!(这里的提示是解决之后的,刚安装完mysql时启动是报错的,OK那里是FAILD)
# 这里的提示最后几行是解决之后启动了软件然后端口开放了。与前边报错显示在同一文件里了。)
mysql报错 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
解决方法:
mysql_install_db
(参考自文章2。)
# mysql默认不推荐用root用户来启动软件。正常情况下用root启动会有提示或报错,这里没有报错就启动了。需要注意一下。
[root@localhost ~]# service mysqld start
Starting mysqld: [ OK ]
mysqladmin 设置用户名初始密码报错you need the SUPER privilege for this operation
CREATE USER 'root'@'localhost' IDENTIFIED BY '[这里替换成想要设置的密码]';
GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'root'@'localhost';
GRANT ALL ON *.* TO 'root'@'localhost';
配置root远程访问
# 说明:mysql对用户访问的控制比较完善,同一个用户名从不同的机器访问同一数据库权限也是不同的。
# 以root为例。同一个用户root对应mysql数据库中user表里的多行数据。从本地访问时user表里对应host为localhost的一行。
# 即使user表里有一行的host叫做localhost.localdomain也不能从本地访问。(经验如此,具体原因不详)
# 从远程访问时需要配置user表里对应host为%的一行。
Enter password: *******
select user,host from user;
update user set host='%' where user='root';
flush privileges;
参考资料:
1、Linux学习之CentOS(十三)--CentOS6.4下Mysql数据库的安装与配置
2、mysql报错Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist