I can't use MySQL in Windows Linux Subsystem - mysql

I entered Windows Linux Subsystem with:
C:\> bash --login
Installed MySQL as follows:
$ sudo apt-get install libmysqlclient-dev
$ sudo apt-get install mysql-server
$ sudo apt-get install mysql-client
When I try the following:
$ sudo mysql -u root
I get:
Error 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

use like:
mysql --host=127.0.0.1 --user=root --password=root

I believe the mysql service isn't running. You can start it with:
sudo /etc/init.d/mysql start

Use TCP/IP connection instead as shown below:
mysql --protocol=tcp -uroot -ppassword

I had the same issue and found that this works for me:
mysqladmin -u root password "<enter_new_password>";
mysql -u root -p
This will prompt you with the password you created

Related

How to set up root password while installing mysql in docker?

I am trying to install mysql in docker and setting default password of root as root using following Dockerfile.
Dockerfile:
FROM ubuntu:20.04
COPY mysql_setup.sh /software/mysql_setup.sh
RUN sh /software/mysql_setup.sh
CMD ["/bin/sh"]
Where /software/mysql_setup.sh
# Download and Install the Latest Updates for the OS
apt-get update && apt-get upgrade -y
# Set the Server Timezone to CST
echo "America/Chicago" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
# Enable Ubuntu Firewall and allow SSH & MySQL Ports
ufw enable
ufw allow 22
ufw allow 3306
# Install essential packages
apt-get -y install zsh htop
# Install MySQL Server in a Non-Interactive mode. Default root password will be "root"
echo "mysql-server mysql-server-8.0.26/root_password password root" | sudo debconf-set-selections
echo "mysql-server mysql-server-8.0.26/root_password_again password root" | sudo debconf-set-selections
apt-get -y install mysql-server
# Run the MySQL Secure Installation wizard
mysql_secure_installation
sed -i 's/127\.0\.0\.1/0\.0\.0\.0/g' /etc/mysql/my.cnf
mysql -uroot -p -e 'USE mysql; UPDATE `user` SET `Host`="%" WHERE `User`="root" AND `Host`="localhost"; DELETE FROM `user` WHERE `Host` != "%" AND `User`="root"; FLUSH PRIVILEGES;'
service mysql restart
But above code does not seem to be working as when i enter into docker and use and use root as password it gives an error.
root#839f2946bfdf:/# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
How can i fix this error?
You cannot run a mysql install inside a container in a normal way. Thing like ufw cannot be done. The entire RUN step is at build time only, so service mysql restart won't be running when the container is started, only CMD is.
Recommend just using the Docker Library mysql container. There's a standard MYSQL_ROOT_PASSWORD variable for setting the root password.

Reset the root password in mysql in Ubuntu 18.04 OS

ok here's the thing I tried installing MySQL-server and it did install perfectly no problem there.
later I had had to format my system and then when I tried to install it, it did install but it did not prompt for the root password. when I later tried to reset the root password here's the problem I get
user#user:~$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
user#user:~$ sudo mysqld --skip-grant-tables &
[3] 13831
user#user:~$ mysql -u root -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
[3] Exit 1 sudo mysqld --skip-grant-tables
I tried resolving the 2002 error but I am unable to do so. any help will be appreciated.
from what I understand I should not get the 2002 error to proceed further
The error is probably due to error in installation. Try the following:
Ensure that my MySQL service is running by executing the following command in the terminal:
$ sudo service mysql start
Verify the state of the process:
$ ps -A|grep mysql
$ ps -A|grep mysqld
Then kill the process with the following command:
$ sudo pkill mysql
$ sudo pkill mysqld
Finally restart the service:
$ sudo service mysql restart
And run the following command:
$ mysql -u root -p
Step#1: Run this command:
sudo mysql_secure_installation
Step#2: press n
Step#3: input your password.
Step#4: press y for until it says All done!
or follow this video tutorial
Also to change the password use this command:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';

MySQL daemon command line login hangs

I have MySQL restarted on Ubuntu (Version 16), and the login command hangs for unknown reasons.
ubuntu#ip-172-31-12-122:~$ sudo /etc/init.d/mysql restart
[ ok ] Restarting mysql (via systemctl): mysql.service.
ubuntu#ip-172-31-12-122:~$
ubuntu#ip-172-31-12-122:~$
ubuntu#ip-172-31-12-122:~$ sudo mysqld -u root -p
It looks like you are starting a new instance of the server in the foreground ?
sudo mysqld -u root -p
https://dev.mysql.com/doc/refman/5.7/en/server-options.html
If you want to login to your running instance
mysql -u root -p
https://dev.mysql.com/doc/refman/5.7/en/mysql.html

"ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)" getting this on aws linux (centos)

I'm trying to install mysql for the first time on aws linux instance running the following commands
sudo yum install mysql-server
sudo mysql_secure_installation
As soon as I run the second command I get
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Enter current password for root (enter for none):
And I haven't even set my root password. How am I supposed to enter a password which I haven't set in the first place?
----List installed mysql
sudo yum list installed | grep mysql
----Remove all
sudo yum remove mysql-client mysql-server mysql-common mysql-devel
delete some conf files manually :
sudo rm -rf /var/lib/mysql/
sudo rm -rf /etc/my.cnf
Try to reinstall
sudo yum install mysql mysql-server
get the autogenerated password
sudo grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
use the autogen password
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass4!';
Hope it solve your problem .
https://dev.mysql.com/doc/mysql-installation-excerpt/5.7/en/linux-installation-yum-repo.html

Accesing LAMPP mysql via the command line on linux

I've have installed LAMPP, I need to access MySQL from the terminal but I dont know how, because if I simply type mysql into the prompt it says the mysql program is not installed, but it has to be installed because it stands for Linux + Apache + MySQL + PHP + Perl. Thank
My solution:
sudo /opt/lampp/lampp status
sudo /opt/lampp/lampp startmysql
sudo /opt/lampp/lampp status
cd /opt/lampp/bin
./mysql -h localhost test
On my system this solved my problem
sudo /opt/lampp/lampp startmysql
/opt/lampp/bin/mysql -u username
For Bitnami LAMP stack
/opt/lampstack-7.1.23-0/mysql/bin/mysql -u root -p
A good start would be to run which mysql to locate the binary and check if it is actually installed. If it is missing try re-installing.