##一.卸载mariadb
列出所有被安装的rpm package
rpm -qa | grep mariadb
mariadb-libs-5.5.50-1.el7_2.x86_64
mariadb-5.5.50-1.el7_2.x86_64
mariadb-server-5.5.50-1.el7_2.x86_64
卸载
rpm -e mariadb-libs-5.5.50-1.el7_2.x86_64
此时报错:
error: Failed dependencies:
libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
libmysqlclient.so.18()(64bit) is needed by (installed) perl-DBD-MySQL-4.023-5.el7.x86_64
libmysqlclient.so.18()(64bit) is needed by (installed) php-mysql-5.4.16-36.3.el7_2.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) perl-DBD-MySQL-4.023-5.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) php-mysql-5.4.16-36.3.el7_2.x86_64
mariadb-libs(x86-64) = 1:5.5.50-1.el7_2 is needed by (installed) mariadb-1:5.5.50-1.el7_2.x86_64
mariadb-libs(x86-64) = 1:5.5.50-1.el7_2 is needed by (installed) mariadb-server-1:5.5.50-1.el7_2.x86_64
强制卸载,因为没有–nodeps
rpm -e --nodeps mariadb-libs-5.5.50-1.el7_2.x86_64
rpm -e --nodeps mariadb-5.5.50-1.el7_2.x86_64
rpm -e --nodeps mariadb-server-5.5.50-1.el7_2.x86_64
然后可以安装MySQL了。
##二.安装MySQL
CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载.传送门:
http://dev.mysql.com/downloads/repo/yum/
选择 Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package, Download. 得到地址
http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
yum install mysql-community-server
成功安装之后初始化MySQL
mysqld --initialize
mysql5.7会生成一个初始化密码,而在之前的版本首次登陆不需要登录。
搜索MySQL的日志文件
cat /var/log/mysqld.log | grep A temporary password is generated for root@localhost
2017-01-20 16:46:53.059632Z 1 [Note] A temporary password is generated for root@localhost: +wGVA#to(4tu
用上面的+wGVA#to(4tu就可以登录了
mysql -uroot -p+wGVA#to(4tu
重置密码,执行以下SQL语句
set password for 'root'@'localhost'=password('newpassword');
set password for 'root'@'%'=password('newpassword');
开启远程访问,执行以下SQL语句,其中password为数据库账户密码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
刷新数据
FLUSH PRIVILEGES;
##后续
最近在一台阿里云CentOS 7 64位服务器上安装MySQL,无论如何都找不到自动生成的密钥,重新安装几次无果后,由于是新安装,于是直接将
rm -rf /var/lib/mysql
文件夹删除,用初始化命令,重新初始化.
mysqld --initialize
最终获取控制台输出的密码:
2017-02-20T14:45:06.344885Z 1 [Note] A temporary password is generated for root@localhost: 5;4f5k(xgc1T
但这个时候出现一个新的问题,mysqld服务无法启动
service mysqld start
出错
Redirecting to /bin/systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
使用命令
systemctl status mysqld.service
和
journalctl -xe
输出
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Mon 2017-02-20 22:39:07 CST; 41s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 1216 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=1/FAILURE)
Process: 1199 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: Failed to start MySQL Server.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: Unit mysqld.service entered failed state.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: mysqld.service failed.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: mysqld.service holdoff time over, scheduling restart.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: start request repeated too quickly for mysqld.service
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: Failed to start MySQL Server.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: Unit mysqld.service entered failed state.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: mysqld.service failed.
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has begun starting up.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 13 - Permission denied)
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: 2017-02-20T14:39:07.471602Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: 2017-02-20T14:39:07.471725Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: 2017-02-20T14:39:07.471730Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: 2017-02-20T14:39:07.476447Z 0 [Warning] Can't create test file /var/lib/mysql/iZbp1bmnc8vn2gk235cg4dZ.lower-test
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: 2017-02-20T14:39:07.476503Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.17) starting as process 1220 ...
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: 2017-02-20T14:39:07.493302Z 0 [Warning] Can't create test file /var/lib/mysql/iZbp1bmnc8vn2gk235cg4dZ.lower-test
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: 2017-02-20T14:39:07.493827Z 0 [Warning] Can't create test file /var/lib/mysql/iZbp1bmnc8vn2gk235cg4dZ.lower-test
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: 2017-02-20T14:39:07.494310Z 0 [ERROR] failed to set datadir to /var/lib/mysql/
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: 2017-02-20T14:39:07.495364Z 0 [ERROR] Aborting
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: mysqld.service: control process exited, code=exited status=1
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: Initialization of mysqld failed: 0
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: 2017-02-20T14:39:07.497018Z 0 [Note] Binlog end
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: 2017-02-20T14:39:07.497183Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: Failed to start MySQL Server.
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has failed.
--
-- The result is failed.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: Unit mysqld.service entered failed state.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: mysqld.service failed.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: mysqld.service holdoff time over, scheduling restart.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: start request repeated too quickly for mysqld.service
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: Failed to start MySQL Server.
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has failed.
--
-- The result is failed.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: Unit mysqld.service entered failed state.
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ systemd[1]: mysqld.service failed.
注意这一行
Feb 20 22:39:07 iZbp1bmnc8vn2gk235cg4dZ mysqld[1216]: mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 13 - Permission denied)
权限问题导致mysql.lock写不了
chmod 777 -R /var/lib/mysql
OK,故障解除!