Centos Linux 系统部署java程序(三、数据库的安装和部署)

这个过程存在一些问题,都已经解决了,相关的问题和解决方法文中都能找到

版本: mysql5.7

安装

由于操作系统版本比较高,默认是8.0,我的目标想装5.7版本,因此首先要下载一个5.7版本的安装包

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

下载完成后,进行安装

rpm -ivh mysql57-community-release-el7-11.noarch.rpm

这个时候,还没真正安装上mysql,还需要执行安装命令

如果直接执行以下命令来安装, 显示版本为8.0 肯定是不对的。 于是上网找怎么解决,解决办法在下面

yum -y install mysql-server

如果执行过上面的命令,建议先删掉,再重新安装,删除的命令如下:

yum -y remove mysql-server

禁用默认的8.0版本,命令如下

yum module disable mysql

再次执行以下命令

yum install -y mysql-server

[root@hcss-ecs-5eee rpm]# yum install -y  mysql-server
Last metadata expiration check: 1:18:32 ago on Mon 22 Apr 2024 02:14:32 PM CST.
Dependencies resolved.
================================================================================================================================================================================
 Package                                          Architecture                     Version                                    Repository                                   Size
================================================================================================================================================================================
Installing:
 mysql-community-server                           x86_64                           5.7.44-1.el7                               mysql57-community                           184 M
Installing dependencies:
 libaio                                           x86_64                           0.3.112-1.el8                              base                                         33 k
 mysql-community-client                           x86_64                           5.7.44-1.el7                               mysql57-community                            31 M
 mysql-community-common                           x86_64                           5.7.44-1.el7                               mysql57-community                           313 k
 mysql-community-libs                             x86_64                           5.7.44-1.el7                               mysql57-community                           3.0 M

Transaction Summary
================================================================================================================================================================================
Install  5 Packages

Total download size: 219 M
Installed size: 930 M
Downloading Packages:
(1/5): libaio-0.3.112-1.el8.x86_64.rpm                                                                                                          186 kB/s |  33 kB     00:00    
(2/5): mysql-community-common-5.7.44-1.el7.x86_64.rpm                                                                                           706 kB/s | 313 kB     00:00    
(3/5): mysql-community-libs-5.7.44-1.el7.x86_64.rpm                                                                                             5.8 MB/s | 3.0 MB     00:00    
(4/5): mysql-community-client-5.7.44-1.el7.x86_64.rpm                                                                                            26 MB/s |  31 MB     00:01    
(5/5): mysql-community-server-5.7.44-1.el7.x86_64.rpm                                                                                           1.5 MB/s | 184 MB     02:04    
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                           1.7 MB/s | 219 MB     02:05     
MySQL 5.7 Community Server                                                                                                                       27 MB/s |  27 kB     00:00    
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Key imported successfully
Import of key(s) didn't help, wrong key(s)?
Public key for mysql-community-client-5.7.44-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-client-5.7.44-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-common-5.7.44-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-common-5.7.44-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-libs-5.7.44-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-libs-5.7.44-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-server-5.7.44-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-server-5.7.44-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.
Error: GPG check FAILED
[root@hcss-ecs-5eee rpm]# vi /etc/yum.repos.d/mysql-community.repo 
[root@hcss-ecs-5eee rpm]# yum install -y  mysql-server
MySQL Connectors Community                                                                                                                       24 kB/s | 2.6 kB     00:00    
MySQL Tools Community                                                                                                                           3.2 kB/s | 2.6 kB     00:00    
MySQL 5.7 Community Server                                                                                                                       24 kB/s | 2.6 kB     00:00    
Dependencies resolved.
================================================================================================================================================================================
 Package                                          Architecture                     Version                                    Repository                                   Size
================================================================================================================================================================================
Installing:
 mysql-community-server                           x86_64                           5.7.44-1.el7                               mysql57-community                           184 M
Installing dependencies:
 libaio                                           x86_64                           0.3.112-1.el8                              base                                         33 k
 mysql-community-client                           x86_64                           5.7.44-1.el7                               mysql57-community                            31 M
 mysql-community-common                           x86_64                           5.7.44-1.el7                               mysql57-community                           313 k
 mysql-community-libs                             x86_64                           5.7.44-1.el7                               mysql57-community                           3.0 M

