Unable to set password error while Mysql Data Migration - mysql

I am trying to migrate mysql databases from one server to another. I am following these steps for the migration (270GB of data including databases and users in datadir):
sudo service mysql stop
sudo apt-get purge mysql-server-5.5 mysql-common
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql
sudo ln -s <path to datadir>/mysql /var/lib/mysql
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.5
This asks for root password, which I try to set accordingly. However, I am getting the following response:
Configuring mysql-server-5.5
Unable to set password for the MySQL "root" user
An error occurred while setting the password for the MySQL administrative
user. This may have happened because the account already has a password, or
because of a communication problem with the MySQL server.
You should check the account's password after the package installation.
Please read the /usr/share/doc/mysql-server-5.5/README.Debian file for more
information.
Note that I followed the same steps on another ubuntu server (dev) based on the same AMI and was successful in doing the setup. The only variable between the two is data.
I cannot afford much downtime, and therefore using rsync for data replication.
I know that both the ubuntu and mysql versions are old, but this migration is necessary and has strict deadlines.

The solution here was pretty simple.
Rebooting the ubuntu server after following the steps to purge mysql* worked for me. Steps:
sudo service mysql stop
sudo apt-get purge mysql-server-5.5 mysql-common
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql
sudo ln -s <path to datadir>/mysql /var/lib/mysql
sudo apt-get clean
sudo apt-get purge mysql*
Reboot the ubuntu machine.
Then:
sudo apt-get update
sudo apt-get install -f
sudo apt-get install mysql-server-5.5

Related

undo mysql uninstallation on ubuntu server

I Accidentally deleted mysql on wrong server, need to undo it
Command I ran were
sudo -i
service mysql stop
killall -KILL mysql mysqld_safe mysqld
apt-get --yes purge mysql-server mysql-client
apt-get --yes autoremove --purge
apt-get autoclean
deluser --remove-home mysql
delgroup mysql
rm -rf /etc/apparmor.d/abstractions/mysql /etc/apparmor.d/cache/usr.sbin.mysqld /etc/mysql /var/lib/mysql /var/log/mysql* /var/log/upstart/mysql.log* /var/run/mysqld
updatedb
exit

Why is mysql asking for password after default installation as root

I see this when I ssh to my Ubuntu server:
Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-1018-aws x86_64)
After installing mysql, I try to login to the mysql server but for some reason it asks me for a password that I do not have. So, I ran the following commands to uninstall mysql and reinstall.
Uninstall
sudo apt-get remove --purge mysql*
sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get remove dbconfig-mysql
sudo apt-get dist-upgrade
The I used this link as guide to install mysql, and the commands went as follows:
sudo apt update
sudo apt install mysql-server
sudo systemctl start mysql.service
When I run:
sudo mysql_secure_installation
The prompt asks me to “Enter password for the user root”. Where do I find this password?
The idea of the command is to set the password.
How can I install mysql in this server to then be able to manage my databases?

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.

mysql - installing or upgrading mysql 5.5 to 5.6 in Linux mint

Following error message getting while upgrading from Mysql 5.5 to 5.6.
The following packages have unmet dependencies:
mysql-client-5.6 : Depends: mysql-client-core-5.6 but it is not going to be installed
mysql-server-5.6 : Depends: mysql-server-core-5.6 (=
5.6.19-0ubuntu0.14.04.1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
I had the same problem which was solved after update and upgrade.
Try this, I hope this works for you:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install mysql-server-5.6
Installing MySQL 5.6 on Linux(debian based distro):
Uninstall any existing version of MySQL:
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
Automatically uninstall mysql:
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor
Download version 5.5.51 from MySQL site
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz
Add mysql user group:
sudo groupadd mysql
Add mysql (not the current user) to mysql user group:
sudo useradd -g mysql mysql
Extract mysql-5.6.*-linux2.6-x86_64.tar.gz to /usr/local:
cd /usr/local
sudo tar -xvf mysql-5.6.*-linux2.6-x86_64.tar.gz
Create mysql folder in /usr/local:
sudo mv mysql-5.6.*-linux2.6-x86_64 mysql
Set mysql directory owner and user group:
cd mysql
**sudo chown -R mysql:mysql * **
Install the required lib package:
sudo apt-get install libaio1
Execute mysql installation script:
sudo scripts/mysql_install_db --user=mysql
Set mysql directory owner from outside the mysql directory:
sudo chown -R root .
Set data directory owner from inside mysql directory:
sudo chown -R mysql data
Copy the mysql configuration file :
sudo cp support-files/my-medium.cnf /etc/my.cnf
Start mysql:
sudo bin/mysqld_safe --user=mysql &
sudo cp support-files/mysql.server /etc/init.d/mysql.server
Initialize root user password:
sudo bin/mysqladmin -u root password 'test'
Start mysql server:
sudo /etc/init.d/mysql.server start
Stop mysql server
sudo /etc/init.d/mysql.server stop
Check status of mysql:
sudo /etc/init.d/mysql.server status
Enable myql on startup:
sudo update-rc.d -f mysql.server defaults
Add mysql path to the system:
sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
Now directly use the command below to start mysql
mysql -u root -p

Error while installing MYSQL

I was trying to install mysql in ubuntu. I applied following command for it
sudo apt-get install mysql-server-5.5
But got the following error.
Errors were encountered while processing:
/var/cache/apt/archives/mysql-server-5.5_5.5.41-0ubuntu0.14.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
Please help me to solve the error.
Doing this solved it for me:
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-5.5 mysql-server-core-5.5
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get install mysql-server
seems like there's an error with one of the packages being installed or that quite never installed properly in the past.
http://ubuntuforums.org/showthread.php?t=1642173
here is a link that helps identify the package and how to correct it.
Try given commands.
sudo apt-get purge mysql-client-core-5.6
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get install mysql-client-core-5.5
sudo apt-get install mysql-server
Try this link
I had this problem And with this method, the problem was solved
1-Get the list of MySQL packages installed on the system by executing the command
sudo dpkg -l | grep mysql
2-Remove the the packages shown above by executing the command
sudo apt-get --purge autoremove <packages from the step 1>
3-Delete /var/lib/mysql
4-To add MariaDB repository to Ubuntu, run the commands below to install the repository key to your system.
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
5-
sudo sh -c "echo 'deb [arch=amd64,i386] https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu '$(lsb_release -cs)' main' > /etc/apt/sources.list.d/MariaDB-10.2.list"
6-After that, run the commands below to install the latest version of MariaDB.
sudo apt-get update
sudo apt-get install mariadb-server mariadb-client
7-
cd /var/run
sudo cp mysqld/ mysqld.bc -rf
sudo chown mysql:mysql mysqld.bc/
sudo service mysql stop
sudo cp mysqld.bc/ mysqld -rf
sudo chown mysql:mysql mysqld -R
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
8-Now able to log in database using
mysql -u root
9-Then to update root password:
UPDATE user SET authentication_string=password('YOURPASSWORDHERE') WHERE user='root';
FLUSH PRIVILEGES;