Cannot connect to Database server through mysqlworkbench - mysql

All of the sudden, I can't connect to the mysql service instance setup in MWB. I get this error:
Failed to Connect to MySQL at localhost:3306 with user root Unknown
MySQL server host 'localhost' (0)
I can start and stop the server through the MySql system preferences. I can also log into the server through the command line:
mysql -u root -p -h 127.0.0.1 -P 3306
Any ideas how to fix this? The following had to effect:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
"password" is currently the root user password.

Related

How to change MySQL root password via a file?

How do I change the MySQL root password in ubuntu server via a file?
The file may be any shell script or normal text file.
My try:
Normally the below command, in the terminal, changes the password for newly installed mysql.
mysqladmin -u root password 'newpass'
But while doing it via file it's showing the bellow error.
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: NO)'
So can someone help me to do so.
Stop the MySQL Server: sudo /etc/init.d/mysql stop
Start the mysqld configuration: sudo mysqld --skip-grant-tables
Login to MySQL as root: mysql -u root mysql
Replace YOURNEWPASSWORD with your new password:
UPDATE
mysql.user
SET
Password = PASSWORD('YOURNEWPASSWORD')
WHERE
User = 'root';
FLUSH PRIVILEGES;
exit;
Note: This method is not regarded as the most secure way of resetting the password, however, it works.
If you have never assigned a root password for MySQL, the server does not require a password at all for connecting as root follow :
Resetting Permissions

Not connecting to MySQL remotely

I've been trying to connect to my MySQL Server remotely and not getting any success. The terminal gets stuck and neither gives me an error message. If I insert the password wrong I get ERROR 1045 (28000): Access denied for user, so I believe MySQL/Server are getting my connection. Locally in the server I can connect with the same user without any issues.
I am connecting to an AWS Ubuntu 16.04, and got the same problem at Azure Debian 8.
Here are the steps I've taken so far:
Commented out #bind-address at /etc/mysql/mysql.conf.d/mysqld.cnf
Ran sudo ufw allow 'MySQL' and sudo ufw allow 'MySQLServer'
Allowed Inbound connection at port 3306
Ran iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
lsof -Pni :3306 returns
mysqld 12118 mysql 16u IPv6 38112 0t0 TCP *:3306 (LISTEN)
Create user with
CREATE USER 'user'#'localhost' IDENTIFIED BY 'password';
CREATE USER 'user'#'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'user'#'localhost';
GRANT ALL PRIVILEGES ON * . * TO 'user'#'%';
FLUSH PRIVILEGES;
When connecting I'm running mysql -h xxx.xxx.xxx.xxx -u user -ppassword
and the terminal process "freezes".
If anyone can help please.
Instead of commenting out bind-address, change it to:
bind-address = 0.0.0.0
And also drop the -ppassword and make it just -p, that errors out by default.
I was able to connect to a MySQL instance running on an Ubuntu 16.04 server on AWS after following the same steps you followed with that single difference.

Mysql client doesn't connect to external server

I'm trying to connect to external mysql server through linux command line.
Whe I try for example:
mysql -h 102.235.10.77 -u root -p password
it gives the next error:
ERROR 1045 (28000): Access denied for user 'root'#'190.201.179.249' (using password: NO)
Where 190.201.179.249 How you can see isn't the external server IP if not my local IP.
I already check out external connections at MySQL Server and 3306 port too, it Seems it's a local problem as if I can't connect to another IP than localhost.
regards.

Stopping MySQL Server from command line on Windows 7

I am trying to shutdown the mysql server from command line.
MySQL root password is "" (blank)
C:\Users\Jigar>"C:\mysql\bin\mysqladmin.exe" -u root -p shutdown
Enter password:
When I just press enter, it stops the server.
But when I don't specify -p, I am not able to stop the server:
C:\Users\Jigar>"C:\mysql\bin\mysqladmin.exe" -u root shutdown
C:\mysql\bin\mysqladmin.exe: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: YES)'
I am actually writing a program to stop the server. In mac I was able to stop the server with blank root password without specifying -p in the command. But I am not able to do the same in Windows.

MYSQL can't start service on Windows 7

EDIT: This happened most of the times, due to power failure.
Two things which worked for me.
1. Knowing how to change root password in MySQL, and taking backup of databases.
2. Install MYSQL as service.
C:\> "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld" --install
I had done clean installation of MYSQL 5.6 few days ago.
On first day everythng was fine. I could access city and world tables.
On next day I started getting below errors. Some were I read to run mysqld at admin level.
And it solved problem, but I couldn't access city and world table anymore.
On third day. I am getting only this errors.
Note: MYSQL service running previously fine, when firewall, antivirus (avast) and apache was running.
When run on admin mode :
C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root -p localhost
Enter password: ***********
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root -p localhost
Enter password: *
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root -p localhost
Enter password:
ERROR 1049 (42000): Unknown database 'localhost'
When run on user mode (who is admin also) :
C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root -p localhost
Enter password: ***********
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root -p localhost
Enter password: *
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root -p localhost
Enter password:
ERROR 1049 (42000): Unknown database 'localhost'
Not able to start MYSQL Service from Control Panel\All Control Panel Items\Administrative Tools\Service
Error Message ; WIndows could not start the MYSQL56 service on Local Computer
Error 1067 THe process terminated unexpectedly
Regards : Msinfo
You need to use "-h" before "localhost" if you want to specify a host, otherwise just remove "localhost" and it should work fine, considering a running server on your system.
Also, MySQL server is "mysqld.exe" not "mysql.exe". mysqld (d stands for daemon) is the server which should run in background and does the actual stuff like creating tables,DBs etc. But mysql.exe just connects to the server and helps you to execute SQL queries. mysql.exe is just an interface to connect to server. If you want to know why your server (windows service in your case) is not starting, you should see the XXX.log in your MySQL server installation folder under Program Files.
try by creating the database in MySql by the respective name "localhost"
eg: create database localhost;
by doing this you can clear the below error
ERROR 1049 (42000): Unknown database 'localhost'
hope i am correct
Thanks,
Daya