Can't connect to local MySQL server through socket

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
All commands in debian9's interactive non-login shell (graphical mode).
I want to backup mysql before reboot or shutdown.
who
test tty7 2018-02-01 18:26 (:0)
test@world:~$ pwd
/home/test
Now the following three commands can backup mysql database.
USERNAME="xxxx"
PASSWORD="yyyy"
mysqldump -u root -p$PASSWORD database > /home/test/wp.sql.bak
Create a service running before reboot or shutdown.
vim /etc/systemd/system/test.service
[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh
[Install]
WantedBy=multi-user.target
The test.sh file .
cat /home/test/test.sh
USERNAME="xxxx"
PASSWORD="yyyy"
mysqldump -u root -p$PASSWORD database > /home/test/wp.sql.bak
Enable the service.
sudo systemctl enable test.service
sudo reboot
Now log into interactive non-login shell (graphical mode).
sudo systemctl enable test.service
-- Logs begin at Thu 2018-02-01 18:26:04 HKT, end at Thu 2018-02-01 18:27:23 HKT. --
Feb 01 18:26:13 world systemd[1]: Starting Run command at shutdown...
Feb 01 18:26:18 world bash[480]: mysqldump: Got error: 2002: "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")"
Feb 01 18:26:19 world systemd[1]: test.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Feb 01 18:26:19 world systemd[1]: Failed to start Run command at shutdown.
Feb 01 18:26:19 world systemd[1]: test.service: Unit entered failed state.
Feb 01 18:26:19 world systemd[1]: test.service: Failed with result 'exit-code'
The three commands can run in terminal instead of containing in test.service,how to write a service backuping all mysql datadb when reboot or shutdown?
systemd mysql shutdown reboot socket
add a comment |Â
up vote
0
down vote
favorite
All commands in debian9's interactive non-login shell (graphical mode).
I want to backup mysql before reboot or shutdown.
who
test tty7 2018-02-01 18:26 (:0)
test@world:~$ pwd
/home/test
Now the following three commands can backup mysql database.
USERNAME="xxxx"
PASSWORD="yyyy"
mysqldump -u root -p$PASSWORD database > /home/test/wp.sql.bak
Create a service running before reboot or shutdown.
vim /etc/systemd/system/test.service
[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh
[Install]
WantedBy=multi-user.target
The test.sh file .
cat /home/test/test.sh
USERNAME="xxxx"
PASSWORD="yyyy"
mysqldump -u root -p$PASSWORD database > /home/test/wp.sql.bak
Enable the service.
sudo systemctl enable test.service
sudo reboot
Now log into interactive non-login shell (graphical mode).
sudo systemctl enable test.service
-- Logs begin at Thu 2018-02-01 18:26:04 HKT, end at Thu 2018-02-01 18:27:23 HKT. --
Feb 01 18:26:13 world systemd[1]: Starting Run command at shutdown...
Feb 01 18:26:18 world bash[480]: mysqldump: Got error: 2002: "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")"
Feb 01 18:26:19 world systemd[1]: test.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Feb 01 18:26:19 world systemd[1]: Failed to start Run command at shutdown.
Feb 01 18:26:19 world systemd[1]: test.service: Unit entered failed state.
Feb 01 18:26:19 world systemd[1]: test.service: Failed with result 'exit-code'
The three commands can run in terminal instead of containing in test.service,how to write a service backuping all mysql datadb when reboot or shutdown?
systemd mysql shutdown reboot socket
1
Looks like your mysql instance has been stopped before the backup runs.
â Raman Sailopal
Feb 1 at 14:35
1
Use the ExecStop=/bin/bash /home/test/test.sh in the actual mysql service template. This should execute the backup before mysql is killed.
â Raman Sailopal
Feb 1 at 14:38
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
All commands in debian9's interactive non-login shell (graphical mode).
I want to backup mysql before reboot or shutdown.
who
test tty7 2018-02-01 18:26 (:0)
test@world:~$ pwd
/home/test
Now the following three commands can backup mysql database.
USERNAME="xxxx"
PASSWORD="yyyy"
mysqldump -u root -p$PASSWORD database > /home/test/wp.sql.bak
Create a service running before reboot or shutdown.
vim /etc/systemd/system/test.service
[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh
[Install]
WantedBy=multi-user.target
The test.sh file .
cat /home/test/test.sh
USERNAME="xxxx"
PASSWORD="yyyy"
mysqldump -u root -p$PASSWORD database > /home/test/wp.sql.bak
Enable the service.
sudo systemctl enable test.service
sudo reboot
Now log into interactive non-login shell (graphical mode).
sudo systemctl enable test.service
-- Logs begin at Thu 2018-02-01 18:26:04 HKT, end at Thu 2018-02-01 18:27:23 HKT. --
Feb 01 18:26:13 world systemd[1]: Starting Run command at shutdown...
Feb 01 18:26:18 world bash[480]: mysqldump: Got error: 2002: "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")"
Feb 01 18:26:19 world systemd[1]: test.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Feb 01 18:26:19 world systemd[1]: Failed to start Run command at shutdown.
Feb 01 18:26:19 world systemd[1]: test.service: Unit entered failed state.
Feb 01 18:26:19 world systemd[1]: test.service: Failed with result 'exit-code'
The three commands can run in terminal instead of containing in test.service,how to write a service backuping all mysql datadb when reboot or shutdown?
systemd mysql shutdown reboot socket
All commands in debian9's interactive non-login shell (graphical mode).
I want to backup mysql before reboot or shutdown.
who
test tty7 2018-02-01 18:26 (:0)
test@world:~$ pwd
/home/test
Now the following three commands can backup mysql database.
USERNAME="xxxx"
PASSWORD="yyyy"
mysqldump -u root -p$PASSWORD database > /home/test/wp.sql.bak
Create a service running before reboot or shutdown.
vim /etc/systemd/system/test.service
[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh
[Install]
WantedBy=multi-user.target
The test.sh file .
cat /home/test/test.sh
USERNAME="xxxx"
PASSWORD="yyyy"
mysqldump -u root -p$PASSWORD database > /home/test/wp.sql.bak
Enable the service.
sudo systemctl enable test.service
sudo reboot
Now log into interactive non-login shell (graphical mode).
sudo systemctl enable test.service
-- Logs begin at Thu 2018-02-01 18:26:04 HKT, end at Thu 2018-02-01 18:27:23 HKT. --
Feb 01 18:26:13 world systemd[1]: Starting Run command at shutdown...
Feb 01 18:26:18 world bash[480]: mysqldump: Got error: 2002: "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")"
Feb 01 18:26:19 world systemd[1]: test.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Feb 01 18:26:19 world systemd[1]: Failed to start Run command at shutdown.
Feb 01 18:26:19 world systemd[1]: test.service: Unit entered failed state.
Feb 01 18:26:19 world systemd[1]: test.service: Failed with result 'exit-code'
The three commands can run in terminal instead of containing in test.service,how to write a service backuping all mysql datadb when reboot or shutdown?
systemd mysql shutdown reboot socket
edited Feb 1 at 14:38
Jeff Schaller
31.4k846105
31.4k846105
asked Feb 1 at 14:28
scrapy
317213
317213
1
Looks like your mysql instance has been stopped before the backup runs.
â Raman Sailopal
Feb 1 at 14:35
1
Use the ExecStop=/bin/bash /home/test/test.sh in the actual mysql service template. This should execute the backup before mysql is killed.
â Raman Sailopal
Feb 1 at 14:38
add a comment |Â
1
Looks like your mysql instance has been stopped before the backup runs.
â Raman Sailopal
Feb 1 at 14:35
1
Use the ExecStop=/bin/bash /home/test/test.sh in the actual mysql service template. This should execute the backup before mysql is killed.
â Raman Sailopal
Feb 1 at 14:38
1
1
Looks like your mysql instance has been stopped before the backup runs.
â Raman Sailopal
Feb 1 at 14:35
Looks like your mysql instance has been stopped before the backup runs.
â Raman Sailopal
Feb 1 at 14:35
1
1
Use the ExecStop=/bin/bash /home/test/test.sh in the actual mysql service template. This should execute the backup before mysql is killed.
â Raman Sailopal
Feb 1 at 14:38
Use the ExecStop=/bin/bash /home/test/test.sh in the actual mysql service template. This should execute the backup before mysql is killed.
â Raman Sailopal
Feb 1 at 14:38
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
First, use ExecStop=/bin/bash /home/test/test.sh rather than ExecStart. See How to run a script with systemd right before shutdown? for more information. You appear to be running your script on startup, presumably before mysql is fully started.
Second, consider adding After=mariadb.service to be sure the script is run before mysql is shut down. Remember that, when considering shutdown order, everything is in reverse.
add a comment |Â
up vote
0
down vote
[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target
After=mariadb.service
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/bin/bash /home/test/test.sh
[Install]
WantedBy=multi-user.target
It is mariadb in debian9 instead of mysql.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
First, use ExecStop=/bin/bash /home/test/test.sh rather than ExecStart. See How to run a script with systemd right before shutdown? for more information. You appear to be running your script on startup, presumably before mysql is fully started.
Second, consider adding After=mariadb.service to be sure the script is run before mysql is shut down. Remember that, when considering shutdown order, everything is in reverse.
add a comment |Â
up vote
1
down vote
accepted
First, use ExecStop=/bin/bash /home/test/test.sh rather than ExecStart. See How to run a script with systemd right before shutdown? for more information. You appear to be running your script on startup, presumably before mysql is fully started.
Second, consider adding After=mariadb.service to be sure the script is run before mysql is shut down. Remember that, when considering shutdown order, everything is in reverse.
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
First, use ExecStop=/bin/bash /home/test/test.sh rather than ExecStart. See How to run a script with systemd right before shutdown? for more information. You appear to be running your script on startup, presumably before mysql is fully started.
Second, consider adding After=mariadb.service to be sure the script is run before mysql is shut down. Remember that, when considering shutdown order, everything is in reverse.
First, use ExecStop=/bin/bash /home/test/test.sh rather than ExecStart. See How to run a script with systemd right before shutdown? for more information. You appear to be running your script on startup, presumably before mysql is fully started.
Second, consider adding After=mariadb.service to be sure the script is run before mysql is shut down. Remember that, when considering shutdown order, everything is in reverse.
edited Feb 2 at 3:13
answered Feb 1 at 18:19
Steve Brandli
1265
1265
add a comment |Â
add a comment |Â
up vote
0
down vote
[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target
After=mariadb.service
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/bin/bash /home/test/test.sh
[Install]
WantedBy=multi-user.target
It is mariadb in debian9 instead of mysql.
add a comment |Â
up vote
0
down vote
[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target
After=mariadb.service
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/bin/bash /home/test/test.sh
[Install]
WantedBy=multi-user.target
It is mariadb in debian9 instead of mysql.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target
After=mariadb.service
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/bin/bash /home/test/test.sh
[Install]
WantedBy=multi-user.target
It is mariadb in debian9 instead of mysql.
[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target
After=mariadb.service
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/bin/bash /home/test/test.sh
[Install]
WantedBy=multi-user.target
It is mariadb in debian9 instead of mysql.
answered Feb 2 at 1:33
scrapy
317213
317213
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f421214%2fcant-connect-to-local-mysql-server-through-socket%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Looks like your mysql instance has been stopped before the backup runs.
â Raman Sailopal
Feb 1 at 14:35
1
Use the ExecStop=/bin/bash /home/test/test.sh in the actual mysql service template. This should execute the backup before mysql is killed.
â Raman Sailopal
Feb 1 at 14:38