Cannot get mysql to start with --skip-grant-tables on ubuntu 16 - mysql

I lost my mysql password and need to reset it.
I have already tried https://help.ubuntu.com/community/MysqlPasswordReset
With the following result
erik#Trantor:~$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
erik#Trantor:~$ sudo /usr/sbin/mysqld --skip-grant-tables &
[1] 21335
erik#Trantor:~$
[1]+ Exit 1 sudo /usr/sbin/mysqld --skip-grant-tables
erik#Trantor:~$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
erik#Trantor:~$
I did not use the skip-networking option as that has been indicated by another post to cause it's own trouble and I'm not worried about security at the moment. Through some checking, I found that the service is failing to actually start with that option.
erik#Trantor:~$ sudo service mysql status
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
Active: inactive (dead) since Sun 2016-11-06 10:41:56 EST; 3min 45s ago
Process: 20846 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=e
Process: 20845 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
Process: 20842 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exi
Main PID: 20845 (code=exited, status=0/SUCCESS)
Nov 06 10:35:01 Trantor systemd[1]: Starting MySQL Community Server...
Nov 06 10:35:02 Trantor systemd[1]: Started MySQL Community Server.
Nov 06 10:41:55 Trantor systemd[1]: Stopping MySQL Community Server...
Nov 06 10:41:56 Trantor systemd[1]: Stopped MySQL Community Server.
lines 1-12/12 (END)
I'm not sure how to get mysql to start with the -skip-grant-tables option at this point, and without my password, I'm dead in the water.
I have tried to remove and install mysql-server again.
Anyone know how I can get it to start with the flag, or where I should look next?

Related

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) after sudo rm -rf /var/lib/mysql*

Background: I am using Ubuntu-20.04 and I needed to downgrade MySQL version from 8.0 to 5.7.
By using multiple tutorials I had not succeeded and then I installed MySQL 8.0 again but now I can not connect with MySQL 8.0.
mysql -u root -p
and got error
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I think the reason was I had run these two commands:
sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql*
After reinstalling mysql 8.0 i found /etc/mysql but there is no directory like /var/lib/mysql* .
Please help me to login in mysql, I have tried a lot of solutions. If you have any question, please let me know.
Some extra Details:
usman#usman-Lenovo-V310-15ISK:~$ systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2021-08-22 22:46:33 PKT; 22min ago
Process: 369742 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)
Aug 22 22:46:33 usman-Lenovo-V310-15ISK systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
Aug 22 22:46:33 usman-Lenovo-V310-15ISK systemd[1]: Stopped MySQL Community Server.
Aug 22 22:46:33 usman-Lenovo-V310-15ISK systemd[1]: mysql.service: Start request repeated too quickly.
Aug 22 22:46:33 usman-Lenovo-V310-15ISK systemd[1]: mysql.service: Failed with result 'exit-code'.
Aug 22 22:46:33 usman-Lenovo-V310-15ISK systemd[1]: Failed to start MySQL Community Server.
It worked for me. And its perfect solution as per my problem.
Solution

MYSQL don't start