Transaction Summary
================================================================================================================================================================================
Install  5 Packages

Total size: 219 M
Installed size: 930 M
Downloading Packages:
[SKIPPED] libaio-0.3.112-1.el8.x86_64.rpm: Already downloaded                                                                                                                  
[SKIPPED] mysql-community-client-5.7.44-1.el7.x86_64.rpm: Already downloaded                                                                                                   
[SKIPPED] mysql-community-common-5.7.44-1.el7.x86_64.rpm: Already downloaded                                                                                                   
[SKIPPED] mysql-community-libs-5.7.44-1.el7.x86_64.rpm: Already downloaded                                                                                                     
[SKIPPED] mysql-community-server-5.7.44-1.el7.x86_64.rpm: Already downloaded                                                                                                   
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                        1/1 
  Installing       : mysql-community-common-5.7.44-1.el7.x86_64                                                                                                             1/5 
  Installing       : mysql-community-libs-5.7.44-1.el7.x86_64                                                                                                               2/5 
  Running scriptlet: mysql-community-libs-5.7.44-1.el7.x86_64                                                                                                               2/5 
  Installing       : mysql-community-client-5.7.44-1.el7.x86_64                                                                                                             3/5 
  Installing       : libaio-0.3.112-1.el8.x86_64                                                                                                                            4/5 
  Running scriptlet: mysql-community-server-5.7.44-1.el7.x86_64                                                                                                             5/5 
  Installing       : mysql-community-server-5.7.44-1.el7.x86_64                                                                                                             5/5 
  Running scriptlet: mysql-community-server-5.7.44-1.el7.x86_64                                                                                                             5/5 
[/usr/lib/tmpfiles.d/mysql.conf:23] Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly.

  Verifying        : libaio-0.3.112-1.el8.x86_64                                                                                                                            1/5 
  Verifying        : mysql-community-client-5.7.44-1.el7.x86_64                                                                                                             2/5 
  Verifying        : mysql-community-common-5.7.44-1.el7.x86_64                                                                                                             3/5 
  Verifying        : mysql-community-libs-5.7.44-1.el7.x86_64                                                                                                               4/5 
  Verifying        : mysql-community-server-5.7.44-1.el7.x86_64                                                                                                             5/5 

Installed:
  libaio-0.3.112-1.el8.x86_64                 mysql-community-client-5.7.44-1.el7.x86_64  mysql-community-common-5.7.44-1.el7.x86_64  mysql-community-libs-5.7.44-1.el7.x86_64 
  mysql-community-server-5.7.44-1.el7.x86_64 

Complete!

服务启动

service mysqld start

验证

通过mysql 命令来验证是否已完成安装,执行以下命令

mysql -uroot -p

如果能正常使用了,则表示安装好了

初始化

5.7版本的mysql,默认会初始化一个密码到日志文件中。 因此直接登录上不去。

需要先修改密码,再登录

我这里选用比较简单的方法

  1. 修改配置文件,增加 skip-grant-table 配置选项

    在默认的配置文件/etc/my.cnf中,[mysqld]节点下增加 skip-grant-tables 选项

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock 
symbolic-links=0 
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
lower_case_table_names=1
skip-grant-tables

  1. 进入mysql 修改登录密码及权限
[root@hcss-ecs-5eee rpm]# 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.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update user set authentication_string =password('test123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> create user root@'%' identified by 'test123456';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to root@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to root@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit
  1. 修改配置文件,去除 skip-grant-table 配置选项
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock 
symbolic-links=0 
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
lower_case_table_names=1
# skip-grant-tables
  1. 重启mysql服务
[root@hcss-ecs-5eee rpm]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service


再使用新密码test123456进行登录测试

[root@hcss-ecs-5eee rpm]# 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.44

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> 

工具介绍

为了方便操作,经常会用一些工具来提高办事效率。 我主要使用navicat来操作。

MYSQL工具列表如下:

SQL Studio navicat Wolkbench DBeaver phpMyAdmin dbForge Studio for MySQL SQLyog HeidiSQL 阿里云DMS Beekeeper Studio Toad Edge DbVisualizer

大家可以自己去百度搜一下,下载下来用一用,看看哪个更好用,可以给我留言。 如果发现这些都不好用,还有更好用的工具,也可以推荐、分享给更多的人。