MySQL daemon command line login hangs - mysql

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

Related

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 won't start in XAMPP Manager-osx

My XAMPP mysql server is working fine
then I download the separate mysql from oracle and installed it. It is running fine but after some days I cant start it as :> mysql -u root
and in xampp mysql server it is also not working it shows stopped always.
I am providing all the commands that I tried from google as well as StackOverflow
and also I am providing all results of all commands.
Please refer commands before answering.
Number indicates ways that I tried.
1.> `mysql -u root -p`
2.> `mysql -u root`
3.> `sudo su`
3.1.> `ps aux | grep mysql`
3.2.> `kill -9 8306`
4.> `sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start`
5.> `sudo killall mysqld`
6.> Changing content of file as: `innodb_force_recovery = 1` in
`/Applications/XAMPP/xamppfiles/etc/my.cnf`
7.> Changing content of file as: read only permission in
`/Applications/XAMPP/xamppfiles/etc/my.cnf`
8.> Port changed from 3306 to 3307 3308 but nothing is happened
9.> Activity manager : mysql service is. not listed
10.> Reinstalled XAMPP
I followed this 10 ways so please dont answer on this 10 ways
Result of commands :
<.1.
Pratiks-MacBook-Pro:~ pratik$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2 "No such file or directory")
<.2.
Pratiks-MacBook-Pro:~ pratik$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2 "No such file or directory")
<.3.
Pratiks-MacBook-Pro:~ pratik$ sudo su
Password:
sh-3.2# ps aux | grep mysql
root 8306 0.0 0.0 4258468 180 s000 U+ 11:35AM 0:00.00 grep mysql
sh-3.2# kill -9 8306
sh: kill: (8306) - No such process
sh-3.2#
<.4.
Pratiks-MacBook-Pro:~ pratik$ sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
Starting MySQL
.2018-03-13 11:44:29 8513 mysqld_safe Logging to '/Applications/XAMPP/xamppfiles/var/mysql/Pratiks-MacBook-Pro.local.err'.
2018-03-13 11:44:29 8513 mysqld_safe Starting mysqld daemon with databases from /Applications/XAMPP/xamppfiles/var/mysql
ERROR!
<.5.
Pratiks-MacBook-Pro:~ pratik$ sudo killall mysqld
No matching processes were found

I can't use MySQL in Windows Linux Subsystem

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

Error when creating a MySQL database in a Dockerfile

I want to create a simple container that contains a MySQL server with an initialized database. My Dockerfile currently looks like this:
FROM ubuntu:16.10
RUN apt-get update
# install MySQL; root user with no password
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get install -y mysql-server mysql-client
RUN service mysql start
RUN mysqladmin -u root create mydb
CMD [ "bash" ]
However, when I build the image via docker build -t mysql-test . I get the following error:
Step 7 : RUN mysqladmin -u root create mydb
---> Running in a35c3d176d4f
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
The command '/bin/sh -c mysqladmin -u root create mydb' returned a non-zero code: 1
When I comment the line where I want to create the database (RUN mysqladmin -u root create mydb) I can build the image, start it, and execute the mysqladmin command from the command line:
# this works
> docker run -it mysql-test
root#...> service mysql start
root#...> mysqladmin -u root create mydb
Why do I get the error when creating the database in the Dockerfile? Thank you!
Reading the documentation of the RUN instruction makes it clear:
The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.
So each run instruction creates a new image and starting the MySQL server and creating the database should be combined in the same RUN instruction:
RUN service mysql start && mysqladmin -u root create mydb
This solves it.

mysql command not found

I recently installed MySQL on RHEL5. I installed it to /usr/local/mysql
Complete steps for installation are here
http://dev.mysql.com/doc/refman/5.1/en/binary-installation.html
shell> cp support-files/mysql.server /etc/init.d/mysql.server
Then I could not start it from /usr/local/mysql/support-files/mysql.server start command
Now I can stop and start MySQL using the below command
/etc/init.d/mysql start
/etc/init.d/mysql stop
To create database here are the first step
mysql -u root -h localhost
I get command not found from anywhere I run. What should I try?