Previously I performed the migration of my database from one directory to another within the server itself (/var/lib/mysql to /mnt/mysql) for lack of space.
When starting the server again, after having changed the /etc/my.cnf with the correct directory it returns me this error:
$ systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
And when I run the systemctl status command on the mysqld service it returns me:
$ systemctl status mysqld.service
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Ter 2019-07-16 09:34:44 -03; 44s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 31923 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
Process: 31899 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 31923 (code=exited, status=1/FAILURE)
Status: "SERVER_BOOTING"
Error: 13 (Permission Denied)
Jul 16 09:34:43 srvepl.cettro.local systemd[1]: Starting MySQL Server...
Jul 16 09:34:44 srvepl.cettro.local systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
Jul 16 09:34:44 srvepl.cettro.local systemd[1]: Failed to start MySQL Server.
Jul 16 09:34:44 srvepl.cettro.local systemd[1]: Unit mysqld.service entered failed state.
Jul 16 09:34:44 srvepl.cettro.local systemd[1]: mysqld.service failed.
If it is permission error, how do I free the server to accept such a directory?
Note: I am using CentOS 7
Thank you!!
If you are using Linux or Unix Server then you should check the permissions of the user to access the service. Here I can see that the user which is logged in can't access the service because of the permission problem.
Try with.
sudo systemctl start mysqld;
Or try sudo su;, enter the creds of the superuser and then try to check the service status.
Or login as superuser and then try to start the service.
Hope this may help you.
After searching i discovered that the error was the 'enforcing' permission of SELINUX.
The answer to fix this problem is:
$ sudo setenforce 0
And the server went up normally.
Are you logged in with root user?
If no, try with sudo.
Otherwise, I think is better to restart your system and try again.
If you aren't expert in linux centos don't manipulate anything.
uninstall mysql and reinstall it.

mysql or mariadb - strange server behaviour

I try to stop mysql but anything I do nothing happens
I checked my database:
~$ mysql --version
mysql Ver 15.1 Distrib 10.0.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
It shows that Im using MariaDB ok... So I tried to stop it and...
$ sudo systemctl stop mariadb
Failed to stop mariadb.service: Unit mariadb.service not loaded.
mariadb.service not loaded? why?
I tried to stop database with this command:
sudo systemctl stop mysql
I got no error.
but my website still works. It means database is running.
when I print out status of mysql:
Loaded: loaded (/etc/init.d/mysql; bad; vendor preset: enabled)
Active: failed (Result: exit-code) since wto 2018-04-24 00:32:29 CEST; 9min ago
Docs: man:systemd-sysv-generator(8)
Process: 2062 ExecStop=/etc/init.d/mysql stop (code=exited, status=1/FAILURE)
Process: 1988 ExecStart=/etc/init.d/mysql start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/mysql.service
├─1459 /bin/bash /usr/bin/mysqld_safe
├─1608 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --skip-log-error --pid-file=/var/r
└─1609 logger -t mysqld -p daemon error
kwi 24 00:32:29 bla-Z68A-D3H-B3 mysql[2062]: * Stopping MariaDB database server mysqld
kwi 24 00:32:29 bla-Z68A-D3H-B3 mysql[2062]: ...fail!
kwi 24 00:32:29 bla-Z68A-D3H-B3 systemd[1]: mysql.service: Control process exited, code=exited status=1
kwi 24 00:32:29 bla-Z68A-D3H-B3 systemd[1]: Stopped LSB: Start and stop the mysql database server daemon.
kwi 24 00:32:29 bla-Z68A-D3H-B3 systemd[1]: mysql.service: Unit entered failed state.
kwi 24 00:32:29 bla-Z68A-D3H-B3 systemd[1]: mysql.service: Failed with result 'exit-code'.
kwi 24 00:33:21 bla-Z68A-D3H-B3 systemd[1]: Stopped LSB: Start and stop the mysql database server daemon.
kwi 24 00:36:51 bla-Z68A-D3H-B3 systemd[1]: Stopped LSB: Start and stop the mysql database server daemon.
kwi 24 00:40:27 bla-Z68A-D3H-B3 systemd[1]: Stopped LSB: Start and stop the mysql database server daemon.
kwi 24 00:40:31 bla-Z68A-D3H-B3 systemd[1]: Stopped LSB: Start and stop the mysql database server daemon.
My question is how can I stop mysql database.
Im getting this error
#1045 - Access denied for user 'skni'#'localhost' (using password: YES)
I found solution that to fix it I need first stop database
mysql --version
says gives the commandline tool's is version. It says nothing about whether mysqld (the 'server') is running.
This might be more informative:
mysqladmin -u root status
where you use sufficient credentials (user/password/host/port) to actually connect to the server.
#1045 - Access denied for user 'skni'#'localhost' (using password: YES)
Says that user 'skni' is not allowed to connect with the password used. This is a login problem, not a server start/stop problem. The server must be running for that message to occur.

