安装MySQL
mysql安装的方式很简单:更新软件包索引,安装mysql-server软件包,然后运行附带的安全脚本即可。
sudo apt-get update
sudo apt-get install mysql-server
sudo mysql_secure_installation
步骤1 – 安装MySQL
在 Ubuntu 16.04 中,默认情况下,只有最新版本的 MySQL 包含在 APT 软件包存储库中。在撰写本文时,那是 MySQL 5.7
要安装它,只需更新服务器上的包索引并安装默认包 apt-get。
sudo apt-get update
sudo apt-get install mysql-server
系统将提示您在安装过程中创建 root 密码。选择一个安全的密码,并确保你记住它,因为你以后需要它。接下来,我们将完成 MySQL 的配置。
步骤2 – 启动MySQL
因为是全新安装,mysql没有自动启动,需要手动启动:
sudo /etc/init.d/mysql status
sudo /etc/init.d/mysql start
现在,我们来测试MySQL了。
步骤3 – 测试MySQL
MySQL运行后,可以进行登录了。
mysql -uroot -p
这时候要输入上面设置的root密码,输入正确后可以看到熟悉的mysql命令行页面:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 789
Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu)
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>
如果额外的检查,您可以尝试使用该 mysqladmin 工具连接到数据库,该工具是允许您运行管理命令的客户端。例如,该命令表示以 root(-u root)方式连接到 MySQL ,提示输入密码(-p)并返回版本。
mysqladmin -p -u root version
你应该看到类似的输出:
mysqladmin Ver 8.42 Distrib 5.7.21, for Linux on x86_64
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.
Server version 5.7.21-0ubuntu0.16.04.1
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 1 day 7 hours 32 min 19 sec
Threads: 4 Questions: 69747 Slow queries: 0 Opens: 846 Flush tables: 1 Open tables: 405 Queries per second avg: 0.614
这意味着MySQL正在运行。
安装jdk
采用设置源仓库的方法安装,只需输入命令即可
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
步骤1 – 安装jdk1.8
如果报ubuntu add-apt-repository command not found,这个时候直接apt-get add-apt-repository是不可以的!可以先安装software-properties-common,输入命令
apt-get install software-properties-common
然后就可以继续安装jdk8,安装时间会有点久,安装完毕后就是检查java和测试:
java -version
步骤2 – 配置jdk1.8
配置$JAVA_HOME环境变量
sudo vi /etc/environment
增加一行
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
保存执行source /etc/environment
echo $JAVA_HOME