how to kill process holding the apt lock - mysql

I'm updating apt and installing mysql-client at run time to a ubuntu 18.04 aws instance.
My shell command are like,
- apt-get update
- apt-get install -y mysql-client
- apt-get install -y unzip
But 'apt-get install -y mysql-client' hang and lock apt. Therefor 'apt-get install -y unzip' get fail. So to proceed this, I have to manually kill the process and unclock the apt from following commands.
Step 01. ps -ef | grep apt
Step 02. kill -9
Step 03. sudo dpkg --configure -a
Step 04. Yes the below message
restarts will be done for you automatically so you can avoid being asked questions on each library upgrade. │ Restart services during package upgrades without asking?
Step 05. apt-get install -y mysql-client
My question is how I implement following from shell script or is there a any way to install mysql-client at run time?

Try to set DEBIAN_FRONTEND=noninteractive and the -q parameter to avoid apt from opening interactive prompts.
e.g:
DEBIAN_FRONTEND=noninteractive apt-get install -yq mysql-client

Related

How to install MySQL 5.6 in Ubuntu 18.04(VM)

I'm using packer to install MySQL 5.6 on an Ubuntu VM. To install it, I'm using the below script.
#!/bin/bash
sudo add-apt-repository 'deb http://kr.archive.ubuntu.com/ubuntu xenial main' -y
sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty universe' -y
sudo apt-get update -y
sudo apt-get install mysql-server-5.6 -y
systemctl restart mysql
However, the installer kept prompting for a password. Is there any way to pass the password in the script since it's installed within a VM? I'm stuck in this situation.
error-screenshot

How to install mysql workbench in debian buster?

I tried the following commands :
sudo dpkg -i mysql-apt-config_0.3.5-1debian8_all.deb
sudo apt-get update
sudo apt-get install mysql-workbench-community
but on searching mysql-workbench-community
sudo apt-cache search workbench | grep mysql
returns nothing.
And
sudo apt-get install mysql-workbench-community
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package mysql-workbench-community
What to do ?
I did manage to install without issues MySQL Workbench 8.0.19 version from an Ubuntu package in Debian Buster, with the command:
sudo dpkg -i mysql-workbench-community_8.0.19-1ubuntu18.04_amd64.deb
First you must download the package from the mysql website:
Just select Ubuntu Linux operating system and 18.04 version (19.10 version had broken dependencies) .
Hope this helps.
MySQL Workbench mysql-workbench has been removed from Debian buster due to a release-critical bug.
https://tracker.debian.org/pkg/mysql-workbench
https://tracker.debian.org/news/943250/mysql-workbench-removed-from-testing/
https://bugs.debian.org/867943
https://bugs.mysql.com/bug.php?id=89898
It can also be installed from Snapcraft. I haven't used it that much, but apparently it works. First you need to enable snapd:
$ sudo apt update
$ sudo apt install snapd
$ sudo snap install core
Then install MySQL workbench (community edition):
$ sudo snap install mysql-workbench-community
If you want to delete it, simply:
$ sudo snap remove mysql-workbench-community
I was able to install the latest version of MySQL Workbench (as of this writing) on Debian 10 using this method:
sudo apt install ./mysql-workbench-community_8.0.23-1ubuntu20.10_amd64.deb
A couple dependencies were missing so I subsequently ran:
sudo apt --fix-broken install
Just started using it, but MySQL Workbench seems to be running fine. It's also worth mentioning the link below states MySQL Workbench community is not available on Debian, although I'm not sure why this is the case.
mysql-workbench-community - MySQL Workbench (not available for Debian
platforms)
https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/#repo-qg-apt-available
Command line to install mysql on Debian 10:
$ sudo apt update
$ sudo apt upgrade
$ wget http://repo.mysql.com/mysql-apt-config_0.8.13-1_all.deb
$ sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb
Remember to make safe passwords with lettler numbers and symbols
$ sudo apt update
$ sudo apt install mysql-server
$ sudo apt-get build-dep mysql-server
$ wget https://downloads.mysql.com/archives/get/file/mysql-workbench-community_8.0.16-1ubuntu18.04_amd64.deb
$ sudo dpkg -i mysql-workbench-community_8.0.16-1ubuntu18.04_amd64.deb
$ sudo apt install -f
$ sudo dpkg -i mysql-workbench-community_8.0.16-1ubuntu18.04_amd64.deb
have a nice coding!

unable to install mysql on ubuntu 16.04