Webmin MySQL Error on starting

Firstly, I must say that I have not used these tools in the past so linux commands are not familiar to me.
Backstory:
On my Webmin server, I have been trying to get a Drupal Installation to work. I changed a parameter on the MySQL module and now the MySQL will not start.
Current Situation:
When I click "Start MySQL Server" I receive the follow:
Failed to start database : Redirecting to /bin/systemctl start
mariadb.service Job for mariadb.service failed because the control
process exited with error code. See "systemctl status mariadb.service"
and "journalctl -xe" for details.
I've search around this, and most people recommend to reinstall MariaDB.
I connected to the server with putty to get some more information
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2017-08-01 16:29:00 UTC; 7min ago
Process: 22851 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=1/FAILURE)
Process: 22850 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)
Process: 22823 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 22850 (code=exited, status=0/SUCCESS)
Aug 01 16:28:57 li172-89.members.linode.com systemd[1]: Starting MariaDB database server...
Aug 01 16:28:57 li172-89.members.linode.com mysqld_safe[22850]: 170801 16:28:57 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Aug 01 16:28:57 li172-89.members.linode.com mysqld_safe[22850]: 170801 16:28:57 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Aug 01 16:29:00 li172-89.members.linode.com systemd[1]: mariadb.service: control process exited, code=exited status=1
Aug 01 16:29:00 li172-89.members.linode.com systemd[1]: Failed to start MariaDB database server.
Aug 01 16:29:00 li172-89.members.linode.com systemd[1]: Unit mariadb.service entered failed state.
Aug 01 16:29:00 li172-89.members.linode.com systemd[1]: mariadb.service failed.
[root#li172-89 ~]#
I gather that this means Mariadb wont even start so I should probably reinstall it. I did try to simply use a defaul my.cnf but that didn't really do anything.
Ideally, I do not want to lose any of the databases I have.
What should I do? Should I reinstall Mariadb? Is there a suitable guide that lists the commands? Could I install Mariadb but to another folder?
What is the best course of action at this point?

Mysql Error ERROR 2002 (HY000) persists after full reinstall

So I've been working on a rails server with MySQL and suddenly can't access my database. When I try to log in with mysql -u root -p I get ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2). I've read most of the forums I can find and looked through all the logs trying to reset mysqld.sock. I've tried reinstalling and repackaging unsuccessfully. The weird thing is that var/run/mysqld/ doesn't even exist after reinstalling.
So I decided to just back up my databases and overhaul everything. I cleaned out both apache and mysql with apt-get remove --purge and reinstalled. All went fine, apache launched fine, and then tried to relaunch mysql with systemctl start mysql which gave a prompt to check the log which says:
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Fri 2016-12-16 23:56:19 UTC; 17s ago
Process: 15690 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: mysql.service: Control process exited, code=exited status=1
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: Failed to start MySQL Community Server.
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: mysql.service: Unit entered failed state.
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: mysql.service: Failed with result 'exit-code'.
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: Stopped MySQL Community Server.
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: mysql.service: Start request repeated too quickly.
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: Failed to start MySQL Community Server.
Update - I created the folder mysqld, which seems to allow sudo mysqld --initialize to run. Unfortunately this yielded the error
2016-12-17T00:16:36.298825Z 0 [ERROR] Can't change data directory owner to mysql
2016-12-17T00:16:36.299212Z 0 [ERROR] Aborting
So no party yet. Any thoughts would be hugely appreciated.
edit /etc/mysql/conf.d/mysql.cnf :
sudo nano /etc/mysql/conf.d/mysql.cnf
add this line :
socket=/var/run/mysqld/mysqld.sock
then restart mysql service :
sudo service mysql restart