debian 10 linux系统安装配置jdk和mysql8.0正确步骤详解

一、安装和配置jdk

1.在usr下创建java文件夹

mkdir usr/java

2.给创建的java文件夹赋权限

sudo chmod 777 usr/java  

3.下载jdk,我使用的是jdk-8u144-linux-x64.tar.gz版本,
下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html,jdk的下载在这里就不详细讲解了,进入下载页面,下载Linux版本的jdk就可以了。
上传下载的jdk到Linux服务器(这里我上传到了usr/java目录下),我使用的是FileZilla来完成这一步骤,当然其他的工具也可以。

4.解压 需指定文件路径下cd usr/java
后缀是gz用 -zxvf ;后缀是xz用 -jxf; 后缀是tar用 -xvf

sudo tar -zxvf jdk-8u144-linux-x64.tar.gz

5.配置jdk环境

vim /etc/profile

在profile文件的末尾加入如下命令:
在这里插入图片描述
// 多个path路径时用 : 连接
//jdk1.8.0_144换成你安装的版本

export JAVA_HOME=/usr/java/jdk1.8.0_144
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export JAVA_PATH=$JAVA_HOME/bin:$JRE_HOME/bin
export PATH=$PATH:$JAVA_PATH

然后按Esc,使用:wq保存退出,重启系统,这样jdk的安装就全部完成了

esc 
 :wq

6.最后执行指令生效

source /etc/profile
  1. 使用下面命令查看jdk版本:
java -version

在这里插入图片描述

说明jdk已经安装完成,再使用javac检查环境变量是否设置成功:
如下图:
在这里插入图片描述
说明环境变量设置也是成功的,自此jdk的安装就完成了。

二、配置MySQL的软件仓库

这里我安装的是8.0版本的
1.要将MySQL APT存储库添加到系统,请转到存储库下载页面并下载最新的发行包:

wget http://repo.mysql.com/mysql-apt-config_0.8.10-1_all.deb

2.下载完成后,使用以下命令安装发行包:

sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb

您将看到配置菜单,您可以在其中选择要安装的MySQL版本。
在这里插入图片描述
MySQL版本选中MySQL版本选中

MySQL 8.0是默认选择的,如果你想安装另一个版本的MySQL,请选择MySQL Server&Cluster(当前选择:mysql-8.0)并选择你喜欢的MySQL版本

我们要安装MySQL 8.0版。 选择最后一个选项确定,然后按Enter键(如上图所示)以保存配置。

Tip:在撰写本文时,最新版本的MySQL是8.0版。 如果您不确定选择哪个版本,请参阅您要在服务器上部署的应用程序的文档。

**

安装MySQL

**
在Debian 10服务器上安装MySQL之前,首先使用以下命令更新软件包列表:

sudo apt update

更新软件包列表后,运行以下命令在Debian服务器上安装MySQL:

sudo apt install mysql-server

安装程序将要求您设置MySQL root密码。 现在不要设置密码(留空),我们将在下一节中进行设置。 接下来,您将看到一条消息,通知您有关新的MySQL 8身份验证的信息。 在选择默认的mysql 8身份验证插件之前,请确保您的应用程序支持它。
在这里插入图片描述

验证MySQL安装
安装完成后,MySQL服务将自动启动。

我们可以通过输入以下内容来检查MySQL服务状态

sudo systemctl status mysql

输出内容:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: 
   Active: active (running) since Thu 2018-08-02 17:22:18 UTC; 18s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 14797 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (co
 Main PID: 14832 (mysqld)
   Status: "SERVER_OPERATING"
    Tasks: 37 (limit: 4915)
   CGroup: /system.slice/mysql.service
           └─14832 /usr/sbin/mysqld
 

保护MySQL

运行mysql_secure_installation命令设置root密码并提高MySQL安装的安全性:

sudo mysql_secure_installation

输出内容:

Securing the MySQL server deployment.
 
Connecting to MySQL using a blank password.
 
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
 
Press y|Y for Yes, any other key for No: 

系统将要求您配置VALIDATE PASSWORD PLUGIN,用于测试MySQL用户密码的强度。 密码验证策略有三个级别,低,中和强。 如果您不想设置验证密码插件,请按ENTER。

输出内容:

Please set the password for root here.
 
New password: 
 
Re-enter new password:

在下一个提示中,将要求您为MySQL root用户设置密码。

输出内容:

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
 
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
 
 
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
 
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
 
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
 
 
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.
 
 - Removing privileges on test database...
Success.
 
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
 
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
 
All done! 

设置root密码后,脚本还会要求您删除匿名用户,限制root用户访问本地计算机并删除测试数据库。 你应该对所有问题回答“是”(是)。

从命令行连接到MySQL
要通过终端与MySQL交互,我们将使用MySQL客户端作为MySQL服务器包的依赖项。

以root用户身份登录MySQL服务器:

mysql -u root -p

系统将提示您输入运行mysql_secure_installation脚本时先前设置的root密码。

输入密码后,您将看到mysql shell,如下所示:

输出内容:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.12 MySQL Community Server - GPL
 
Copyright (c) 2000, 2018, 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>

到这里mysql就已经安装完成了,但是想用navicat软件远程连接数据库需要新增一个root用户;

MySQL 8.0已经不支持下面这种命令写法
grant all privileges on . to root@"%" identified by “.”;

正确的写法是先创建用户
CREATE USER ‘root’@’%’ IDENTIFIED BY ‘Hadoop3!’;

//刷新
flush privileges;

再给用户授权
grant all privileges on . to ‘root’@’%’ ;

好了这样就可以远程连接上了

**

ps:MySQL V8.0设置大小写不敏感后不能正常启动

**
Mysql8.0开启忽略表大小写,无法启动,解决方案

注:mysql8.0默认是区分大小写。因此如果要设置忽略大小写,需要在安装完成之后,初始化数据库的时候进行设置。

/usr/sbin/mysqld --initialize --user=mysql --lower-case-table-names=1

初始化完成之后在启动数据库。否则的话就会是无效的。
如果要是已经启动了数据库,在配置文件中再去修改,就会造成数据库无法启动的情况。
如果出现这个情况,
1.首先需要删除掉/var/lib/mysql文件夹下面的所有的文件。

rm -rf /var/lib/mysql

2.再去修改配置文件my.cnf;
之前百度的文章都说在etc/my.cnf 但是我的my.cnf在etc/mysql/my.cnf下
所以:

vi etc/mysql/my.cnf

添加lower_case_table_names=1;若没有[mysqld]就手动加上;如图:
在这里插入图片描述
修改完按esc键,:wq保存

3.在重新启动mysql就解决区分大小写问题了;

到此debian 10 liunx系统安装部署jdk和mysql就完成了

猜你喜欢

转载自blog.csdn.net/w15562397578/article/details/114157737