Giter Club home page Giter Club logo

sqladvisor-web-1's Introduction

sqladvisor-web

美团SQLAdvisor SQL优化建议工具的Web版,告别命令行。

  • 项目中使用的美团SQL分析工具是在CentOS上编译的,所以建议部署到CentOS上。
  • 该项目是使用Python的Flask框架开发的。
  • 使用CentOS自带的Python版本,版本号是2.7.5。
  • 再部署前建议先看一下美团的分析工具文档
  • CentOS所在环境是使用Vagrant虚拟的环境。

系统搭建

1、安装git、wget、Mysql和pip

sudo yum install git
sudo yum install wget

CentOS 7安装Mysql需要先下载Mysql的rpm文件。

wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
sudo yum install mysql-community-server

配置Mysql

mysql_secure_installation

执行上面命令设置root密码。

sudo systemctl enable mysqld

设置开机启动。

重启数据库

sudo systemctl mysqld restart

进入Mysql创建sqladvisor数据库

CREATE DATABASE IF NOT EXISTS sqladvisor default charset utf8 COLLATE utf8_general_ci;

一定要设置charset为utf8和COLLATE为utf8_general_ci,否则无法保存中文。

安装pip

sudo yum -y install epel-release
sudo yum install python-pip

2、配置项目

git clone https://github.com/zyw/sqladvisor-web.git

下载项目。

cd sqladvisor-web

为了不报下面异常

root@pts/4 $ pip install MySQL-python
Collecting MySQL-python
  Using cached MySQL-python-1.2.5.zip
    Complete output from command python setup.py egg_info:
    sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-kWowP9/MySQL-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 25, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-kWowP9/MySQL-python/

首先安装

sudo yum install python-devel mysql-community-devel -y

下面安装依赖

sudo pip install -r requirements.txt

修改数据库配置

编辑工程中的config.py文件

SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URL') or 'mysql://root:root@localhost/sqladvisor'

把第二个root修改成你安装Mysql时设置的密码。

恢复数据库

python manage.py db init
python manage.py db migrate
python manage.py db upgrade

如果migrations文件夹已存在,先删除。

经过上三条命令,sqladvisor数据库中的表已经被创建了。

解压sqlparser.tar.gz

解压sqlparser.tar.gz/usr/local

启动系统

python manage.py runserver --host 0.0.0.0

启动完成后访问http://127.0.0.1:5000/

部署sqladvisor-web

使用上面的命令是在开发环境启动Python Web应用,如果想要供多人使用还是使用gunicorn部署比较好。

  • 安装gunicorn
pip install gunicorn
  • 启动服务
gunicorn manage:app -p manage.pid -b 0.0.0.0:8000 -D

上面的命令启动一个监听0.0.0.0:8000 IP和端口的服务,-D是启动一个守护进程

3、截图

analysis setting his

sqladvisor-web-1's People

Contributors

zyw avatar

Watchers

James Cloos avatar frank zhang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.