|
1 | | -# Mysql example |
2 | | -# This example is tested with mysql Ver 8.0.29 |
| 1 | +# MySQL example |
| 2 | +This example is tested with MySQL version 8.0.29. |
3 | 3 |
|
4 | | -This directory contains an example for running Mysql-Server in Gramine, including |
| 4 | +This directory contains an example for running Mysql server in Gramine, including |
5 | 5 | the Makefile and a template for generating the manifest. |
6 | 6 |
|
7 | | -# Prerequisites Steps |
| 7 | +# Pre-requisites |
8 | 8 |
|
9 | | -## Install mysql-server on baremetal: |
10 | | - sudo apt-get install mysql-server |
| 9 | +- `sudo apt-get install mysql-server` to install MySQL server. |
| 10 | +- Comment out the log line `log_error = /var/log/mysql/error.log` in the config file |
| 11 | + `/etc/mysql/mysql.conf.d/mysqld.cnf` to see the log on console. |
| 12 | +- `systemctl stop mysql.service` to stop the default MySQL service .We will manually |
| 13 | + run MySQL process. |
| 14 | +- `sudo mkdir /var/run/mysqld && sudo chown -R <current_user>:<current_user> /var/run/mysqld` |
| 15 | +to allow MySQL server to create socket file `mysqld.sock`. |
| 16 | +- `sudo chown -R <current_user>:<current_user> /var/lib/mysql-files` to allow MySQL server for |
| 17 | +internal usage. |
| 18 | +- `sudo chown -R <current_user>:<current_user> /var/lib/mysql-keyring` to allow MySQL server for |
| 19 | +internal usage. |
| 20 | +- `mysqld --initialize-insecure --datadir=mysql-data/` to initialize data directory. |
11 | 21 |
|
12 | | -## Comment log in /etc/mysql/mysql.conf.d/mysqld.cnf to see the logs on console: |
13 | | - #log_error = /var/log/mysql/error.log |
| 22 | +# Build |
14 | 23 |
|
15 | | -## Stop mysql service, we need to manually run mysql with mysqld: |
16 | | - systemctl stop mysql.service |
17 | | - sudo mkdir /var/run/mysqld && sudo chown -R <current_user>:<current_user> /var/run/mysqld |
18 | | - sudo chown -R <current_user>:<current_user> /var/lib/mysql-files |
19 | | - sudo chown -R <current_user>:<current_user> /var/lib/mysql-keyring |
| 24 | +Run `make` to build the non-SGX version and `make SGX=1` to build the SGX |
| 25 | +version. |
20 | 26 |
|
21 | | -## Prepare new data directory: |
22 | | - sudo mkdir /tmp/mysql && sudo chown -R <current_user>:<current_user> /tmp/mysql |
| 27 | +# Run |
23 | 28 |
|
24 | | -## Add the following 2 lines to /etc/apparmor.d/usr.sbin.mysqld: |
25 | | - /tmp/mysql r, |
26 | | - /tmp/mysql/** rwk, |
| 29 | +Execute any one of the following commands to run the workload: |
27 | 30 |
|
28 | | -## Restart apparmor: |
29 | | - sudo service apparmor restart |
| 31 | +- Natively: `mysqld --datadir /tmp/mysql`. |
| 32 | +- Gramine w/o SGX: `gramine-direct mysqld -u root --datadir /tmp/mysql`. |
| 33 | +- Gramine with SGX: `gramine-sgx mysqld -u root --datadir /tmp/mysql`. |
30 | 34 |
|
31 | | -## Initialize mysql: |
32 | | - mysqld --initialize-insecure --datadir=/tmp/mysql |
33 | | - sudo rm /tmp/mysql/undo* |
| 35 | +# Testing client connection and running sysbench benchmarking |
34 | 36 |
|
35 | | -# Generating the manifest |
| 37 | +Run below command from new terminal: |
36 | 38 |
|
37 | | -## Installing prerequisites |
| 39 | +- `mysql -P 3306 --protocol=tcp -uroot` to connect a client to MySQL server. |
| 40 | +- `mysql> exit` to disconnect the client. |
38 | 41 |
|
39 | | -## Building for Linux |
| 42 | +Run Sysbench benchmarking: |
40 | 43 |
|
41 | | -Run `make` (non-debug) or `make DEBUG=1` (debug) in the directory. |
| 44 | +- `sudo apt install -y sysbench` to install sysbench. |
| 45 | +- `sudo mysqladmin -h 127.0.0.1 -P 3306 create sbtest` to create test database. |
42 | 46 |
|
43 | | -## Building for SGX |
44 | | - |
45 | | -Run `make SGX=1` (non-debug) or `make SGX=1 DEBUG=1` (debug) in the directory. |
46 | | - |
47 | | -# Run Mysql with Gramine |
48 | | - |
49 | | -Here's an example of running Mysql under Gramine: |
50 | | - |
51 | | -Without SGX: |
52 | | -``` |
53 | | -gramine-direct mysqld -u root --datadir /tmp/mysql |
54 | | -``` |
55 | | - |
56 | | -With SGX: |
57 | | -``` |
58 | | -gramine-sgx mysqld -u root --datadir /tmp/mysql |
59 | | -``` |
| 47 | +- `sysbench --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-db=sbtest --time=20 --report-interval=5 oltp_read_write --tables=2 --table_size=100000 --threads=32 prepare` to |
| 48 | + create records in test database. |
| 49 | +- `sysbench --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-db=sbtest --time=20 --report-interval=5 oltp_read_write --tables=2 --table_size=100000 --threads=32 run` to |
| 50 | + run the sysbench benchmarks. |
| 51 | +- `sysbench --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-db=sbtest --time=20 --report-interval=5 oltp_read_write --tables=2 --table_size=100000 --threads=32 cleanup` to |
| 52 | +delete the records from test database. |
0 commit comments