Skip to content

Commit 209fed2

Browse files
committed
fixup! Add MySQL server example
Signed-off-by: Jitender Kumar <[email protected]>
1 parent ce8049e commit 209fed2

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

mysql/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
ARCH_LIBDIR ?= /lib/$(shell $(CC) -dumpmachine)
2+
UID ?= $(shell id -u)
3+
GID ?= $(shell id -g)
24

35
ifeq ($(DEBUG),1)
46
GRAMINE_LOG_LEVEL = debug
@@ -16,6 +18,8 @@ mysqld.manifest: mysqld.manifest.template
1618
gramine-manifest \
1719
-Dlog_level=$(GRAMINE_LOG_LEVEL) \
1820
-Darch_libdir=$(ARCH_LIBDIR) \
21+
-Duid=$(UID) \
22+
-Dgid=$(GID) \
1923
-Dentrypoint=$(realpath $(shell sh -c "command -v mysqld")) \
2024
$< >$@
2125

mysql/README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
11
# MySQL example
22
This example is tested with MySQL version 8.0.29.
33

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
55
the Makefile and a template for generating the manifest.
66

7-
# Pre-requisites
7+
## Pre-requisites
88

99
- `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
10+
- Comment out the log line `log_error = /var/log/mysql/error.log` in the config file
1111
`/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
12+
- `systemctl stop mysql.service` to stop the default MySQL service. We will manually
1313
run MySQL process.
14-
- `sudo mkdir /var/run/mysqld && sudo chown -R <current_user>:<current_user> /var/run/mysqld`
14+
- `sudo mkdir /var/run/mysqld && sudo chown -R <current_user>:<current_user> /var/run/mysqld`
1515
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.
16+
- `sudo chown -R <current_user>:<current_user> /var/lib/mysql-files` to allow running
17+
MySQL server under the current non-root user.
18+
- `sudo chown -R <current_user>:<current_user> /var/lib/mysql-keyring` to allow running
19+
MySQL server under the current non-root user.
20+
- `mysqld --initialize-insecure --datadir=/tmp/mysql-data` to initialize data directory. For
21+
details on '--initialize-insecure', please see the https://dev.mysql.com/doc/mysql-linuxunix-excerpt/5.7/en/data-directory-initialization.html page.
2122

22-
# Build
23+
## Build
2324

2425
Run `make` to build the non-SGX version and `make SGX=1` to build the SGX
2526
version.
2627

27-
# Run
28+
## Run
2829

2930
Execute any one of the following commands to run the workload:
3031

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`.
32+
- Natively: `mysqld --datadir /tmp/mysql-data`.
33+
- Gramine w/o SGX: `gramine-direct mysqld --datadir /tmp/mysql-data`.
34+
- Gramine with SGX: `gramine-sgx mysqld --datadir /tmp/mysql-data`.
3435

35-
# Testing client connection and running sysbench benchmarking
36+
## Testing client connection and running Sysbench
3637

37-
Run below command from new terminal:
38+
Run below commands from new terminal:
3839

39-
- `mysql -P 3306 --protocol=tcp -uroot` to connect a client to MySQL server.
40+
- `mysql -P 3306 --protocol=tcp -u root` to connect a client to MySQL server.
4041
- `mysql> exit` to disconnect the client.
4142

42-
Run Sysbench benchmarking:
43+
Run Sysbench:
4344

44-
- `sudo apt install -y sysbench` to install sysbench.
45+
- `sudo apt install -y sysbench` to install Sysbench.
4546
- `sudo mysqladmin -h 127.0.0.1 -P 3306 create sbtest` to create test database.
4647

4748
- `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
4849
create records in test database.
4950
- `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+
run the Sysbench benchmarks.
5152
- `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
5253
delete the records from test database.

mysql/mysqld.manifest.template

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ libos.entrypoint = "{{ entrypoint }}"
66
loader.log_level = "{{ log_level }}"
77

88
loader.env.LD_LIBRARY_PATH = "/lib:{{ arch_libdir }}:/usr/lib:/usr/{{ arch_libdir }}"
9-
loader.PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
109

1110
loader.insecure__use_cmdline_argv = true
1211
sys.enable_sigterm_injection = true
@@ -15,15 +14,19 @@ sgx.nonpie_binary = true
1514
sgx.enclave_size = "8G"
1615
sgx.thread_num = 128
1716

17+
loader.uid = {{ uid }}
18+
loader.gid = {{ gid }}
19+
1820
fs.mounts = [
1921
{ path = "/lib", uri = "file:{{ gramine.runtimedir() }}" },
2022
{ path = "{{ arch_libdir }}", uri = "file:{{ arch_libdir }}" },
2123
{ path = "/usr/{{ arch_libdir }}", uri = "file:/usr/{{ arch_libdir }}" },
22-
{ path = "/usr/sbin/mysqld", uri = "file:/usr/sbin/mysqld" },
24+
{ path = "{{ entrypoint }}", uri = "file:{{ entrypoint }}" },
2325
{ path = "/usr/lib/mysql", uri = "file:/usr/lib/mysql" },
2426
{ path = "/var/lib/mysql-files", uri = "file:/var/lib/mysql-files" },
2527
{ path = "/var/lib/mysql-keyring", uri = "file:/var/lib/mysql-keyring" },
2628
{ path = "/var/run/mysqld", uri = "file:/var/run/mysqld" },
29+
{ path = "/lib/mysql/plugin", uri = "file:/lib/mysql/plugin" },
2730
{ path = "/tmp", uri = "file:/tmp" },
2831
]
2932

@@ -34,6 +37,7 @@ sgx.trusted_files = [
3437
"file:{{ arch_libdir }}/",
3538
"file:/usr/{{ arch_libdir }}/",
3639
"file:/usr/lib/mysql/",
40+
"file:/lib/mysql/plugin/",
3741
]
3842

3943
sgx.allowed_files = [

0 commit comments

Comments
 (0)