superset鏈接本地mysql數據庫


  剛安裝好superset的時候大家都知道是用的其自動生成的sqllite數據庫,如果我們想讓器鏈接到自己數據庫,給大家分享一下我的方法,以mysql為例:

1.安裝好數據庫mysql:

$ sudo apt-get install mysql-server

$ sudo apt-get install mysql-client

$ sudo apt-get install libmysqlclient-dev

安裝過程中需要設置啟動mysql密碼,必須記住。

2.啟動mysql,並創建數據庫

$ mysql -u root -p

輸入密碼加入以后,命令:

mysql> create database teamwork

teamwork為庫名

然后操作數據庫,可以用寫好的sql腳本文件:

drop database `teamwork`;
create database `teamwork`;
use `teamwork`;

create table `teams`
(`team_id` int(11) not null auto_increment,
 `team_name` varchar(50) not null,
 `team_intro` varchar(500) not null,
 `team_builderid` int(11) not null,
 primary key(`team_id`),
 key `team_ibfk_1` (`team_builderid`),
 constraint `team_ibfk_1` foreign key (`team_builderid`) references `users` (`user_id`) on delete cascade on update cascade
)engine = innodb default charset=utf8;

insert into teams values (1,'團隊1','籃球群','1'), 
(2,'團隊2','興趣愛好','1'),(3,'團隊3','群','1'),(4,'團隊4','籃球群','2');

將這個文件保存為teamwork.sql,終端執行命令:

$ mysql -u root -p teamwork</home/jiang/py3env/teamwork.sql

上面的命令是在數據庫teamwork中執行sql文件,注意/home/wang/py3env/teamwork.sql為存放路徑,teamwork是已有的數據庫。

輸入密碼后可鍵入命令,查看是否成功:

mysql> show database;

mysql> use teamwork;

mysql> show tables;

3.配置superset配置文件,config.py

將原數據庫改為myqsl。

4.重新配置登錄帳號

  這個時候數據庫是新的狀態,之前在sqlite中的登錄帳號已經沒有了需要重新設置一下:

$ (py3env)jiang@ubuntu:~/py3env$ fabmanager create-admin --app superset

$ (py3env)jiang@ubuntu:~/py3env$ superset db upgrade

$ (py3env)jiang@ubuntu:~/py3env$ superset init

注意這些操作都是在虛擬環境激活的情況下完成的。

這個時候重新啟動superset就完成了:

$ (py3env)jiang@ubuntu:~/py3env$ superset runserver

具體這個東西怎么用,后面在研究補充。。。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM