Unable to setup mysql in google cloud shell - mysql

I'm trying to install mysql in a cloud engine through the cloud shell
I installed it with:
sudo apt-get -y install mysql-server
And set password with:
sudo mysql_secure_installation
when I input the password, I receive this error:
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")
How can I fix this?

As John say, Cloud shell is a container.
You should use cloud shell to login to your vm
For example, your VM name is mysql-server
gcloud compute ssh username#mysql-server
Then follow with your install setup.
Or
gcloud compute ssh username#mysql-server --command 'sudo apt-get -y install mysql-server'

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.

Trouble installing MySQL on Amazon Linux

I'm trying to install MySQL on my Amazon Linux instance following these set of commands:
(Taken from here):
wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
yum localinstall mysql57-community-release-el6-11.noarch.rpm
yum remove mysql55 mysql55-common mysql55-libs mysql55-server
yum install mysql-community-server
service mysqld restart
mysql_upgrade -p
However, when I run:
service mysqld restart
I get the following error message:
Running the same command prefixed with sudo gets the following error message:
And then running:
mysql_upgrade -p
Produces the following error message:
A little bit lost on how to tackle this problem. Any ideas?
You can use the root user to try the above operation.
If permission is still denied, then you need to focus on SELinux and AppArmor.

How to start mysql and set up the mysql root password for a docker container?

I am trying to host a web server via docker.The web server needs mysql database.But I am failing to change the root password of mysql and also start the mysql and apache2 service.
So can someone help me to set the root password and start start the services.
Here is my try to setup the docker container.
FROM ubuntu:16.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get install apache2
RUN apt-get -q -y install mysql-server
CMD service mysql start

Connect to RDS MySQL instance from ec2 Linux AMI - mysql command not found

I try to connect to my RDS MySQL instance from an SSH connection to my ec2 server (through PUTTY) as outlined here:
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToInstance.html#USER_ConnectToInstance.CLI
But I get:
-bash: mysql: command not found
I think maybe I have to install the MySQL Utility client on my ec2 linux server? If this is the case how do I do this?
I try to run the mysql command from my /home/ec2-user directory.
When using Amazon Linux 2 AMI, we need to install mysql. Use this command to install mysql on the instance:
sudo yum install mysql
And then you can connect using this command:
mysql -h change-to-your-rds-endpoint.rds.amazonaws.com -u <USER> -p
Install mysql client on AWS Linux EC2:
$ sudo yum install mysql
Connect:
$ mysql -h endpoint -P port -u masteruser -p
If you enter your password and nothing happens, check your security groups. You may need to edit your inbound rules.
First install mysql into your ec2 instace using below command
sudo apt-get install mysql-server mysql-client
After installing mysql try with below cmd to connect RDS
mysql -h hostname -u username - p password
You'll need to install MySQL. Amazon AMIs use yum instead of apt so use:
sudo yum install mysql-server mysql-client
if you are working to setup a LAMP (Linux, Apache, MySQL, PHP) server then follow these instructions http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html
Install the mysql client lib with the package manager of your system, for example on Ubuntu:
apt-get install mysqlclient

What's the correct way of installing MySQL on CentOS 6.6 on Compute Engine by Google?

I've been trying to install MySQL on CentOS 6.6 but with no good results. I have just created a new VM with these steps:
1.- sudo yum -y install mysql-server mysql
2.- sudo mysql -u root
RESULT .- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
also doing a "sudo service mysql start"
RESULT mysql: unrecognized service
Thanks mates !
Try
sudo /etc/init.d/mysqld start
or
sudo service mysqld start