mysqld.service failed because a timeout was exceeded - mysql

With this command:
sudo systemctl restart mysqld
I face with this error:
Job for mysqld.service failed because a timeout was exceeded. See "systemctl status mysqld.service" and "journalctl -xe" for details.
How can I solve it?

Most probably you have huge database that requires a lot of time to start.
If that's the case then you can change the service start timeout to something that will work for you. To do that add this line to the service file:
TimeoutSec=1200
or
TimeoutStartSec=1200
If you are using MariaDB then the file is located at this path:
/usr/share/mysql/systemd/mariadb.service
If you are using MySQL then probably the path is:
/usr/share/mysql/systemd/mysqld.service

Reinstalling MySQL might help:
Uninstall the current MySQL
Delete /var/lib/mysql and /etc/mycnf or /etc/mycng.rpmsave
Reboot the machine
Reinstall MySQL

This maybe related to selinux being set to enforcing. Have a look at /etc/selinux/config (on CentOS, location may vary on other distributions). If SELINUX=enforcing, try setting SELINUX=permissive and
Reboot the machine
Start MySQL if not already (sudo systemctl start mysqld)
In case SELINUX=enforcing is required, have a look at https://www.techrepublic.com/blog/linux-and-open-source/practical-selinux-for-the-beginner-contexts-and-labels/ or other similar posts.
Hope this helps.

Related

I faced error message Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' when I tried to connect local mysql server

I am trying to connect my local MySQL server, but I am facing this error message.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
I tried many solutions on different websites, but none of them did not work. As an instance, I tried to kill the mysql and mysqld processes and then restart the MySQL service, but not worked.
Or I executed these lines (from another site):
sudo chmod -R u+rwx /etc/mysql/
sudo chown -R mysql.mysql /etc/mysql/
but did not work and gave me the new error message:
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
Could you please help me with this problem?
Thanks
Finally, after about 3 hours of searching on net, the solution founded on this site :-)
https://askubuntu.com/questions/1008298/cant-start-mysql-server-database-corruption
Edit the my.cnf (/etc/mysql/my.cnf) file and add the following lines:
[mysqld]
innodb_force_recovery = 1
then run the command:
sudo systemctl start mysql
It may do not work for the first time and you need to increment the number to 2 or 3. I will be fixed finally. :-)

mysql server doesn't recognize changes in my.cnf

I have installed mysql server and mysql client with bundle in Centos 7. mysql server's port is displayed as 0. I want to give specific port to it. For this purpose, I have changed /etc/my.cnf with below;
port=4545
After changes, I've restarted the service. But it's start with skip-networking as ON. I have also tried to change skip-networking to OFF but didn't accomplish.
I have also tried mysql_secure_installation after changes but got below error :
Failed! Error: The MySQL server is running with the
--skip-grant-tables option so it cannot execute this statement
How can i solve this?
Thanks for answering
I have solved my question with below;
systemctl stop mysqld
systemctl daemon-reload
systemctl set-environment MYSQLD_OPTS="--skip-networking=OFF"
After this I have started service again.
systemctl start mysqld

mysql.sock does not exist error in fresh install of MySQL on Arch Linux

