spark往mysql里写东西
如果报错no suitable driver found for jdbc
是spark没有合适的jdbc连接驱动,需要下一个jdbc connector的jar包放到spark路径下并把次路径放到spark/conf/spark-env.sh的SPARK_CLASSPATH里
如:export SPARK_CLASSPATH=$SPARK_CLASSPATH:/root/spark/mysql-connector-java-5.1.35.jar
要注意这里的driver版本不要太高,6以上貌似不行。
如果报ERROR 1130: Host ’x′ is not allowed to connect to this MySQL server则是对面MySQL做了ip限制,本机无权限访问mysql
grant all privileges on database.* to root@' ' identified by 'user' with grant option;
flush privileges;
注意目前Spark还没有支持往外部mysql数据库里insert数据,只能append,因此如果有自增字段需要自己写好序号 ,或者将计算结果collect到本地处理好再insert
浙公网安备 33010602011771号