温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Ubuntu中如何安装JDK与Mysql

发布时间:2022-10-26 10:24:33 来源:亿速云 阅读:128 作者:iii 栏目:服务器

这篇文章主要介绍“Ubuntu中如何安装JDK与Mysql”,在日常操作中,相信很多人在Ubuntu中如何安装JDK与Mysql问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Ubuntu中如何安装JDK与Mysql”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

一、安装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等软件,在其他计算机访问数据库了。

Ubuntu中如何安装JDK与Mysql

到此,关于“Ubuntu中如何安装JDK与Mysql”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI