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.’;