阿里云服务器Centos7安装MySQLCommunityServer8.0.21

database

官网地址:https://dev.mysql.com/downloads/mysql/

下载

1.  Select Operating System: 选择 Red Hat ,CentOS 是基于红帽的,Select OS Version: 选择 linux 7

2.  选择 RPM Bundle 点击 Download

安装

1 、解压

tar -xvf mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar

mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar解压后有如下8个文件: 

[root@VM_0_2_centos home]# 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

2、安装

建议装之前先把之前的mysql相关包全部卸载,rpm -e --nodeps <包名>即可

1. 卸载系统自带的mariadb-lib

  • 查看mariadb版本

rpm -qa | grep mariadb

  • 卸载mariadb  

rpm -e --nodeps mariadb-libs-5.5.65-1.el7.x86_64

 

2. 安装:

  • 必须安装(注意顺序)

rpm -ivh mysql-community-common-8.0.21-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-8.0.21-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-8.0.21-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-8.0.21-1.el7.x86_64.rpm

  • 非必要安装(注意顺序)

rpm -ivh mysql-community-libs-compat-8.0.21-1.el7.x86_64.rpm

rpm -ivh mysql-community-embedded-compat-8.0.21-1.el7.x86_64.rpm

rpm -ivh mysql-community-devel-8.0.21-1.el7.x86_64.rpm

rpm -ivh mysql-community-test-8.0.21-1.el7.x86_64.rpm

安装截图如下(注意顺序): 

rpm -ivh mysql-community-common-8.0.21-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-8.0.21-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-compat-8.0.21-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-8.0.21-1.el7.x86_64.rpm

yum install -y libnuma*

rpm -ivh mysql-community-server-8.0.21-1.el7.x86_64.rpm

yum install -y openssl-devel.x86_64 openssl.x86_64

rpm -ivh mysql-community-devel-8.0.21-1.el7.x86_64.rpm

yum install -y perl.x86_64 perl-devel.x86_64

yum install -y perl-JSON.noarch

yum -y install autoconf

rpm -ivh mysql-community-test-8.0.21-1.el7.x86_64.rpm

 

3、测试

mysql -V

显示如下信息说明安装成功

4. 修改默认配置

查看配置文件所在位置

ll /etc/my.cnf

-rw-r--r-- 1 root root 1243 Jun 17 01:58 /etc/my.cn

修改常用配置

1. 修改大小写敏感问题

vim /etc/my.cnf

添加如下信息:

#配置MYSQL大小写敏感(1-不敏感,0-敏感)

lower_case_table_names=1

注意!MySQL8.0想要 大小写不敏感,必须在安装好MySQL后未启动之前 修改MySQL配置文件设置为不敏感,一旦启动后,再设置是无效的,而且启动会报错。

如果已经晚了,那必须把MySQL数据库文件全部 删除,修改配置文件再启动。

 如果数据不重要,可以先关闭服务删掉数据,再执行以上操作:

service mysqld stop

rm -rf /var/lib/mysql

5、初始化数据库

mysqld --initialize --console

6、目录授权,否则启动失败

chown -R mysql:mysql /var/lib/mysql/

7、启动msyql服务

systemctl start mysqld

备注:
  停止命令:service mysqld stop

8、查看msyql服务的状态

service mysqld status


9、在/var/log/mysqld.log下查看临时密码

cat /var/log/mysqld.log

10、用临时密码登录到数据库

  • mysql -u root -p + 回车键
  • 输入临时密码(输入时不会显示出来,输入完直接回车)

11、执行下列mysql命令 修改密码

alter USER "root"@"localhost" IDENTIFIED BY "密码";

密码:必须包含数字及大小写字母特殊字符

12、授权远程连接

依次执行下列mysql命令 授权远程连接

     查看所有用户是否可以远程连接,依次执行下列命令:

  • show databases;
  • use mysql;
  • select host, user, authentication_string, plugin from user;

    修改root用户host值,使root用户可以远程登录

  • update user set host = "%" where user="root";

  • 刷新
    flush privileges;

13、结束

广而告之:【全民云计算】云服务器今日限时秒杀,新用户专享1折起

以上是 阿里云服务器Centos7安装MySQLCommunityServer8.0.21 的全部内容, 来源链接: utcz.com/z/535076.html

回到顶部