root user "locked" phpmyadmin in localhost - mysql

in localhost i have mistakenly click on "lock" option of "root" user of phpmyadmin then im getting " mysqli::real_connect(): (HY000/4151): Access denied, this account is locked" issue while trying to connect "localhost/phpmyadmin" again! how can i resolve this issue?
Thanks
I have tried by changing "user" "password" "hostname" in "config.inc.php" file but nothing works!
how can i resolve this issue?

If you are running MySQL on a Mac or Linux variant , depending on which account is locked, you may still be able to connect with sudo mysql. If so, you can run the UPDATE query (further down) to unlock the root account. You will need to run FLUSH PRIVILEGES; or restart MySQL service for the change to take effect.
If that does not work, or you are on Windows, you can use skip-grant-tables to start the service with the authentication disabled. The location of the relevant configuration file varies with version and OS.
Typical location of configuration file for MySQL 8.0 on Windows -
C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
MySQL on many Linux variants will check for -
/etc/my.cnf
If it does not exist check the typical location for your Linux variant. Add the skip-grant-tables option in the mysqld section -
[mysqld]
skip-grant-tables
Now you need to restart the MySQL service -
# On Windows (cmd as admin)
net stop MYSQL80
net start MYSQL80
# or PowerShell as admin
Restart-Service -Name MYSQL80
# On Linux
sudo service mysql restart
You should now be able to connect to MySQL without needing credentials, and you can pass the UPDATE query in directly with --execute or -e.
mysql -e "UPDATE `mysql`.`user` SET `account_locked` = 'N' WHERE `User` = 'root';"
And now you can reverse the configuration changes made above and restart MySQL service again.

Related

Cannot connect to MySQL installed on GCP Virtual Machine

I've installed MySQL on a Google Cloud Virtual Machine (debian buster). What I want to do is to make this accessible publicly (using username / password obviously).
As far as I can tell the server is visible from the outside world, as I can ping the IP and I get results, and I think I've set up a user correctly and given the appropriate permissions so I can log in.
For info, my firewall settings on GCP look like this (this is just the egress, there is one exactly the same for ingress):
Which I'm assuming is correct and leaves the correct port open?
The issue I have when I use MySQL Workbench is that when I try to create a new connection, it gives me the following error:
Your connection attempt failed for user 'username' to the MySQL server at [my ip address]:3306:
Unable to connect to localhost
Please:
1 Check that MySQL is running on address [my ip address]
2 Check that MySQL is reachable on port 3306 (note: 3306 is the default, but this can be changed)
3 Check the user username has rights to connect to [my ip address] from your address (MySQL rights define what clients can connect to the server and from which machines)
4 Make sure you are both providing a password if needed and using the correct password for [my ip address] connecting from the host address you're connecting from**
Any pointers would be gratefully received.
Update: What is really confusing me is the 'Unable to connect to localhost' error. I'm not trying to connect to localhost...?
Update 2: As per comments, results of the following commands:
Note I am trying to connect using the matprichardson username. The svc2toria user is pointing to my own IP address.
Mat, If you want to use your Google Cloud Instance Database using your MySQL workbench. I suggest you connect to it through an SSH tunnel. So, this problem won't happen. I also ran into this problem several times. Connecting through SSH made the job done.
But if your need is something else, this would not help you at all. If your only purpose is managing your database from your local machine using the MySQL workbench. This will work nicely. Create a USER in your Debian VM. and open port 22 to the public. Also, make sure to have strong credentials or a better key file when connecting through SSH. This method is working for every cloud VM database. I'm using this method for G-Cloud, Azure, and AWS. After all of your work is done. Close port 22 (SSH).
My best guess will be because of number 2. "Check that MySQL is reachable on port 3306 (note: 3306 is the default, but this can be changed)".
Your Virtual Machine will have network security controls / firewall which will be blocking port 3306 by default.
I don't use Google cloud but I believe you are looking for "network details" -> "Firewall rules".
did you change your mysqld.cnf already?
bind-address = 0.0.0.0
As none of the suggestions posted worked I went for the rather more nuclear option of deleting and rebuilding my VM and setting MySQL up again from scratch. I must have done something wrong in my initial setup, as things worked without any issues at all once I’d done this.
The location of the MySQL configuration file differs depending on the distribution.
In Ubuntu and Debian the file is located at /etc/mysql/mysql.conf.d/mysqld.cnf
while in Red Hat based distributions such as CentOS, the file is located at /etc/my.cnf
Open the file with your text editor :
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Search for a line that begins with bind-address and set its value to the IP address on which a MySQL server should listen.
By default, the value is set to 127.0.0.1 (listens only in localhost).
In this example, we’ll set the MySQL server to listen on all IPv4 interfaces by changing the value to 0.0.0.0
bind-address = 0.0.0.0
# skip-networking
If there is a line containing skip-networking, delete it or comment it out by adding # at the beginning of the line.
In MySQL 8.0 and higher, the bind-address directive may not be present. In this case, add it under the [mysqld] section.
Once done, restart the MySQL service for changes to take effect. Only root or users with sudo privileges can restart services.
To restart the MySQL service on Debian or Ubuntu, type:
sudo systemctl restart mysql
On RedHat based distributions like CentOS to restart the service run:
sudo systemctl restart mysqld
For more Detail Read Here

