CentOS 7 安装 MySQL数据库遇到的问题

解决MySQL 5.7安装与登录问题
本文介绍了解决在CentOS上安装MySQL 5.7时遇到的文件冲突问题的方法,包括如何卸载预装的MariaDB库及正确的安装步骤。此外,还详细说明了首次登录MySQL 5.7时遇到权限拒绝错误的处理方案,并提供了获取和修改默认初始密码的具体步骤。

linux 镜像:CentOS-7-x86_64-DVD-1708.iso
MySQL版本:mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar
问题:
1. 执行 rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm 操作,遇到

file /usr/share/mysql/charsets/latin5.xml from install of mysql-community-common-5.7.21-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
    file /usr/share/mysql/charsets/latin7.xml from install of mysql-community-common-5.7.21-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
    file /usr/share/mysql/charsets/macce.xml from install of mysql-community-common-5.7.21-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
    file /usr/share/mysql/charsets/macroman.xml from install of mysql-community-common-5.7.21-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
    file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.21-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64

解决方式:
安装前先卸载自带的mariadb-lib(必须卸载,不然会碰到问题,我遇到的上述问题就是没有卸载自带的mariadb-lib造成的)

备注:如果删不掉的话可以试试这条命令:yum remove mysql-libs

然后依次安装:

  #rpm -ivh mysql-community-common-版本.el6.x86_64.rpm
  #rpm -ivh mysql-community-libs-版本.el6.x86_64.rpm
  #rpm -ivh mysql-community-client-版本.el6.x86_64.rpm
  #rpm -ivh mysql-community-server-版本.el6.x86_64.rpm

2.安装完成后需要数据库初始化:

为了保证数据库目录为与文件的所有者为 mysql 登陆用户,如果你是以 root 身份运行 mysql 服务,需要执行下面的命令初始化
 mysqld --initialize --user=mysql
 systemctl start mysqld.service

mysql-5.7.21登录数据库时报:
[root@hadoop-1 software]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
[root@hadoop-1 software]# mysql
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

使用 mysqladmin 修改也不行

[root@hadoop-1 software]# mysqladmin -uroot -passwd mysql
  mysqladmin: [Warning] Using a password on the command line interface can be insecure.
  mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
[root@hadoop-1 software]# mysqladmin -uroot -password 'mysql'
   mysqladmin: [Warning] Using a password on the command line interface can be insecure.
   mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
[root@hadoop-1 software]# mysql -uroot -pmysql
   mysql: [Warning] Using a password on the command line interface can be insecure.
   ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

解决方法:
从mysqld.log 文件中找到安装时的默认初始密码(只有密码没有修改的前提下才有用)

[root@hadoop-1 software]# cat /var/log/mysqld.log  | grep password  
   2018-03-25T12:37:00.542780Z 1 [Note] A temporary password is generated for root@localhost: xkh_QOrXB4M-
   2018-03-25T12:37:33.255719Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
   2018-03-25T12:37:42.349320Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO)

密码为第一行数据的: xkh_QOrXB4M-

然后登陆MySQL数据库成功

[root@hadoop-1 software]# mysql -u root -pxkh_QOrXB4M-
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.21
Copyright (c) 2000, 2018, 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.
mysql>

登陆后修改密码:
修改密码方式一.
mysql> alter user ‘root’@’localhost’ identified by ‘mysql’;
Query OK, 0 rows affected (0.00 sec)
mysql>

修改密码方式二.
mysql>alter user ‘root’@’localhost’ identified by ‘Mysqlpassw0rd.’;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值