I didn't catch the question had nothing to do with mysql! The question is actually here:
** (gedit:23076): WARNING **: Could not open X display
No protocol specified
error: XDG_RUNTIME_DIR not set in the environment.
(gedit:23076): Gtk-WARNING **: cannot open display: :0
The question then becomes "why didn't sudo -s -u mysql export my environment variable to the mysql session, including and especially all the environment variables relative to X?"...
Well, consider this:
root@o-2:~# export vartest="this is a test variable"
root@o-2:~# echo ${vartest}
this is a test variable
root@o-2:~# sudo -s -u mysql
mysql@o-2:/root$ echo ${vartest}
mysql@o-2:/root$
exit
That's what you have at the moment. if you try to echo ${XDG_DISPLAY} in your original session, you probably get something, while when you do it in the mysql session, you get nothing.
There is a solution in man sudo:
-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their existing environment variables.
The security policy may return an error if the user does not have permission to preserve the environment.
So, let's try that:
root@o-2:~# sudo -s -u mysql --preserve-env
bash: /root/.bashrc: Permission denied
mysql@o-2:~$ echo ${vartest}
this is a test variable
mysql@o-2:~$ whoami
mysql
mysql@o-2:~$ exit
As you can see, it kinda works: you "become" mysql with all the environment of your original user, expect a couple of mismatches, especially if you were coming from a root session. Fortunately, the manpage also says:
--preserve-env=list
Indicates to the security policy that the user wishes to add the comma-separated list of environment variables to those preserved from the user's environment.
The security policy may return an error if the user does not have permission to preserve the environment.
This option may be specified multiple times.
Let's try that:
root@o-2:~# sudo -s -u mysql --preserve-env=vartest
mysql@o-2:/root$ echo ${vartest}
this is a test variable
mysql@o-2:/root$
I don't have an X server at hand to test exactly your issue, but start with
sudo -s -u mysql --preserve-env=XDG_RUNTIME_DIR
and add variable names until you get no error (it's comma-separated, like in --preserve-env=XDG_RUNTIME_DIR,DISPLAY).