Ubuntu下使用安装和使用MYSQL和JDBC

本文档详细介绍了在Ubuntu操作系统中如何安装MySQL数据库以及配置JDBC,为后续在Java应用中进行数据库连接测试提供指导。
摘要由CSDN通过智能技术生成

JDBCAndMySQL

#####################################################33

1.安装MYSQL,JDBC

sudo apt install mysql-client mysql-server  libmysql-java

打开~/.bashrc文件,添加CLASSPATH,然后更新源文件,并查看环境变量设置情况。
sudo geany ~/.bashrc
    CLASSPATH = $CLASSPATH:/usr/share/java/mysql.jar
source ~/.bashrc
echo $CLASSPATH

2. 配置

#登录主用户,设置密码
mysql -uroot -p

#创建数据库
    create database webmagic;
#新增用户
    grant all privileges on webmagic.* to auss@localhost identified by "auss";
    flush privileges;

#测试新用户
mysql -uauss -h 127.0.0.1 -p

3. 在Java里面测试

import java.sql.*;
import java.util.Properties;

public class DBDemo
{
  // The JDBC Connector Class.
  private static final String dbClassName = "com.mysql.jdbc.Driver";

  // Connection string. emotherearth is the database the program
  // is connecting to. You can include user and password after this
  // by adding (say) ?user=paulr&password=paulr. Not recommended!

  private static final String CONNECTION =
                          "jdbc:mysql://127.0.0.1/webmagic";

  public static void main(String[] args) throws
                             ClassNotFoundException,SQLException
  {
    System.out.println(dbClassName);
    // Class.forName(xxx) loads the jdbc classes and
    // creates a drivermanager class factory
    Class.forName(dbClassName);

    // Properties for user and password. Here the user and password are both 'paulr'
    Properties p = new Properties();
    p.put("user","auss");
    p.put("password","auss");

    // Now try to connect
    Connection c = DriverManager.getConnection(CONNECTION,p);

    System.out.println("It works !");
    c.close();
    }
}
安装Hive和MySQL的步骤如下: 1. 安装MySQLUbuntu安装MySQL,可以使用以下命令: sudo apt-get update sudo apt-get install mysql-server 安装过程中,会提示输入MySQL的root用户密码。 2. 安装Hive 在Ubuntu安装Hive,可以使用以下命令: sudo apt-get update sudo apt-get install hive 安装过程中,会提示输入Hive的配置信息。 3. 配置MySQL 在Hive中使用MySQL作为元数据存储,需要进行以下配置: 3.1 创建Hive元数据数据库 在MySQL中创建一个新的数据库,用于存储Hive的元数据信息: mysql -u root -p CREATE DATABASE hive_metastore; 3.2 创建Hive元数据用户 在MySQL中创建一个新的用户,用于访问Hive元数据数据库: mysql -u root -p GRANT ALL PRIVILEGES ON hive_metastore.* TO 'hiveuser'@'localhost' IDENTIFIED BY 'hivepassword'; 3.3 修改Hive配置文件 修改Hive的配置文件hive-site.xml,添加以下配置信息: <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost/hive_metastore?createDatabaseIfNotExist=true</value> <description>JDBC connect string for a JDBC metastore</description> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> <description>Driver class name for a JDBC metastore</description> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>hiveuser</value> <description>username to use against metastore database</description> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>hivepassword</value> <description>password to use against metastore database</description> </property> 4. 启动Hive 启动Hive,可以使用以下命令: hive 以上就是在Ubuntu安装Hive和MySQL的步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值