No able to connect remote mysql database

I'm trying to connect on my mysql database when I'm not on localhost - on localhost it's working. Everytime I wish to connect, I don't have any error, but only a timeout exec...
Here is what I've done so far
create a user on mysql who can access to any hosts("%")
purge the iptables
my port 3306 is opened (see screenshot)
the bind-address line is 0.0.0.0 in the mysqld.cnf file - I even tried to put in it comment - please note my.cnf sends to the mysqld.cnf file.
of course for every modification I've restarted the mysql server - and the server itself...
no firewall are setup...
I'm on Ubuntu 16.04 LTS, mysql and phpmyadmin are setup on it.
What I'm missing ?
Thank you for your help
Bastien
After you changed the bind address you restarted with systemctl restart mysql.service, yes?
Here's a very similar situation, try following all of these steps: Remote Connections Mysql Ubuntu
I think the flush privileges step will be a help to you.

Failed to Connect to MySQL at localhost:3306 with user root

I use Mysql Workbench to connect my database,[
Hostname Port and Username are as shown in figure ,and password is right.When I click Test Connection ,it show as above.But if i use 3307 in place of 3306 as port,it connect sucessfully. What matter lead that and how I fix it?
I use macbook pro and I don't know check which my.cnf. I use sudo vim /usr/local/mysql/my.cnf in terminal .
And the my.cnf is as below:
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
And I rewite it as below:
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M
[mysqldump]
quick
But it does not work.
Steps:
1 - Right click on your task bar -->Start Task Manager
2 - Click on Services button (at bottom).
3 - Search for MYSQL57
4 - Right Click on MYSQL57 --> Start
Now again start your mysql-cmd-prompt or MYSQL WorkBench
Open System Preference > MySQL > Initialize Database > Use Legacy Password Encription
I had this exact problem after my last windows update and none of the above solutions worked. I know it's an old question, but if anyone has this problem in the future:
I managed to solve it by going to windows control panel > administrative tools > Component Services and finding "MySQL57" in the Services(local) list (I assume your server might have a slightly different name).
There I went to properties by right clicking and changed the Startup Type to Automatic under the General tab. Then I went on the Log On tab and checked "Allow Service to interact with Desktop".
If none of that works, you can try checking the "This account" box and filling both password fields with the root password you set up after installing the server (leave account blank).
I know it's a lot to do and most of these steps must be innefective, but I did it all at once and frankly have no clue which one solved the problem. Good luck I hope it helps.
Try to execute below command in your terminal :
mysql -h localhost -P 3306 -u root -p
If you successfully connect to your database, then same thing has to happen with Mysql Workbench.
If you are unable to connect then I think 3306 port is acquired by another process.
Find which process running on 3306 port. If required, give admin privileges using sudo.
netstat -lnp | grep 3306
Kill/stop that process and restart your MySQL server. You are good to go.
Execute below command to find my.cnf file in macbook.
mysql --help | grep cnf
You can change MySQL port to any available port in your system. But after that, make sure you restart MySQL server.
It worked for me this way:
Step1: Open System Preference > MySQL > Initialize Database.
Step2: Put password you used while installing MySQL.
Step3: Start MySQL server.
Step4: Come back to MySQL Workbench and double connect/ create a new one.
Go to system preferences, then "MySQL".
Click on "Start MySQL Server".
MySQL default port is 3306 but it may be unavailable for some reasons, try to restart your machine. Also sesrch for your MySQL configuration file (should be called "my.cnf") and check if the used port is 3306 or 3307, if is 3307 you can change it to 3306 and then reboot your MySQL server.
Go to >system preferences >mysql >initialize database
-Change password
-Click use legacy password
-Click start sql server
it should work now
At rigth side in Navigator -> Instance-> Click on Startup/Shutdown -> Click on Start Server
It will work surely
go to apple icon on the top left corn and click "System Preference"
find "Mysql" at the bottom and click it
"start Mysql server"
It failed because there is no server install on your computer. You need to Download 'MySQL Community Server 8.0.17' & restart your server.
set root user to mysql_native_password
$ sudo mysql -u root -p # I had to use "sudo" since is new installation
mysql:~ USE mysql;
mysql:~ SELECT User, Host, plugin FROM mysql.user;
mysql:~ UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql:~ FLUSH PRIVILEGES;
mysql:~ exit;
$ service mysql restart
I got the same problem on MACOS. I did the following. Make sure MySQL Server is installed.
Command + Space -> Type mysql. Open the option mysql.prefPane
Click on the button Stop MySQL Server. Let the server stop.
Click on Initialize Database button
A new Popup will open. Type the password you want for root user.
Once the password is long enough, OK button will get enabled. Click on OK button
Do Test Connection from MySQL WorkBench and enter the password you set in above step. It should work.
For those of you getting this on an SQL Server container on docker, when you do the run command, be sure you put -p 3306:3306 so for example, my run command looks like docker run --name test-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=your_password -d mysql
I re-downloaded many times and found out it's so simple!
THERE ARE TWO DOWNLOADS NEEDED
1. SQL Community Server
https://dev.mysql.com/downloads/mysql/
This is what shows up in "System Preferences" and allows you to start the instance!
2. MYSQL Workbench
https://dev.mysql.com/downloads/workbench/
This is what you're trying to fix.. Once the Instance is on you can successfully connect :)
(for macOS system users)
On window, work for me.
1 - Open "Service"
2 - Search for MYSQL
3 - Right Click on MYSQL80 --> Start
Hope it work in your MySQL Workbench
Thank you!!!

Cannot login to MySQL when MySQL service is running

I can't login to MySQL when the service is running. But when I stop the service and run MySQL via executing "C:\\Program Files\\MySQL\\MySQL Server 5.6\\bin\\mysqld.exe" in CMD, I can login to MySQL via phpmyadmin but there's no database there (except the default databases)
When the service is running I can't login via phpmyadmin or MySQL CMD.
I tried to reset my password using this article but it didn't work.
The problem comes from lack of --defaults-file when I'm resetting my password. (or wrong path of the file since I tried to run my command with and without this option) I found the path of defaults-file and by adding this to mysqld and resetting password the problem solved.

Linking MySQL Workbench to my Remote Server

I've just downloaded MySQL Workbench.
But I don't quite understand how to syn this with the databases on my remote server.
Work bench asks for "hostname" so I provided the hostname of my remote server. I designate port 3306.
I then provide a username. This is the username I use when I log into PhpAdmin -- should I be using a different one?
Then I provide a password, again the same one I use for PhpAdmin.
But this doesn't work.
Oddly, the error always tells me my user name is: username#current_network_im_using_to_access_the_internet
But this doesn't seem right -- on phpAdmin my user name says username#localhost.
I'm not quite sure what to do.
Can you help me?
MySQL treats logins as specific to the host they originate from. You can have a different password from your home machine than the one you use on the server itself, and you can have entirely different sets of permissions granted to the same username from different origin hosts.
On PHPMyadmin, the database is running on the same server as the web server, and therefore refers to itself as localhost, with IP 127.0.0.1. Your machine on which Workbench is installed must access MySQL with different credentials than your username#localhost. The server requires you to grant access to your username from any host you intend to connect from.
In PhpMyAdmin, you will need to grant access to your database from the remote host: (See also Pekka's answer for how to allow connections from any host)
GRANT ALL PRIVILEGES on dbname.* TO yourusername#your_remote_hostname IDENTIFIED BY 'yourpassword';
To see all the grants you currently have on localhost so that you can duplicate them for the remote host:
SHOW GRANTS FOR yourusername#localhost;
Additionally, the MySQL server needs to be setup to accept remote connections in the first place. This isn't always the case, especially on web hosting platforms. In the my.cnf file, the skip-networking line has to be removed or commented out. If there is no skip-networking line, you must comment out the line:
bind-address = 127.0.0.1
...then restart MySQL.
Your phpMyAdmin seems to run on the same server as the database itself.
Therefore, it can use username#localhost to connect to the server.
You would need to make mySQL accept connections from outside localhost by adding another user username#% (% meaning "any host").
Note however that this is not good practice - if you have a static IP, consider limiting access to that one address.
If you are planning to use MySQL workbench for managing MySQL databases and tables in a remote server, I am recommending connect over SSH. by following many articles and forums I tried many other ways by adding bind-address, adding a new user to MySql with uname#host with all privileges, etc. but in my case, all those steps were wasting of time, those steps will be useful if your server is so strict.
Follow the steps below.
Click on the + button beside the MySql connections Title to add a new connection.
Enter Connection Name(Whatever you need).
Select connection method Standard TCP/IP over SSH.
Enter the SSH details like Host(IP/Domain), Username, and Password. (SSH using Password Authorisation should be enabled in server)
MySQL host details like Hostname(By Default localhost or 127.0.0.1), port(3306), MySQL username and password.
Then click on test connection.
To get connected to MySQL Workbench installed on Windows 10, I found the above post written by Shihab and edited by Dharman useful to get connected instantly. But, here are the things that I did to connect via TCP/IP which was also useful for me to connect to MySQL via my code:
Step 1:Changing the bind address in MyMySQL
On the Ubuntu machine (where my MySQL Community Server is installed) using Putty, I changed the mysqld.cnf file with the command "sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf". Using arrow keys, I scrolled down to the row with "bind-address" and I changed it from "127.0.0.1" to "0.0.0.0". I used ctrl+x to close and entered "Y" to save the file.
Step 2: Restart the MySQL Server
You have to restart the MySQL server. To do that, you can restart using the command "sudo service mysql restart". If you are unable to restart, kill MySQL Process. First find the Process ID of MySQL using "ps ax | grep mysql" then kill the process using "sudo kill [process_id]"
Step 3:Changing the Firewall Settings of Ubuntu
To allow outside connections, you should change the settings of the firewall. I used UFW (Uncomplicated FireWall) to change the settings. Start the UFW if it is not yet enabled using the command "sudo ufw enable". Check the status using "sudo ufw status". Now, enable connections to the MySql port 3306 (default) from a particular IP address using the command "sudo ufw allow from [ip_address] to any port 3306" or you can allow all connections to the port from any IP address is your IP address keeps changing using the command "sudo ufw allow mysql"
Step 4: Creating a user in MySQL
I created a user in MySQL to avoid logging in using the root using the command "CREATE USER 'user_name'#'your_IP_Address' IDENTIFIED BY 'password';
Step 5: Connect via the MySQL workbench
Click Database
Click Connect to Database
In the Connection Method field, select "Standard TCP/IP"
In the Hostname, enter your server IP address
In the Server Port, leave as it is "3306" unless you have changed the port of MySql in your server
In the Username, enter your server user name
In the Password, enter your server password
Click Ok
Step 6: If you are still not able to connect
On your server, disable the firewall and check if you are able to connect
If you are able to connect, reset the firewall with the command "sudo ufw reset" (Make sure you take a copy or screenshot of all the connections in the firewall. You can get all the ports with the command "sudo ufw status"). If you are unable to connect go to step 9.
Now allow each and every port that was earlier present with the command "sudo ufw allow 80", "sudo ufw allow mysql", etc.
Disable and enable the firewall using the commands "sudo ufw disable" and "sudo ufw enable" respectively.
Check if you are able to connect via the workbench
If you are still not able to connect, just restart the server using the command "sudo reboot"
Once the reboot is complete, you should be able to connect to the MySQL server.
If you are still not able to connect, use something like nmap software to check for all the open ports and see if you can see 3306. If you can't see the port, you have to debug what is stopping the firewall from blocking your MySQL connections.
Check your MySQL privileges with the command "show grants for 'user_name'#'localhost';". If you are able to see the grants, that means your IP address is not allowed. Try to update the grants with your IP address with the following command "GRANT ALL PRIVILEGES ON database.* TO 'user'#'yourremotehost' IDENTIFIED BY 'newpassword';" or GRANT ALL PRIVILEGES ON database.* TO 'user'#'yourremotehost' IDENTIFIED BY 'newpassword'; (To allow connections from everywhere)
If the above steps don't work and still you want to connect via a quick hack
Premium Hack Step: Logging in using MySQL Workbench via SSH
Click Database
Click Connect to Database
In the Connection Method field, select "Standard TCP/IP over SSH"
In the SSH Hostname, enter your server IP address
In the SSH Username, enter your server user name
In the SSH Password, enter your server password
In the SSH Key file, don't do anything
In the MySQL Hostname, leave it as it is "127.0.0.1"
In the Server Port, leave as it is "3306" unless you have changed the port of MySQL in your server
In the Username, enter your MySQL username that you created in the previous step
In the Password, enter your MySQL password that you created in the previous step
Click Ok
Now, you should be able to enter your MySQL Workbench
Other useful commands:
To check if MySQL is running: systemctl status mysql
Entering MySQL: sudo mysql -u [username] -p (Default username is root and password is nothing (just press enter key))
To check the status of ufw: sudo ufw status
To check the ufw status numbered for deleting a port access: sudo ufw status numbered
To delete a ufw port access: sudo ufw delete [number_of_the_port_to_be_deleted_from_previous_command]
To start MySQL service: sudo service mysql start
To update all packages: sudo apt update
To uninstall MySQL: sudo apt-get remove mysql*
To install MySQL
Step 1: sudo apt update
Step 2: sudo apt install mysql-server
Step 3: sudo systemctl start mysql.service
Step 4 (if something is broken during installation): sudo apt --fix-broken install