Uno, instalación del paquete RPM
1. Descargue el paquete de instalación de RPM del sitio web oficial y cárguelo en el servidor:
2. Compruebe si desea cargar:
[root@bogon ~]# ls -l mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar
-rw-r--r--. 1 root root 569344000 1月 11 15:06 mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar
3. Descomprima y vea:
[root@bogon ~]# tar xf mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar
[root@bogon ~]# ls -l mysql-community*
-rw-r--r--. 1 7155 31415 25012200 7月 14 2016 mysql-community-client-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 277608 7月 14 2016 mysql-community-common-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 3770552 7月 14 2016 mysql-community-devel-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 45366572 7月 14 2016 mysql-community-embedded-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 23925764 7月 14 2016 mysql-community-embedded-compat-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 125630688 7月 14 2016 mysql-community-embedded-devel-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 2235496 7月 14 2016 mysql-community-libs-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 2112812 7月 14 2016 mysql-community-libs-compat-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 51288740 7月 14 2016 mysql-community-minimal-debuginfo-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 158947688 7月 14 2016 mysql-community-server-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 14021340 7月 14 2016 mysql-community-server-minimal-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 116741256 7月 14 2016 mysql-community-test-5.7.14-1.el7.x86_64.rpm
4. Instale y primero restrinja los paquetes relacionados con mariadb :
[root@bogon ~]# yum remove mariadb-libs
[root@bogon ~]# yum install -ivh mysql-community-client-5.7.14-1.el7.x86_64.rpm mysql-community-common-5.7.14-1.el7.x86_64.rpm mysql-community-libs-5.7.14- 1.el7.x86_64.rpm mysql-community-server-5.7.14-1.el7.x86_64.rpm
5. Inicie el servicio y verifique el estado:
[root@bogon ~]# systemctl start mysqld
[root@bogon ~]# systemctl enable mysqld
[root@bogon ~]# systemctl is-active mysqld
active
6. Inicie sesión en la base de datos
①Obtenga la contraseña inicial de la base de datos:
[root@bogon ~]# awk '/temporary password/ {print $NF}' /var/log/mysqld.log
Ws-OZH#gl8pq
②Iniciar sesión:
[root@bogon ~]# 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.14
Copyright (c) 2000, 2016, 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> \q
Bye
Instalación de dos formatos binarios universales
1. Descargue la versión glibc de Mysql del sitio web y cárguela en el servidor:
2. Cree un nuevo usuario para ejecutar el proceso de forma segura:
[root@bogon ~]# groupadd -r -g 306 mysql //添加用户组
[root@bogon ~]# useradd -r -g 306 -u 306 mysql //添加用户
[root@bogon ~]# id mysql //查看用户信息
uid=306(mysql) gid=306(mysql) 组=306(mysql)
3. Instale e inicialice mysql:
① Instalación
[root@bogon ~]# tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar -C /usr/local //解压
[root@bogon ~]# cd /usr/local
[root@bogon local]# tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz //二次解压
[root@bogon local]# ln -s mysql-5.7.14-linux-glibc2.5-x86_64 mysql //制作软链接
[root@bogon local]# chown -R mysql.mysql mysql/* //更改权限
② Inicialización:
[root@bogon local]# mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2021-01-11T09:51:52.940057Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-01-11T09:51:53.235501Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-01-11T09:51:53.285861Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-01-11T09:51:53.348995Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a234c25a-53f2-11eb-83bc-000c29190c65.
2021-01-11T09:51:53.349625Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-01-11T09:51:53.364186Z 1 [Note] A temporary password is generated for root@localhost: 2QixadqkpG.o //此处标记数据库初始密码
4. Proporcione el archivo de configuración principal para mysql :
[root@bogon local]# cd /usr/local/mysql
[root@bogon mysql]# \cp support-files/my-default.cnf /etc/my.cnf
[root@bogon mysql]# vim /etc/my.cnf
添加如下行指定mysql数据文件的存放位置:
datadir = /usr/local/mysql/data
5. Proporcione el script de servicio sysv para mysql :
[root@bogon mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@bogon mysql]# chmod +x /etc/rc.d/init.d/mysqld
6. Inicie mysql:
[root@bogon bin]# chkconfig --add mysqld //添加为系统服务
[root@bogon bin]# # chkconfig mysqld on //开机自启动
[root@bogon bin]# systemctl start mysqld //启动mysql服务
7, el mysql 's bin directorio añaden a PATH variable de entorno, editar el archivo / etc / profile archivo:
[root@bogon mysql]# cd /etc/profile.d/
[root@bogon profile.d]# vim mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
[root@bogon profile.d]# source mysql.sh
8. Inicie sesión en la base de datos:
[root@bogon profile.d]# 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.14
Copyright (c) 2000, 2016, 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>
Tres, modificar la contraseña de la base de datos
[root@bogon profile.d]# mysqladmin -uroot -p'2QixadqkpG.o' password '123abcABC'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@bogon profile.d]# mysql -uroot -p'123abcABC'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.14 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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>