2. ABPZero series Tutorials: how to change the database to Mysql and abpzeromysql

Source: Internet
Author: User
Tags mysql connection string

2. ABPZero series Tutorials: how to change the database to Mysql and abpzeromysql

 

To deploy a project to an ECS instance and do not want to install SqlServer on the server, you need to change the project to Mysql.

Project Initialization

1. Download the compressed project package. As mentioned in the previous article, you can add a group to the group file to download the package. Decompress the downloaded project source code and use VS2015 to open the project

 

 

Here we need to restore the package. Right-click the solution --- (restore the NuGet package), and now it is much faster to restore the NuGet package. This is why Microsoft attaches great importance to Chinese developers.

 

 

After the package is restored, click solution to regenerate it. You can see that the project is successfully generated. Next, go to the Mysql database modification step.

Note: If you do not want to use the Mysql database, skip the following steps to create the database.

Install Mysql package

Before that, install the Mysql database and the Mysql database on the computer to ensure that the computer can successfully connect to the Mysql database.

Mysql installation-free environment configuration graphic Tutorial: http://www.jb51.net/article/83636.htm

 

Then install the Mysql package, which must be installed for both EntityFramework and Web projects.

 

The installation of the NuGet package and the project to which it is installed have been circled. Select version 6.9.10 here.

Web Project

Open web. config and modify the connection string

<ConnectionStrings> <! -- <Add name = "Default" connectionString = "Server = localhost; Database = AbpZeroTemplate; Trusted_Connection = True;" providerName = "System. Data. SqlClient"/> --> <! -- Mysql connection string --> <add name = "Default" connectionString = "Data Source = localhost; port = 3306; Initial Catalog = pdddb3.4; uid = root; password = ab12; charset = utf8 "providerName =" MySql. data. mySqlClient "/> <add name =" Abp. redis. cache "connectionString =" localhost "/> </connectionStrings>

 

Install the Mysql driver

Install the Mysql driver. Select the same version as the above package.
Driver: https://dev.mysql.com/downloads/connector/net/

 

After the download, you can continue to install it.

EntityFramework Project

Modify the Configuration constructor under the EntityFramework Project

File Path: D: \ abp version \ aspnet-zero-3.4.0 \ aspnet-zero-3.4.0 \ src \ MyCompanyName. AbpZeroTemplate. EntityFramework \ Migrations \ Configuration. cs

Public Configuration () {AutomaticMigrationsEnabled = false; ContextKey = "AbpZeroTemplate"; // Add the following code SetSqlGenerator ("MySql. data. mySqlClient ", new MySql. data. entity. mySqlMigrationSqlGenerator (); // set the SQL generator to Mysql}

 

 

Add a feature to the AbpZeroTemplateDbContext class.

File Path: D: \ abp version \ aspnet-zero-3.4.0 \ aspnet-zero-3.4.0 \ src \ MyCompanyName. AbpZeroTemplate. EntityFramework \ AbpZeroTemplateDbContext. cs

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]    public class AbpZeroTemplateDbContext : AbpZeroDbContext<Tenant, Role, User>    {

 

 

Regenerate the migration File

Now the code is added and the Migration file is regenerated. We can see that there are a lot of migration files in the project. We don't want these files to be regenerated by ourselves.

 

Delete the remaining Seed directory and Configuration file

 

 

Note: Set the Web project as the startup project first.

 

Open the VS package management console, and select the. EntityFramework project in the package management console as the default project. Then, run the following command on the console:

Add-Migration "AbpZero_Initial"

 

The yellow prompt indicates that the Migration file is successfully created.

 

 

At the same time, a file is added to the Migrations Directory, which is the migration file just created.

Now you can use the following command to create a database:

Update-Database

 

 

 

 

Everything has been done. Now you can run your project and use the MySQL database.

This document shows you how to start the project. We recommend that you deploy it to IIS to start the project. In future articles, I will start the project with IIS for operations.

Http://www.cnblogs.com/shensigzs/p/6258835.html

 

Total returned directory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.