官术网_书友最值得收藏!

Creating the database on MySql

Before attempting to access the Mysql console make sure that it is running. To check that:

  1. Open terminal/shell and login your Mysql with the following command:
     mysql -u root
    
  2. Remember, if you are using a different user or password, using the following command and replace youruser and yourpassword for your own credentials:
     mysql -u youruser -p yourpassword
    
  3. Now let's create our database, type the following command:
     CREATE DATABASE mvc_mysql_app;
    
  4. The result after the command will be the following line:
     Query OK, 1 row affected (0,04 sec)
    

This confirms that the operation was successful, and we are ready to go forward.

Using db migrations to insert data on Mysql

Now is the time to do the migration of the schemes to the database. Again we use the sequelize-cli for this migration. Before we proceed, we need to install a Mysql module manually.

  1. Open terminal/shell and type the following command:
     npm install
    

    Tip

    Note that the Sequelize interface depends on the individual modules of each type of database used in the application, in our case we are useing Mysql

  2. Open your terminal/shell and type the following command:
     sequelize db:migrate
    
  3. This will be the result of the operation above, the output from your terminal:
    Sequelize [Node: 6.3.0, CLI: 2.3.1, ORM: 3.19.3, mysql: ^2.10.2]
    Loaded configuration file "config/config.json".
    Using environment "development".
    Using gulpfile /usr/local/lib/node_modules/sequelize- cli/lib/gulpfile.js
    Starting 'db:migrate'...
    Finished 'db:migrate' after 438 ms
    == 20160319100145-create-user: migrating =======
    == 20160319100145-create-user: migrated (0.339s)
    == 20160319101806-create-band: migrating =======
    == 20160319101806-create-band: migrated (0.148s)
    
主站蜘蛛池模板: 宜州市| 白玉县| 裕民县| 酉阳| 湘潭县| 怀柔区| 曲阜市| 二手房| 永新县| 马尔康县| 宁海县| 于田县| 阜城县| 瑞安市| 博爱县| 晋宁县| 栾城县| 鄂托克旗| 龙泉市| 石台县| 福建省| 溆浦县| 四川省| 衡阳市| 延长县| 元阳县| 来凤县| 磐安县| 怀柔区| 镇远县| 齐齐哈尔市| 榆社县| 永寿县| 龙海市| 合水县| 平度市| 鄂托克旗| 甘谷县| 海宁市| 淳安县| 清远市|