欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

Ubuntu18.04 linux系统安装JDK与Mysql的方法

程序员文章站 2024-02-04 16:58:28
平台部署一、安装jdkstep1.下载oraclejdkstep2. 解压step3. 加入环境变量具体操作如下:lemon@ubuntu:~$ cd ~/download/lemon@ubuntu:...

平台部署

一、安装jdk

step1.下载oraclejdk
step2. 解压
step3. 加入环境变量

具体操作如下:

lemon@ubuntu:~$ cd ~/download/
lemon@ubuntu:~/download$ wget https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173c853231432d94f001e99d882ca7/jdk-13.0.2_linux-x64_bin.tar.gz

lemon@ubuntu:~/download$ tar vxf jdk-8u191-linux-x64.tar.gz
lemon@ubuntu:~/download$ ls #查看当前目录下的文件
jdk1.8.0_191 jdk-8u191-linux-x64.tar.gz
lemon@ubuntu:~/download$ sudo mv jdk1.8.0_191/ /usr/local/jdk1.8/ #将jdk1.8.0_191文件夹移动到/usr/local/下并重命名为jdk1.8
lemon@ubuntu:~/download$ sudo vim /etc/profile #编辑环境变量

在环境变量末尾加入如下内容:

export java_home=/usr/local/jdk1.8
export jre_home=${java_home}/jre
export classpath=.:${java_home}/lib:${jre_home}/lib
export path=.:${java_home}/bin:$path

保存后重新加载环境变量,使生效:

lemon@ubuntu:~/download$ source /etc/profile #刷新环境变量,使生效
lemon@ubuntu:~$ java -version#输入java -version,如显示以下信息,则jdk安装成功
java version "1.8.0_191"
java(tm) se runtime environment (build 1.8.0_191-b12)
java hotspot(tm) 64-bit server vm (build 25.191-b12, mixed mode)

二、安装mysql

step1. 安装mysql并配置
step2. 创建数据库与表

由于在安装ubuntu系统时,本人选择了安装lamp服务,所以mysql已安装完成,仅需设置即可启用。

测试是否安装:

lemon@ubuntu:~$ mysql #输入mysql,如出现以下提示,说明已安装mysql
error 1045 (28000): access denied for user 'lemon'@'localhost' (using password: no)

如未安装:

lemon@ubuntu:~$ sudo apt-get install mysql-server
lemon@ubuntu:~$sudo apt isntall mysql-client
lemon@ubuntu:~$sudo apt install libmysqlclient-dev

如已安装:

lemon@ubuntu:~$ sudo mysql_secure_installation

两者都会进入mysql设置过程,具体设置内容如下:

#1
validate password plugin can be used to test passwords...
press y|y for yes, any other key for no: n(不启用弱密码检查)

#2
please set the password for root here...
new password: (设置root密码)
re-enter new password: (重复输入)

#3
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...
remove anonymous users? (press y|y for yes, any other key for no) : y(不启用匿名用户)

#4
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 (不允许root远程登陆)

#5
by default, mysql comes with a database named 'test' that
anyone can access...
remove test database and access to it? (press y|y for yes, any other key for no) : n

#6
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 (立刻刷新权限表)

all done!

接下来进入进入mysql进行操作:

#最新版的mysql安装之后无法使用密码进行登陆,需要sudo登录修改登录方式
lemon@ubuntu:~$ sudo mysql -uroot -p
enter password: (空密码)
mysql>
mysql>update mysql.user set authentication_string=password('lemon'), plugin='mysql_native_password' where user='root';
mysql> flush privileges;
mysql>exit

lemon@ubuntu:~$ sudo service mysql restart
lemon@ubuntu:~$ mysql -u root -p
enter password: (上一步设置的密码,password括号内的)
mysql>create database nutch;
mysql>use nutch
mysql> create table `webpage` (
`id` varchar(767) not null,
`headers` blob,
`text` mediumtext default null,
`status` int(11) default null,
`markers` blob,
`parsestatus` blob,
`modifiedtime` bigint(20) default null,
`score` float default null,
`typ` varchar(32) character set latin1 default null,
`baseurl` varchar(767) default null,
`content` longblob,
`title` varchar(2048) default null,
`reprurl` varchar(767) default null,
`fetchinterval` int(11) default null,
`prevfetchtime` bigint(20) default null,
`inlinks` mediumblob,
`prevsignature` blob,
`outlinks` mediumblob,
`fetchtime` bigint(20) default null,
`retriessincefetch` int(11) default null,
`protocolstatus` blob,
`signature` blob,
`metadata` blob,
`batchid`varchar(767)default null,
primary key (`id`)
) engine=innodb
row_format=compressed
default charset=utf8mb4;
mysql>exit

*最新版本默认情况下,mysql是不允许远程登录的,如需远程访问需要做一些修改:

lemon@ubuntu:~$sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
#将bind-address = 127.0.0.1注释掉,重启mysql服务
lemon@ubuntu:~$sudo service mysqld start

接下来就可以通过navicat等软件,在其他计算机访问数据库了。

Ubuntu18.04 linux系统安装JDK与Mysql的方法

这样就ok了