I'm trying to use MySQL on Arch Linux. it is already installed but this error comes up when I try to connect:
connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory")'
I've looked for /etc/my.cfg but the file does not exist.
Something must have gone wrong during the installation.
How can I "purge" MariaDB and reinstall it?
If you're using archlinux it is a vital idea to understand the package manager (pacman). For the question about /etc/my.cfg you can run
pacman -Ql mariadb
there you will see that the file is actually called:
/etc/mysql/my.cnf
Arch linux will not configure the package for you, that is part of the arch philosophy. It will provide example configurations, and even provide you with a systemd unit file
usr/lib/systemd/system/mysqld.service
but it is your responsibility to ensure that the configuration is correct and actually start the daemon.
systemctl enable mysqld # add the unit file to the boot sequence
systemctl start mysqld # runs ExecStart= in the unit file
systemctl stop mysqld # kills the daemon
systemctl disable mysqld # remove unit from boot sequence
reinstall
Since the word reinstall is in the title of the question and someone might find this question thanks to that: To reinstall mariadb you simply do
pacman -S mariadb
pacman will reinstall a package that is already installed, there is no need to remove the package (for completeness, package removal happens with pacman -R)
as of 7-28-17 I had to do this on a new install. Newbie here might save someone some time. It was a real pain.
OK HERE IS THE DEAL!!!!!
INSTALL APACHE _ NO PROB
INSTALL MYSQL _PROBLEM
pacman -S mysql then before starting service
MUST UNCOMMENT INNODB IN:
nano /etc/mysql/my.cnf
then must initialize datadirectory before starting service:
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
You need to initialize the MariaDB data directory prior to starting
the service. This can be done with mysql_install_db command, e.g.:
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Optional dependencies for mariadb
galera: for MariaDB cluster with Galera WSREP
perl-dbd-mysql: for mysqlhotcopy, mysql_convert_table_format and
mysql_setpermission
CNF file is /etc/mysql/my.cnf in Arch Linux.
One simple way I can reproduce your issue is when MariaDB is shut down. Sorry if it sounds dumb but as you did not mention it: is MariaDB started? sudo systemctl start mysqld.service
You should have a look at MariaDB logs to get some clue: journalctl _SYSTEMD_UNIT=mysqld.service (maybe paste some part if you still don't get what is going on).
This happens the first time you install MySQL and MariaDB. As grochmal pointed out, you have to set up configurations before first use. But, the user teckk sent these three links in the archlinux newbie corner:
https://wiki.archlinux.org/index.php/MariaDB
https://wiki.archlinux.org/index.php/MariaDB#Reset_the_root_password
https://bbs.archlinux.org/viewtopic.php?id=51981
In short, you have to run the command below before starting the service:
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Optionally (recommended) you should improve the initial security by calling:
sudo mysql_secure_installation
Now you can start the service:
sudo systemctl start mariadb
Optionally, you could install and use a graphical front-end tool.
Carry on with setting up the configurations as described in the archwiki post on MariaDB Configuration.

MySQl 5.7 installation failed on Kubuntu 16.04 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
Configuring mysql-server-5.7 (5.7.11-0ubuntu6) …
insserv: warning: current start runlevel(s) (empty) of script `mysql' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `mysql' overrides LSB defaults (0 1 6).
mysql_upgrade: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) while connecting to the MySQL server
Upgrade process encountered error and will not continue.
mysql_upgrade failed with exit status 11
dpkg: error with
mysql-server-5.7 (--configure):
apt-get remove return the same result.
This error come in with upgrade from 15.10 to 16.04
It was exactly same for me: runlevel warnings and mysql_upgrade error.
I guess it was because I disabled mysql service, enabling it fixes the problem:
sudo systemctl enable mysql
I've just encountered this problem, there's a bug report that is quite similar here: https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/1584287
In my case I had the mysql.service set to disabled and the mysql_upgrade script seemed incapable of starting the server in this case. I enabled the service (didn't need to start it) and re-ran the upgrade. After that worked I stopped the service and disabled it again.
I'm not sure what else might cause this, but if someone encounters this with the service disabled, just enable it for the upgrade.
Manualy remove all file of MySQL server
Seems mysql-server is now replaced with mariadb
Installing maridb-server fixed the issue.
sudo apt-get install mariadb-server
Note:- You won't get your databases. Reset mysql password using command mysql_secure_installation
In my case I could solve the problem by changing apparmor (on kubuntu 16.04 using plasma).
I took a look at journalctl -xe as suggested by the installation error message:
[....] Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
In there I found apparmor DENIED messages:
AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/home/system/var/log/mysql/error.log" pid=32610 comm="mysqld" request
In deed, the base directory /home/system/... exists, but access is not allowed by /etc/apparmor.d/usr.sbin.mysqld.
So adding the following lines to /etc/apparmor.d/local/usr.sbin.mysqld solved my problem:
# For more details, please see /etc/apparmor.d/local/README.
# Allow log file access
/home/system/var/log/mysql.err rw,
/home/system/var/log/mysql.log rw,
/home/system/var/log/mysql/ r,
/home/system/var/log/mysql/** rw,
Don't forget to restart apparmor, and restart mysql installation (e.g. apt-get install --reinstall mysql-common mysql-server or whatever is your way to install it.)
I don't know at all why (and since when) the directory /home/system exists and why mysql points in there. But some day a hopefully figure out ... ;)
Below worked for me, found solution - here
sudo update-alternatives --remove my.cnf /etc/mysql/my.cnf.migrated
sudo service mysql start
I found the solution here
Remove all of mysql's files:
rm -r /var/lib/mysql*
Install mysql self database:
mysql_install_db -u mysql
(might not work for newer systems, but don't worry)
Enable the service for systemd: systemctl unmask mysql.service
Then start the mysql service service mysql start

fresh installed mysql and mysql-server but failed to start server

I am new to Linux and tried to install mysql in my local box
I googled a lot and follow the instruction but none of them works
some people recommand this" but it did not work for me and system give me warning about this is not a official version.
Basically what I did was:
yum install mysql mysql-version
succeed without error, version is 5.5.28
systemctl start mysqld.service
here it threw out error:
Job failed. See system logs and 'systemctl status' for details.
I am using Fedora 16 (3.1.0-7.fc16.i686)
Thank you in advance
Could you try running
yum groupinstall "MySQL Database"
then run
service mysqld start
and see the outcome. Assuming you are running as root or with root permissions.
Got the EXACT same problem. It seems there is an issue regarding the permissions of the /var/lib/mysql directory.
This nailed it for me:
chown -R mysql.mysql /var/lib/mysql
Source: http://www.vivaolinux.com.br/dica/Como-solucionar-ERROR-2002-Cant-connect-to-local-MySQL-server