centos7安装配置MySQL8

配置源

进入https://dev.mysql.com/downloads/repo/yum/页面选择合适的系统的源进行下载,我这里使用的centos7所以使用源https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm
下载:

wget https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm

安装:

sudo yum install mysql80-community-release-el7-7.noarch.rpm

安装MySQL

  1. 查看MySQL相关源yum repolist all | grep mysql
  2. 默认安装的是MySQL8.0,可以使用命令切换默认安装版本(跳过)
$> sudo yum-config-manager --disable mysql57-community
$> sudo yum-config-manager --enable mysql80-community

或编辑文件 /etc/yum.repos.d/mysql-community.repo file修改enabled=0关闭,enabled=1开启

# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 8.0
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

查看MySQL对应开启的源 yum repolist enabled | grep mysql

  1. 关闭默认的MySQL模块 sudo yum module disable mysql 没有就跳过
  2. 安装MySQL sudo yum install mysql-community-server
    如果安装报错:
---> 软件包 mariadb-server.x86_64.1.5.5.68-1.el7 将被 取代
--> 正在处理依赖关系 mariadb-server,它被软件包 akonadi-mysql-1.9.2-4.el7.x86_64 需要
---> 软件包 mysql-community-client-plugins.x86_64.0.8.0.31-1.el7 将被 安装
---> 软件包 mysql-community-libs.x86_64.0.8.0.31-1.el7 将被 舍弃
--> 正在检查事务
---> 软件包 mariadb-server.x86_64.1.5.5.68-1.el7 将被 取代
--> 正在处理依赖关系 mariadb-server,它被软件包 akonadi-mysql-1.9.2-4.el7.x86_64 需要
---> 软件包 mysql-community-libs-compat.x86_64.0.8.0.31-1.el7 将被 舍弃
--> 解决依赖关系完成
错误:软件包:akonadi-mysql-1.9.2-4.el7.x86_64 (@anaconda)
          需要:mariadb-server
          正在删除: 1:mariadb-server-5.5.68-1.el7.x86_64 (@anaconda)
              mariadb-server = 1:5.5.68-1.el7
          取代,由: mysql-community-server-8.0.31-1.el7.x86_64 (mysql80-community)
              未找到
 您可以尝试添加 --skip-broken 选项来解决该问题
 您可以尝试执行:rpm -Va --nofiles --nodigest

使用命令移除mariadb-libs yum -y remove mariadb-libs,重新运行安装命令。
6. 然后就是一路确认安装即可。

配置MySQL

  1. 开启mysqld服务systemctl start mysqldservice mysqld start
  2. 查看开启状态systemctl status mysqld
  3. 服务启动后会创建一个默认的账户'root'@'localhost,其默认密码生成路径为/var/log/mysqld.log
    查看默认密码 sudo grep 'temporary password' /var/log/mysqld.log cat /var/log/mysqld.log
[root@localhost]# cat /var/log/mysqld.log
2022-12-01T15:56:28.931265Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31) initializing of server in progress as process 61451
2022-12-01T15:56:28.940674Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-12-01T15:56:29.973257Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-12-01T15:56:31.097144Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: g&yP+f_T_1V.
2022-12-01T15:56:33.377470Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.31) starting as process 61644
2022-12-01T15:56:33.665946Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-12-01T15:56:35.150925Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-12-01T15:56:35.885498Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-12-01T15:56:35.885596Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-12-01T15:56:35.995928Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.31'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.
2022-12-01T15:56:35.996186Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock

  1. 登录mysql -uroot -p 输入自己对应的临时密码
  2. 修改登录密码ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

用户创建、权限相关:https://blog.csdn.net/u013271384/article/details/118438047

配置文件位置:/etc/my.inf
配置相关调整: http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

官方网址:https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html
密码验证相关:https://dev.mysql.com/doc/refman/8.0/en/validate-password.html

你可能感兴趣的:(Mysql,mysql,数据库,linux)