I ran the following command
wget http://repo.mysql.com/mysql-apt-config_0.8.9-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.9-1_all.deb
sudo apt-get update
all goes well but when i hit
sudo apt-get install mysql-server
It gives me following errors
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created or
been moved out of Incoming. The following information may help to
resolve the situation:
The following packages have unmet dependencies: mysql-server :
Depends: mysql-community-server (= 5.7.20-1ubuntu16.04) but it is not
going to be installed E: Unable to correct problems, you have held
broken packages.
To fix broken packages i did ran
sudo apt-get install -f
sudo apt autoremove
sudo apt-get update
but all in vain. Thanks to you guys in advance :)
To begin with, I deleted MySQL with:
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get autoremove
sudo apt-get autoclean
Then I downloaded the .deb from oficial page and used the following commands:
curl -OL https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
sudo dpkg -i mysql-apt-config*
sudo apt update
sudo apt install mysql-server -y
At this point I had trouble because of Ubuntu eoan "incompability" (I'm using Ubuntu 19.10), displaying a message like: "The detected system (Debian jessie) is not supported by MySQL. If you believe the platform is compatible with one of the supported systems, one of the corresponding repositories may be selected". But I researched in MySQL bugs page and ran:
dpkg -i mysql-apt-config_0.8.13-1_all.deb
sudo apt update
sudo apt install mysql-server -y
When it finishes, you may check the installation with:
sudo systemctl status mysql.service
And you should see something like...
This worked for me, after trying solutions in StackExchange, none of which worked. I hope this helps! Looking for feedback if I did something wrong, thanks.
try to install mysql server with the version.
sudo apt-get update
sudo apt-get install mysql-server-5.6

dpkg: error processing package mysql-server (dependency problems)?

When I try to install mysql-server, an error comes like:
dpkg: error processing package mysql-server (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
mysql-server-5.7
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
What does it mean. Any ideas?
dpkg returning an error code 1 doesn't mean anything specific but it usually has to do with dependency issues. In your case, you tried to install two versions/instances of the same package i.e. mysql-server and mysql-server-5.7. So do the following to remove any redundant dependency issues and install a functioning mysql package
sudo apt-get clean
sudo apt-get purge mysql*
sudo apt-get update
sudo apt-get install -f
sudo apt-get install mysql-server-5.7
sudo apt-get dist-upgrade
this should fix the problem at hand. But in the future, have care about the package names you add after sudo apt-get install since the wrong list of package names - for example redundant entries in the list - results in failure to install either of the packages or worse - you might even find yourself wading through the hellish depths of #DEPENDENCY-HELL
All of the answers I've been able to find for this question have been of the form "purge your Mysql install and re-install it." But in my case, I already have a working/active Mysql install. For me, the reason why dpkg --configure -a fails is because Mysql is already installed. Why dpkg thinks that the postinstall script needs to be run for my already-installed-and-upgraded Mysql I may never know, but it does.
After considerable time scouring for answers, I found a solution that should work if there are others who already have a working Mysql 5.7 and just want to get past this bogus postinstall script. You can edit the postinstall script directly as (on Ubuntu):
sudo vi /var/lib/dpkg/info/mysql-server-5.7.postinst
And then, on the second line, just add exit 0 and then run dpkg again and you should get something like:
$ sudo dpkg --configure -a
Setting up mysql-server-5.7 (5.7.28-0ubuntu0.18.04.4) ...
You definitely would not want to follow these instructions if your Mysql installation had not previously completed (there's a reason that the postinstall script insists on running). But for those who might end up with dpkg in a wonky state, as I have, the above can save you a lot of time purging and reinstalling an already-working version of Mysql.
This should help
sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get dist-upgrade
And now reinstall mysql
sudo apt-get install mysql-server
If you're on a VPS or similar, your error may be due to lack of RAM.
Running apt-upgrade seems to require some RAM, so it may force-close mysql, hence the problem to recover from the error.
Try:
1) Stop mysql manually before any apt-upgrade
sudo /etc/init.d/mysql stop
2) Fix:
sudo dpkg --configure mysql-server-X.X
(if version not known, use just mysql-server to find out (will not fix error)
3) Check:
sudo apt-get upgrade
Start mysql manually if it wasn't started by apt.
I had a similar issue. This is how I fixed mine.
Restart MySQL service sudo service mysql restart
Then fix broken installations sudo apt install -f
My answer from askubuntu.
New Answer
kill the musql deamon and purging helps
sudo pkill mysqld # kill
sudo apt-get purge mysql-server-5.7 # Or whatever you are trying to purge.
Thanks, #endrias for the suggestion.
Old Answer
None of the apt methods worked for me, try this:
Find locking process
$ ps -eaf
root 7316 1 0 00:19 ? 00:00:00 /usr/bin/dpkg --status-fd 35 --configure --pending
root 7808 7316 0 00:19 ? 00:00:00 /usr/bin/perl -w /usr/share/debconf/frontend /var/lib/dpkg/info/mysql-se
root 7817 7808 0 00:19 ? 00:00:00 /bin/bash /var/lib/dpkg/info/mysql-server-5.7.postinst configure
mysql 7973 7817 0 00:20 ? 00:00:00 mysqld --user=mysql --init-file=/var/lib/mysql-files/tmp.iNyY06ty0K --so
Kill it
do sudo kill -9 7973, basically the mysql one.
Now purge
sudo apt-get purge mysql-server-5.7 # Or whatever you are trying to purge.
i face same error due to problem in my upgrade from ubuntu 18.04 to ubuntu 20.04 , what i did is get mariadb instead also make sure when you do pruge mysql that if asked you to remove dbs in the dir
tell it not to delete the dbs so you will have your old databases with no data loss
what i did was this cmds
sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get dist-upgrade
sudo apt-get install mariadb-server
I tried almost every possible way but nothing was working for me. Then I found the problem that I was facing was due to less available ram. You can check your current ram status by free -h (in my case available was less than 1 GB). To clear ram restart your device. Then type following commands
sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get dist-upgrade
then again install mysql-server by
sudo apt-get install mysql-server
try this solution using aptitude this will replace all the file corrupted.
This is work on my 18.04
cr. https://www.digitalocean.com/community/questions/mysql-installation-error-dpkg-error-processing-package-mysql-server-5-5-configure?answer=61604
In my case I had to run:
systemctl stop mysql.service
to stop MySQL before being able to install mysql without errors using:
sudo apt-get install mysql-server
To solve the dependency issue, try:
sudo apt-get purge
sudo apt-get clean
sudo apt-get check
And reinstall the package again by: sudo apt-get install mysql-server.
Source: Thread: Dpkg: Dependency problems - leaving unconfigured.
Other commands to try:
sudo apt-get install -f
sudo apt-get autoremove
sudo dpkg --configure -a
Related: How can I Resolve dpkg dependency? at Ask Ubuntu.
The problem can be much simpler (in my case) I had a missconfigured value in my configuration file [my.cnf] which lead to the error.
After cleaning up my.cnf mysql-server was restarted successfully
If you are working on Debian 10, you need to first install GNUPG:
sudo apt-get install gnupg
That's all; now you can try dpkg again.
Also pay attention to the terminal you are using, if it is ZSH many uninstall commands will not work like: sudo apt-get purge mysql* and the reinstallation process will fail, to fix this it is simple type in your terminal the word bash so that the terminal used is Bash, run the sudo apt-get purge mysql* command again and also the following commands below to confirm that you removed everything.
sudo apt-get remove mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql
Finally, run mysql --version to make sure there is no version on your machine and you can try installing again.
I came across the yes Unix binary, which is incredibly stupid: it just endlessly types y (try it, you can just run yes in your terminal)
so the following just works (I used this in a dockerfile)
yes | apt-get install mysql-community-server
I had another mysql process running in background.
(ckeck if your lampp mysql server is on, Then turn it off.)
then try
sudo apt dist-upgrade
if lammp mysql is not working then,
check this command,
ps -eaf
and then look for mysql process and kill it by it's port number
sudo kill -9
I was in the same situation. After completely removing MySQL, I reinstalled it, killed the PID using port 3306, and reinstalled MySQL again. It's working now.

Installation of MySQL 5.7 on Debian 7 Wheezy

I would like to install MySql 5.7 on Debian 7 Wheezy. I put :
deb http://repo.mysql.com/apt/debian/ wheezy mysql-5.7
in file:
/etc/apt/sources.list.d/mysql.list
Next I run commands:
sudo apt-get update
sudo apt-get upgrade
And tried install package:
sudo apt-get install mysql-server-5.7
I got an error:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'mysql-community-server' instead of 'mysql-server-5.7'
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
mysql-community-server : Depends: mysql-common (= 5.7.11-1debian7) but 5.5.47-0+deb7u1 is to be installed
Depends: mysql-client (= 5.7.11-1debian7)
E: Unable to correct problems, you have held broken packages.
Do you have any ideas to resolve this problem?
I also tried:
Note, selecting 'mysql-community-server' instead of 'mysql-server-5.7'
But it's not the solution of the problem.
I stumbled upon this post and can confirm simply changing the priority of your cache by downloading the .deb package directly from MySQL Downloads
Using the command line:
$ cd /usr/src && sudo wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
Please note: by convension the /src directory on linux exists for source code to live before being compiled - I believe the deb package above therefore belongs here.
This works for Debian/Wheezy.
$ sudo dpkg -i http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
Once this you have gone through the steps, you simply hit Ok, and then proceed to install mysql-server like normal:
$ sudo apt-update
$ sudo apt-get install mysql-server
For me, this resulted in the following:
[info] MySQL Community Server 5.7.14 is started.
Setting up mysql-server (5.7.14-1debian7) ...
Further reading, if you ever want to remove this package, you can do so:
$ cd /usr/src && sudo dpkg --remove http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
As of 2020 with Debian Wheezy 7.11 the answer doesn't work anymore. I had to change a few things and thought it might be useful to share the result:
Install mysql-apt-config_0.8.10-1_all.deb (Version 0.8.15-1_all won't work: dpkg can't handle the "control.tar.xz" it contains.)
cd /usr/src
sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb
This will create the necessary /etc/apt/sources.list.d/mysql.list file.
sudo apt-get update
sudo apt-get install mysql-server
Thanks goes to David Kehr from where I got the working mysql-apt-config version.
You don't need to specify the version in the apt-get command, just type :
sudo apt-get install mysql-server
After the install, you can type the following command to check mysql version
aptitude show mysql-server
On my machine I have the following result :
...
Version : 5.7.13-1debian7
...