centos7 安装MySQL5.7中遇到的问题和解决方法

centos7默认不支持mysql(原因大家都懂),默认支持的是mariadb,mariadb是mysql一个开源分支。

1、卸载mariadb,否则安装mysql会出现冲突

执行命令

rpm -qa | grep mariadba

列出所有被安装的mariadb rpm 包;

执行命令

rpm -e --nodeps 包名称(比如:rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64)

逐个将所有列出的mariadb rpm 包给卸载掉

2、添加官方的yum源

以centos7安装mysql5.7为例:

创建并编辑mysql-community.repo文件

vi /etc/yum.repos.d/mysql-community.repo

将以下内容粘贴进去并保存

[mysql56-community]

name=MySQL 5.7 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

注意:gpgcheck是GPG加密校验,官方文档中,值为1,但check会报错误,所以这里改为0跳过检查,对安装无影响。

同理,其他centos版本安装其他版本的mysql只需要改为对应的baseurl即可:

centos7安装mysql5.7:baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

centos6安装mysql5.6:baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/

centos6安装mysql5.7:baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/

3、安装

执行命令

sudo yum install mysql-community-server

4、启动

执行命令

sudo service mysqld start

5、改mysql 的root密码

再修改密码的时候会出现下列问题

解决过程:

1、编辑/etc/my.cnf

在[mysqld] 配置部分添加一行

skip-grant-tables

2、保存后重启mysql

[root@localhost etc]# service mysqld restart
Shutting down MySQL.                                       [  OK  ]
Starting MySQL.                                                   [  OK  ]

3、登录数据库重新设置root密码


[root@localhost ~]# mysql -uroot -p mysql
Enter password:

直接回车进入
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
执行下列语句
mysql>use mysql;
mysql> update user set password=password("mysql") where user='root';

新安装的MySQL5.7,登录时提示密码错误,安装的时候并没有更改密码,后来通过免密码登录的方式更改密码,输入update mysql.user  set password=password('root') where user='root'时提示ERROR 1054 (42S22): Unknown column 'password' in 'field list',原来是mysql数据库下已经没有password这个字段了,password字段改成了

 authentication_string

 所以更改语句替换为 update mysql.user set authentication_string=password('root') where user='root' ;

即可

最后再刷新修改

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

4、删除/etc/my.cnf文件中添加的“skip-grant-tables”行,重启mysql;

用新设的密码就能正常登录了;

centos7上安装MySQL成功

可能是新版本的原因对MySQL的密码要求很严,如果密码太过简单就会出现下面的问题

不管执行什么MySQL命令都会出现下面的错误

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this

设置你的密码

set password="YOUR_PASSWORD";

此时又会出现你的密码太过简单的错误提示,如果想要坚持使用简单的命令就要改下下面两个值的参数:

注意:如果只想设置简单密码需要修改两个全局参数:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;

猜你喜欢

转载自blog.csdn.net/qq_37194598/article/details/81190153