vitess.io/vitess@v0.16.2/examples/compose/external_db/README.md (about)

     1  **This README is kept here for reference, however the parent [README](../README) contains all the information necesaary to simulate this in a better way**
     2  
     3  # Simulate external/remote database for Vitess using docker-compose 
     4  
     5  This directory has a docker-compose that will bring up a mysql instance.
     6  You can then point your vitess cluster to it to understand how to use Vitess for your existing database 
     7  when you cannot install Vitess on the mysql instance.
     8  
     9  First you will need to [install docker-compose](https://docs.docker.com/compose/install/).
    10  
    11  
    12  ### Create new docker-machine
    13  Create a new docker-machine that will run your mysql container.  
    14  Creating a new machine allows you to more comprehensively test the remote functionality.
    15  ```
    16  vitess/examples/compose/external_db$ docker-machine create remote-db
    17  ```
    18  
    19  Grab the docker-machine ip
    20  ```
    21  vitess/examples/compose/external_db$ docker-machine ip remote-db
    22  192.168.99.101
    23  ```
    24  
    25  Set the environment variables for the remote-db machine
    26  ```
    27  vitess/examples/compose/external_db$ eval $(docker-machine ip remote-db)
    28  ```
    29  
    30  ### Start mysql
    31  Start the mysql instance
    32  ```
    33  vitess/examples/compose/external_db$ docker-compose up -d
    34  ```
    35  This will do the following;
    36  1. Starts mysql service and exposes it at `<docker-machine-ip>:3306`  
    37  2. Creates a `commerce` database with `users` table  
    38  3. Adds sample data to the users table
    39  4. Starts a lightweight adminer container to interact with the database accessible at `<docker-machine-ip>:8081`  
    40  5. Default credentials  
    41     ```
    42     MYSQL_DB: commerce
    43     MYSQL_USER: dbuser  
    44     MYSQL_PASSWORD: dbpass  
    45     MYSQL_ROOT_PASSWORD:  pass
    46     ```
    47  
    48  ### Confirm containers are up
    49  Run the following
    50  ```
    51  vitess/examples/compose/external_db$ docker-compose ps
    52  ```
    53  
    54  A valid response should look like below
    55  ```sh
    56          Name                       Command                  State                     Ports
    57  ---------------------------------------------------------------------------------------------------------
    58  external_db_adminer_1   entrypoint.sh docker-php-e ...   Up             0.0.0.0:8081->8080/tcp
    59  external_db_db_1        docker-entrypoint.sh mysqld      Up (healthy)   0.0.0.0:3306->3306/tcp, 33060/tcp
    60  ```
    61  You now have a mysql instance ready to be *migrated* to Vitess.
    62  
    63  ### Start Vitess pointed to this remote database
    64  Head on to [vitess compose instructions](../README.md )  
    65  
    66  If using docker-compose.beginners.yml, run;  
    67  ```
    68  vitess/examples/compose$ cp docker-compose.beginners.yml docker-compose.yml
    69  ```
    70  Update your `.env` file with these;  
    71  ```
    72  KEYSPACE=commerce
    73  DB=commerce
    74  EXTERNAL_DB=1
    75  DB_HOST=<docker-machine-ip>
    76  DB_PORT=3306
    77  DB_USER=dbuser
    78  DB_PASS=dbpass
    79  DB_CHARSET=CHARACTER SET latin1 COLLATE latin1_swedish_ci
    80  ```
    81  
    82  
    83  If using `vtcompose` command, run;  
    84  ```
    85  vitess/examples/compose$ go run vtcompose/vtcompose.go -keyspaceData="commerce:0:2::" -externalDbData="commerce:<docker-machine-ip>:3306:dbuser:dbpass:CHARACTER SET latin1 COLLATE latin1_swedish_ci"
    86  ```
    87  
    88  **Ensure you start Vitess in a different docker-machine!!**
    89  If not, run;
    90  ```
    91  vitess/examples/compose$ docker-machine create vitess
    92  vitess/examples/compose$ $(docker-machine env vitess)
    93  ```
    94  
    95  Start Vitess
    96  ```
    97  vitess/examples/compose$ docker-compose up -d
    98  ```
    99  
   100  You should now have Vitess running against your external database instance.
   101   
   102  * [Follow this guide for advanced usage](../README.md#advanced-usage "Advanced Usage" )  
   103  * [See this for common issues](../README.md#common-errors "Common Issues" )  
   104  
   105  ### Migrating to Vitess
   106  Migrating to Vitess entirely can be done from;  
   107  a) The Vitess Control Panel at http://<vitess_ip>:15000  
   108  b) The `lvtcl.sh` Helper Script;  
   109  
   110  The steps are same
   111  1. Do an EmergencyReparentShard to make a replica the new primary.
   112  2. Ran InitShardPrimary on the new primary.
   113  3. If Vitess is wrong about who the MySQL primary is, you can update it with TabletExternallyReparented