我是靠谱客的博主 听话洋葱,最近开发中收集的这篇文章主要介绍在CentOS7中安装配置MySQL8.0.21详细过程查询卸载其它旧版本的SQL查询系统版本根据操作系统版本下载合适的MySQL安装包将下载好的MySQL8.0.21安装包放在指定目录下  初始化数据、用户授权、开启服务、启用数据设置密码登录等……,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

查询卸载其它旧版本的SQL

查询已安装MySQL或者mariadb的命令为:

rpm -qa|grep mysql;
rpm -qa|grep mariadb;

查询结果:

[root@dosbo-01 ~]# rpm -qa|grep mysql
pcp-pmda-mysql-3.11.3-4.el7.x86_64
mysql57-community-release-el7-9.noarch
qt-mysql-4.8.5-13.el7.x86_64

[root@dosbo-01 ~]# rpm -qa | grep mariadb
mariadb-5.5.52-1.el7.x86_64
mariadb-server-5.5.52-1.el7.x86_64
mariadb-libs-5.5.52-1.el7.x86_64
mariadb-devel-5.5.52-1.el7.x86_64

删除:

rpm -evh --nodeps pcp-pmda-mysql-3.11.3-4.el7.x86_64;
rpm -evh --nodeps mysql57-community-release-el7-9.noarch;
rpm -evh --nodeps qt-mysql-4.8.5-13.el7.x86_64;

rpm -evh --nodeps mariadb-5.5.52-1.el7.x86_64;
rpm -evh --nodeps mariadb-server-5.5.52-1.el7.x86_64;
rpm -evh --nodeps mariadb-libs-5.5.52-1.el7.x86_64;
rpm -evh --nodeps mariadb-devel-5.5.52-1.el7.x86_64;

查询系统版本

查询命令:

cat /etc/redhat-release;

根据操作系统版本下载合适的MySQL安装包

官方下载地址:MySQL :: Download MySQL Community Server (Archived Versions)

选择如下包

将下载好的MySQL8.0.21安装包放在指定目录下 

这里我是通过xshell直接移入到服务器的/usr/local/mysql目录下

 可能会出现没有权限的情况(当向linux服务端上传文件的时候,提示permission not allowed)

sudo chmod 777 /usr/local/mysql

 进入/usr/local/mysql 目录查看文件

[root@dosbo-01 ~]# cd /usr/local/mysql
[root@dosbo-01 mysql]# ls
mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar

 解压文件并查看是否成功

tar -xvf mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar 
[root@dosbo-01 mysql]# tar -xvf mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar 
mysql-community-common-8.0.21-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.21-1.el7.x86_64.rpm
mysql-community-libs-8.0.21-1.el7.x86_64.rpm
mysql-community-devel-8.0.21-1.el7.x86_64.rpm
mysql-community-server-8.0.21-1.el7.x86_64.rpm
mysql-community-client-8.0.21-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.21-1.el7.x86_64.rpm
mysql-community-test-8.0.21-1.el7.x86_64.rpm
[root@dosbo-01 mysql]# ls
mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-8.0.21-1.el7.x86_64.rpm
mysql-community-common-8.0.21-1.el7.x86_64.rpm
mysql-community-devel-8.0.21-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.21-1.el7.x86_64.rpm
mysql-community-libs-8.0.21-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.21-1.el7.x86_64.rpm
mysql-community-server-8.0.21-1.el7.x86_64.rpm
mysql-community-test-8.0.21-1.el7.x86_64.rpm

 依次安装common、libs、client、server模块,命令如下:

[root@dosbo-01 mysql]# rpm -ivh mysql-community-common-8.0.21-1.el7.x86_64.rpm --nodeps --force;
[root@dosbo-01 mysql]# rpm -ivh mysql-community-libs-8.0.21-1.el7.x86_64.rpm --nodeps --force;
[root@dosbo-01 mysql]# rpm -ivh mysql-community-client-8.0.21-1.el7.x86_64.rpm --nodeps --force;
[root@dosbo-01 mysql]# rpm -ivh mysql-community-server-8.0.21-1.el7.x86_64.rpm --nodeps --force;

 初始化数据、用户授权、开启服务、启用数据

初始化数据库:

[root@dosbo-01 mysql]# mysqld --initialize

用户授权:

[root@dosbo-01 mysql]# chown -R mysql:mysql /usr/local/mysql

开启服务:

[root@dosbo-01 mysql]# systemctl start mysqld.service;

在这一步可能会出现这个错误:

[root@dosbo-01 mysql]# 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.

解决方法如下:

[root@dosbo-01 mysql]# chmod -R 777 /var/lib/mysql
[root@dosbo-01 mysql]# chown mysql:mysql -R /var/lib/mysql
[root@dosbo-01 mysql]# systemctl start mysqld.service
[root@dosbo-01 mysql]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-09-15 06:47:10 UTC; 10s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 5733 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 5760 (mysqld)
   Status: "Server is operational"
    Tasks: 39
   Memory: 356.9M
   CGroup: /system.slice/mysqld.service
           └─5760 /usr/sbin/mysqld

Sep 15 06:47:05 dosbo-01 systemd[1]: Starting MySQL Server...
Sep 15 06:47:10 dosbo-01 systemd[1]: Started MySQL Server.

启用数据:

[root@dosbo-01 mysql]# systemctl  enable mysqld;

设置密码登录等……

查询初始密码命令:

cat /var/log/mysqld.log | grep password

如下图所示,查询的结果为:)dZaf<jqo4mh

[root@dosbo-01 mysql]# cat /var/log/mysqld.log | grep password
2021-09-15T06:45:29.493159Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: )dZaf<jqo4mh


登录命令:

[root@dosbo-01 mysql]# mysql -uroot -p

回车后Enter password处直接粘贴前面复制的密码即可。

命令:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

修改密码成功后,可输入quit或exit,或者按Ctrl+d退出MySQL,重新用新密码登录。

这里设置密码可能也会有错误,如果想设置简单密码可以修改密码简单规则(部分可能不需要……)

mysql> show variables like "%validate%";
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| innodb_validate_tablespace_paths     | ON    |
| validate_password.check_user_name    | ON    |
| validate_password.dictionary_file    |       |
| validate_password.length             | 8     |
| validate_password.mixed_case_count   | 1     |
| validate_password.number_count       | 1     |
| validate_password.policy             | LOW   |
| validate_password.special_char_count | 1     |
+--------------------------------------+-------+
8 rows in set (0.01 sec)

mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;  //刷新权限
Query OK, 0 rows affected (0.00 sec)

最后

以上就是听话洋葱为你收集整理的在CentOS7中安装配置MySQL8.0.21详细过程查询卸载其它旧版本的SQL查询系统版本根据操作系统版本下载合适的MySQL安装包将下载好的MySQL8.0.21安装包放在指定目录下  初始化数据、用户授权、开启服务、启用数据设置密码登录等……的全部内容,希望文章能够帮你解决在CentOS7中安装配置MySQL8.0.21详细过程查询卸载其它旧版本的SQL查询系统版本根据操作系统版本下载合适的MySQL安装包将下载好的MySQL8.0.21安装包放在指定目录下  初始化数据、用户授权、开启服务、启用数据设置密码登录等……所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部