Notas de estudio básico de MySQL: instalación de la base de datos MySQL

Instalar la base de datos MySQL

1. Descarga de MySQL

Enlace de descarga: http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar

Elección: mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar (también se pueden seleccionar otras versiones adecuadas)


2. Instalación en plataforma Linux

  • Trabajo de requisito previo: desinstalar mariadb
[root@mysql ~]# yum remove mysql-libs -y
  • Descomprima mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar:
[root@mysql ~]# tar -xvf mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-devel-5.7.31-1.el7.x86_64.rpm
mysql-community-libs-5.7.31-1.el7.x86_64.rpm
mysql-community-client-5.7.31-1.el7.x86_64.rpm
mysql-community-server-5.7.31-1.el7.x86_64.rpm
mysql-community-embedded-5.7.31-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.31-1.el7.x86_64.rpm
mysql-community-common-5.7.31-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm
mysql-community-devel-5.7.31-1.el7.x86_64.rpm
mysql-community-test-5.7.31-1.el7.x86_64.rpm
  • Instale el paquete RPM:

Debido a que existen algunas dependencias entre los paquetes, deben instalarse en un orden determinado:

  1. mysql-community-common-5.7.31-1.el7.x86_64.rpm

    [root@mysql ~]# rpm -ivh mysql-community-common-5.7.31-1.el7.x86_64.rpm
    警告:mysql-community-common-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-common-5.7.31-1.e################################# [100%]
    
  2. mysql-community-libs-5.7.31-1.el7.x86_64.rpm

    [root@mysql ~]# rpm -ivh mysql-community-libs-5.7.31-1.el7.x86_64.rpm
    警告:mysql-community-libs-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-libs-5.7.31-1.el7################################# [100%]
    
  3. mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm

    [root@mysql ~]# rpm -ivh mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm
    警告:mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-libs-compat-5.7.3################################# [100%]
    
  4. mysql-community-client-5.7.31-1.el7.x86_64.rpm

    [root@mysql ~]# rpm -ivh mysql-community-client-5.7.31-1.el7.x86_64.rpm
    警告:mysql-community-client-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-client-5.7.31-1.e################################# [100%]
    
  5. mysql-community-server-5.7.31-1.el7.x86_64.rpm

    [root@mysql ~]# rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm
    警告:mysql-community-server-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
    错误:依赖检测失败:
            /usr/bin/perl 被 mysql-community-server-5.7.31-1.el7.x86_64 需要
            net-tools 被 mysql-community-server-5.7.31-1.el7.x86_64 需要
            perl(Getopt::Long) 被 mysql-community-server-5.7.31-1.el7.x86_64 需要
            perl(strict) 被 mysql-community-server-5.7.31-1.el7.x86_64 需要
    

    Se requieren Perl y net-tools, simplemente instálelo:

    [root@mysql ~]# yum install perl net-tools -y
    

    Una vez instalada la dependencia, puede instalarla:

    [root@mysql ~]# rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm
    警告:mysql-community-server-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-server-5.7.31-1.e################################# [100%]
    
  • Inicie MySQL:
[root@mysql ~]# systemctl start mysqld			#启动服务
[root@mysql ~]# systemctl enable mysqld			#开机自启
[root@mysql ~]# systemctl status mysqld			#查看状态
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2020-09-21 20:12:15 CST; 15s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 3278 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─3278 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mys...

9月 21 20:12:13 mysql systemd[1]: Starting MySQL Server...
9月 21 20:12:15 mysql systemd[1]: Started MySQL Server.
  • Inicie sesión en MySQL:

La versión posterior a MySQL 5.7 elimina la contraseña vacía del usuario root durante la instalación predeterminada. Al iniciar sesión por primera vez, el sistema generará una contraseña de root temporal, que se puede ver a través de /var/log/mysqld.log :

[root@mysql ~]# cat /var/log/mysqld.log | grep "password"
2020-09-21T12:12:13.721817Z 1 [Note] A temporary password is generated for root@localhost: Qqfpoxet1+p(
# 初始密码为:Qqfpoxet1+p(
[root@mysql ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31

Copyright (c) 2000, 2020, 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>

Entre ellos, mysql representa el comando del cliente, "-u" es seguido por el usuario de la base de datos y "-p" representa la contraseña que se debe ingresar. Al mismo tiempo, la interfaz de bienvenida también explica las siguientes partes:

  • Los comandos terminan con; o \ g. Los comandos terminan con ";" o "\ g"
  • Su ID de conexión MySQL es 2 El ID de conexión del cliente. Este número registra la cantidad de conexiones realizadas por el servicio MySQL hasta el momento; cada nueva conexión agregará automáticamente 1
  • Versión del servidor: 5.7.31 Versión y tipo del servidor MySQL
  • Escriba 'help;' o '\ h' para obtener ayuda. Escriba '\ c' para borrar la declaración de entrada actual. Use "help;" o "\ h" para mostrar el contenido de ayuda; use "\ c" para borrar la memoria caché de la línea de comandos

Sin embargo, la contraseña temporal no puede realizar la mayoría de las operaciones, como:

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.		
#提示要使用 ALTER USER 来修改初始密码
  • Cambia la contraseña:
mysql> alter user 'root'@'localhost' identified by 'Opfordream@0518';
Query OK, 0 rows affected (0.00 sec)
  • Configure el usuario root para iniciar sesión de forma remota:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Opfordream@0518' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
  • Configurar MySQL:
[root@mysql ~]# vim /etc/my.cnf
#增加如下内容
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8
[root@mysql ~]# systemctl restart mysqld	#重启 MySQL
  • Pruebe la conexión remota:

Se recomienda apagar primero el firewall en el lado del servidor:

[root@mysql ~]# systemctl stop firewalld
[root@mysql ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

Pruebe la conexión remota:

Inserte la descripción de la imagen aquí

Supongo que te gusta

Origin blog.csdn.net/qq_36879493/article/details/108719480
Recomendado
Clasificación