大数据入门到精通13--为后续和MySQL数据库准备

时间:2023-03-08 21:19:51
大数据入门到精通13--为后续和MySQL数据库准备

We will be using the sakila database extensively inside the rest of the course and it would be great if you can follow the installation process below.

Importing the Sakila Database

一、 Change the File 。这一步原来提供的文件中可能已经i做好了。

Find and Replace all "InnoDB" with "MyISAM" in the schema file - different database engine - Full text - so don't have to upgrade

// MySQL用我的host03.xyy上安装了mysql数据库,所以在host03上做

二、登录数据库并执行数据库脚本

mysql -u root -p

root

SOURCE /home/cloudera/Spark/sakila-db/sakila-schema.sql

SOURCE /home/cloudera/Spark/sakila-db/sakila-data.sql

SHOW FULL TABLES;

DROP VIEW actor_info;

DROP VIEW customer_list;

DROP VIEW film_list;

DROP VIEW nicer_but_slower_film_list;

DROP VIEW sales_by_film_category;

DROP VIEW sales_by_store;

DROP VIEW staff_list;

三、使用hive并创建hive数据库

// Hive在host03机器上切换到hdfs用户,然后执行hive,进入hive命令行

CREATE DATABASE sakila;

四、执行导入mysql数据到hive。通过sqoop命令

// Terminal在03机器上使用hdfs用户进入,执行如下命令,否则找不到驱动程序。

sqoop import-all-tables --connect "jdbc:mysql://host03.xyy:3306/sakila" --username root --password root --hive-import --hive-database sakila

因为sqoop回转化为hadoop的mapreduce来做,所以会从多个机器上同时执行。

这个时候可能发生其他机器上链接不上mysql的问题,因为默认的mysql是拒绝其他机器访问的。

可以如下操作

mysql -u root -p
GRANT ALL PRIVILEGES ON *.* TO root@"host01.xyy" IDENTIFIED BY "root" WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO root@"host02.xyy" IDENTIFIED BY "root" WITH GRANT OPTION;

或者直接所有的远程机器都可以访问授权。

GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
FLUSH PRIVILEGES;