centos7安装MySQL8.0.16
我常常因为环境问题,影响开发进度。就像这次我因为在centos7安装mysql耽搁了好久,我刚开始安装的是5.7版本,装完后,起不来,翻阅网上各种解决方案,都解决不了问题。无奈,我打算重装,换个高版本(MySQL8.0.16),结果MySQL8.0.16和之前的版本有少许差异,也是折腾了我好些时间,所以,我打算把安装调试过程记录下,方便日后参阅。第一步,清理环境1. 首先,我们可以使用命令...
我常常因为环境问题,影响开发进度。就像这次我因为在centos7安装mysql耽搁了好久,我刚开始安装的是5.7版本,装完后,起不来,翻阅网上各种解决方案,都解决不了问题。无奈,我打算重装,换个高版本(MySQL8.0.16),结果MySQL8.0.16和之前的版本有少许差异,也是折腾了我好些时间,所以,我打算把安装调试过程记录下,方便日后参阅。
第一步,清理环境
1. 首先,查看系统是否已经安装了mysql数据库
rpm -qa | grep mysql
演示如下:
[root@localhost etc]# rpm -qa | grep mysql
mysql-community-libs-8.0.16-2.el7.x86_64
mysql-community-common-8.0.16-2.el7.x86_64
mysql-community-client-8.0.16-2.el7.x86_64
mysql80-community-release-el7-3.noarch
mysql-community-server-8.0.16-2.el7.x86_64
2. 查询到已安装的MySQL库后,执行以下命令依次卸载
yum remove mysql-xxx-xxx
若没有查询后,没有安装Mysql库,可直接跳过此步。
3. 删除mysql的配置文件(MySQL卸载不会自动删除配置文件,需自行清理)
首先使用如下命令查找出所用的配置文件
find / -name mysql
[root@localhost etc]# find / -name mysql
/etc/logrotate.d/mysql
/var/lib/docker/overlay2/a74267a6cde69551beede82788b48f1430f6ac88e4c7a8cdf9bcf16b2125aac6/diff/etc/mysql
/var/lib/docker/overlay2/a74267a6cde69551beede82788b48f1430f6ac88e4c7a8cdf9bcf16b2125aac6/diff/usr/include/mysql
/var/lib/docker/overlay2/a74267a6cde69551beede82788b48f1430f6ac88e4c7a8cdf9bcf16b2125aac6/diff/usr/include/mysql/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql
根据需求使用以下命令 依次 对配置文件进行删除
rm -rf /var/lib/mysql
二、删除MariaDB的文件
由于 在CentOS中默认安装有MariaDB,所以如果我们不删除MariaDB文件的话,安装mysql时可能会发生冲突。冲突信息如下:
[root@localhost yum.repos.d]# yum install mysql-community-server.x86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* epel: mirrors.ustc.edu.cn
* extras: mirrors.163.com
* updates: centos.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package mariadb-server.x86_64 1:5.5.52-1.el7 will be obsoleted
--> Processing Dependency: mariadb-server for package: akonadi-mysql-1.9.2-4.el7.x86_64
---> Package mysql-community-server.x86_64 0:5.7.19-1.el7 will be obsoleting
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.19-1.el7 for package: mysql-community-server-5.7.19-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.19-1.el7.x86_64
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be obsoleted
---> Package mariadb-server.x86_64 1:5.5.52-1.el7 will be obsoleted
--> Processing Dependency: mariadb-server for package: akonadi-mysql-1.9.2-4.el7.x86_64
---> Package mysql-community-client.x86_64 0:5.7.19-1.el7 will be obsoleting
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.19-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.19-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: perl-DBD-MySQL-4.023-5.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:qt-mysql-4.8.5-13.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: perl-DBD-MySQL-4.023-5.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 1:qt-mysql-4.8.5-13.el7.x86_64
---> Package mariadb-server.x86_64 1:5.5.52-1.el7 will be obsoleted
--> Processing Dependency: mariadb-server for package: akonadi-mysql-1.9.2-4.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.19-1.el7 will be obsoleting
--> Running transaction check
---> Package mariadb-server.x86_64 1:5.5.52-1.el7 will be obsoleted
--> Processing Dependency: mariadb-server for package: akonadi-mysql-1.9.2-4.el7.x86_64
---> Package mysql-community-libs-compat.x86_64 0:5.7.19-1.el7 will be obsoleting
--> Finished Dependency Resolution
Error: Package: akonadi-mysql-1.9.2-4.el7.x86_64 (@anaconda)
Requires: mariadb-server
Removing: 1:mariadb-server-5.5.52-1.el7.x86_64 (@anaconda)
mariadb-server = 1:5.5.52-1.el7
Obsoleted By: mysql-community-server-5.7.19-1.el7.x86_64 (mysql57-community)
Not found
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
1.使用rpm 命令查找出要删除的mariadb文件,命令如下
rpm -pa | grep mariadb
可能出现结果
mariadb-libs-5.5.56-2.el7.x86_64
删除上面的程序
yum -y remove mariadb-libs.x86_64
至此,原有的mysql和mariadb数据库就删除了
三、安装mysql
1. 安装mysql官网提供的mysql repo源
网址:https://dev.mysql.com/downloads/repo/yum/ 操作如下:
2. 使用命令“yum install wget 安装wget,接下来在线安装mysql。使用命令
wget http://dev.mysql.com/get/Downloads/mysql80-community-release-el7-1.noarch.rpm
3. 安装mysql80-community-release-el7-1.noarch.rpm包。使用命令:
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
4. 使用命令 “yum install mysql-community-server”安装mysql。大概有1个多G,请耐心等待安装完成
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
四、mysql初始化配置
启动mysqld服务,并设为开机自动启动。命令:
systemctl start mysqld.service //这是centos7的命令
systemctl enable mysqld.service
五、修改初始密码
1.编辑MyQL配置文件添加以下内容
[root@localhost etc]# vim /etc/my.cnf
添加以下内容
default-authentication-plugin=mysql_native_password #配置文件本来就有去掉注释即可
symbolic-links=0
skip-grant-tables
保存后退出。
2. 重启MySQL服务
systemctl restart mysqld
3.无密码登录MySQL
mysql -u root -p
演示如下:
[root@localhost etc]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.16 MySQL Community Server - GPL
Copyright (c) 2000, 2019, 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>
Enter password:直接敲回车
4. 进入Mysql操作界面后,执行如下
(1)将原密码设置为空
update user set authentication_string=’’ where user=‘root’;
(2) 将root密码设置Haha@123,注意Mysql8密码设置规则必须是大小写字母+特殊符号+数字的类型
alter user ‘root’@‘localhost’ identified by ‘Haha@123’;
(3)将host更改% 方便远程接入
update user set host =’%’ where user=‘root’;
(4)使用已经设置的密码来更改加密方式
ALTER USER ‘root’@’%’ IDENTIFIED BY ‘Haha@123’ PASSWORD EXPIRE NEVER;
(5)使用新的加密方式重新设置密码
ALTER USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY 'Haha@5678;
刷新
flush privileges;
重启MySQL服务
systemctl restart mysqld
分析修改密码环节
我第一次操作到4小节的(3)就重启了,发现本地登录不进去,远程也登录不进去,
后来网上搜索才知道,MySQL8.0的加密规则有所改变,要想用Navicate这样的客户端
连接的话,必须修改加密规则。但是加密规则更改又必须在设置密码的情况下修改,
所以我才改了两次密码,第一次密码是Haha@123,更改完后我就有资格修改加密规则
了,等我加密规则修改后,我就再用新的加密规则把密码再改一次,这之后刷新,然后
重启,我就可正常使用Mysql了。
以下附上我解决此问题的博文
https://blog.csdn.net/qq_39038465/article/details/81663540
https://www.cnblogs.com/whoknows1/p/9476473.html
更多推荐
所有评论(0)