I have a LAMP stack setup. Occasionally, I get the following error message when I open some page from the browser:
Error creating the connection!: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I think the server was configured correctly. The problem happens about every two months. Every time when I reboot the Linux server, or restart mysql, the problem was gone. I want to fix this problem permanently. Can anyone give me some idea?
Much appreciated.
EDIT
The problem occurs again and I checked the mysqld.sock file, it was not there. Do you have any idea how to fix the problem? – Ryan Jul 23 at 16:24
If your file my.cnf (usually in the /etc/mysql/ folder) is correctly configured with
socket=/var/run/mysqld/mysqld.sock
modified
#bind-address = 127.0.0.1
to
bind-address = localhost
you can check if mysql is running with the following command:
mysqladmin -u root -p status
try changing your permission to mysql folder. If you are working locally, you can try:
sudo chmod -R 755 /var/run/mysqld/
And then restart the mysql.
Good luck.
Could it be the log file getting too large and rebooting flushes it. See this in docs on server maintenance and logfiles. Also see discussion at digital ocean. Appears to be confirmed by discussion at serverfault
You could try change the permission of your MySQL sock file like this:
chmod 777 '/var/run/mysqld/mysqld.sock'
It is a test to see if whatever user mysqld is using, it will acess your mysqld.sock file. So, reboot your MySQL and change the permission of mysqld.sock. And you need to check that if your sock folder can be accessed through any mysqld process.
If the mysqld.sock file doesn't exist, that is to say your config file is not correct.Check your mysql config file in /etc/mysql/my.conf, find the socket config just as Vanya Avchyan says.
I think the socket config is /var/run/mysqld/mysqld.sock, but in fact your mysql process runs in other place sock file.
I used to met that problem, the real socket file exists in /tmp/mysqld.sock.
So run
sudo find / -name 'mysqld.sock'
to find the real sock file and change my.conf to this real place, restart your mysql. May have work.
I want to change the default port number of MySQL server presently it is 3306. I want to change it to 3360.
I have tried:
-- port=3360
But things are not working for me. Please provide query to change port not any configuration. I am using Windows 8 64 bit.
You need to edit your my.cnf file and make sure you have the port set as in the following line:
port = 3360
Then restart your MySQL service and you should be good to go. There is no query you can run to make this change because the port is not a dynamic variable (q.v. here for MySQL documentation showing a table of all system variables).
If you're on Windows, you may find the config file my.ini it in this directory
C:\ProgramData\MySQL\MySQL Server 5.7\
You open this file in a text editor and look for this section:
# The TCP/IP Port the MySQL Server will listen on
port=3306
Then you change the number of the port, save the file.
Find the service MYSQL57 under Task Manager > Services and restart it.
On newer (for example 8.0.0) the simplest solution is (good choice for a scripted start-up for example):
mysqld --port=23306
When server first starts the my.ini may not be created where everyone has stated. I was able to find mine in C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.6
This location has the defaults for every setting.
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]
# pipe
# socket=0.0
port=4306 !!!!!!!!!!!!!!!!!!!Change this!!!!!!!!!!!!!!!!!
[mysql]
no-beep
default-character-set=utf8
Go to installed mysql path and find bin folder,open my.ini and search 3306 after that change 3306 to 3360
Actually, you can just run the service using /mysqld --PORT 1234, it would force mysql to run on the specified port without change the cnf/ini file.
I just cought a case that cnf didn't work. It was weired... so I just use the cmd line as the shortcut and it works!
try changing the connection port to 8012
open xampp as administrator
Mysql config => my.ini change the port from 3306 to 8012
close and run it again
I hope it will work.
If you are using windows and installed the database as a service, which is the default, you should find your configuration file by opening your services management console.
For instance: win + r and then type services.msc
Look for a service called MySQL or MariaDB.
On the general tab of the properties of this service you can find a path to your mysqld.exe file and the arguments to start the exe. The --defaults-file argument should point to your configuration file.
Edit your configuration file and restart the MySQL service.
In Windows 8.1 x64 bit os, Currently I am using MySQL version :
Server version: 5.7.11-log MySQL Community Server (GPL)
For changing your MySQL port number, Go to installation directory, my installation directory is :
C:\Program Files\MySQL\MySQL Server 5.7
open the my-default.ini Configuration Setting file in any text editor.
search the line in the configuration file.
# port = .....
replace it with :
port=<my_new_port_number>
like my self changed to :
port=15800
To apply the changes don't forget to immediate either restart the MySQL Server or your OS.
Hope this would help many one.
Change my.cnf file and add this line or change it port=3360
at my fedora 34
sudo vi /etc/my.cnf
add This line ==> port=3360
The best way to do this is take backup of required database and reconfigure the server.
Creating A Backup
The mysqldump command is used to create textfile “dumps” of databases managed by MySQL. These dumps are just files with all the SQL commands needed to recreate the database from scratch. The process is quick and easy.
If you want to back up a single database, you merely create the dump and send the output into a file, like so:
mysqldump database_name > database_name.sql
Multiple databases can be backed up at the same time:
mysqldump --databases database_one database_two > two_databases.sql
In the code above, database_one is the name of the first database to be backed up, and database_two is the name of the second.
It is also simple to back up all of the databases on a server:
mysqldump --all-databases > all_databases.sql
After taking the backup, remove mysql and reinstall it. After reinstalling with the desired port number.
Restoring a Backup
Since the dump files are just SQL commands, you can restore the database backup by telling mysql to run the commands in it and put the data into the proper database.
mysql database_name < database_name.sql
In the code above, database_name is the name of the database you want to restore, and database_name.sql is the name of the backup file to be restored..
If you are trying to restore a single database from dump of all the databases, you have to let mysql know like this:
mysql --one-database database_name < all_databases.sql
I installed MySQL using mysql-installer-5.5.20.0.msi on Windows 7.
From the cmd window, I run "mysqlshow -u root -p". It asked for a password, then returned this error: "Can't connect to MySQL server on 'localhost' (10061)" This is a bad indication of partially failed/successful installation.
After reading the page, http://dev.mysql.com/doc/refman/5.5/en/windows-troubleshooting.html, it told me to find an error log (.err) in C:\Program Files\MySQL\MySQL Server 5.5\data. The directory exists but there is no log file.
I have a feeling this is related to the tight security of Windows 7, especially when installing a Unix based software. And yes, I am the Administrator on my PC.
Any help or suggestions is appreciated. And I can return a favor by answering Java and SQL query questions.
Please Try the following steps:
c:\mysql\bin>mysqld --install
c:\mysql\bin>mysqld --initialize
then press "Windows key + R" write "services.msc", run as admin
start MySQL service.
I also faced the same issue and resolved it by below setups:
Check the MYSQL service in the windows service. If it is there and not running then start it. It will solve your problem.
You can find the services window by navigating to windows Start menu and typing 'services' in the search bar. Select the 'Services' option with the cogs next to it (not the executable file) and the below window will appear. Scroll down to find 'MySql (version)'. When you select MySql you should see an option in the left pane that says 'Start the service'. Click this and a dialogue should appear to indicate Windows is attempting to start the service. Once started the left pane will now give you the option to stop, pause and restart the service and you will now be able to connect to your MySql from the windows cmd line.
If MYSQL service is not present in windows service then follow below setups.
a. Open cmd as administrator.
b. cd to C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin
c. Run the command:
C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin>mysqld.exe --install
d. Check the MySql in the windows service, And if it is not running, Start it by clicking on the service.
e. If your using XAMMP . Start MySQL at the XAMMP control Panel.
this issue is very to solve by windows server users
go to this path
C:\Program Files\MySQL\MySQL Server 5.1\bin
run this tool "MySQLInstanceConfig.exe"
and config the instatnce again and problem solved
The simple solution that worked for me is: change localhost to 127.0.0.1 in your database.yml or in your script if writing one.
Here, you need to make sure that the MySQL service is running is Windows. It might be possible that your MySQL service is not running cuurrently.
Open Services window by pressing Windows+R and entering services.msc
Find out MySQL right click and select start.
It works.
I had this error - stupid mistake was, I was using -p3307 to specify port, whereas I should have used -P3307, i.e. capital P. Small 'p' is for password arg :)
In Windows 7
press Windows+R it opens Run
Enter services.msc
Find out mysql right click and start
if mysql was not found
Run cmd as administrator
goto C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin directory(to go back use cd..) and type mysqld.exe --install
follow step 3
That's all
I solved this by adding the following arguments to the command line string:
mysql --user username --password password --host localhost --port 3306 databasename < "system path to .sql file"
Without the --host and --port arguments, especially if you change the port to let's say 3307, which is a non default value, will cause this error.
I got this error in command prompt when I tried to open MySQL from cmd "mysql -u root -p"
Can't connect to MySQL server on 'localhost:3306' (10061)
It was because I changed my port during the installation of MySQL community server as I had XAMPP server installed and running as well which was not allowing me to use the port 3306.
So basically I had 2 MySQL servers installed in my system.
MySQL community server.
XAMPP server.
If anyone had this same issue this is how I fixed it.
Step 1: Reconfigure MySQL server to port 3306
Step 2: Reconfigure XAMPP to use a different port other than 3306
Note: Stop the XAMPP server before following the steps.
Step 1: Reconfigure MySQL server to port 3306
Click Start and open MySql installer - community
Click on reconfigure button in front of MySql server
Type 3306 in port. Execute and complete the installation.
Step 2: Reconfigure XAMPP to use a different port other than 3306
Open XAMPP and change the port other than 3306 in two files
my.ini under MySQL
and php.ini under Apache
Now everything seems to be working fine for me. I was able to get into MySQL community server from cmd and I can use XAMPP server as well.
I have Windows 8.1 and I too had this problem. My teacher told me it was probably because my MySQL server had stopped running. She told me to go into the Computer Management utility (right click the lower-most left hand corner of the screen on Windows 8.1 to access Computer Management). Then under Services and Applications, open up the Services and find MySQL. You should be able to right-click on MySQL and restart it.
In Start Menu, search for "mysql". Among the results, you should see the "MySQL Installer - Community". Run it.
MySQL Installer window will show up as shown below. Find "MySQL Server" under Product and click on "Reconfigure" link.
The MySQL Installer will show up (same one you used for the first MySQL Server installation). Go through all the steps.
After the MySQL Installer was finished, I started the MySQL service again. This time, the "Startup Message Log" on The MySQL Notifier was showing that the server started successfully:
https://www.howtosolutions.net/2017/08/fixing-mysql-10061-error-after-migration-of-database-files/
This is the easiest solution and worked for me.
Go to where you downloaded
"mysql-installer-web-community-8.0.19.0.msi", file for installing
mysql.
Run this by double clicking on it. (No need to uninstall anything)
Click on "reconfigure" beside the MySql server.
Agree everything which comes in middle, provide password for root where asked.
Finish. That's it you're good to go.
For the 5.7 version, I had the same problem and a simple fix did the trick. As Installed the workbench 5.7 there was another "software" of sorts called the "MySQL Installer Community". I ran this and ran the "Reconfigure" for the MySQL server. It took about a minute and the problem was no longer there.
Hope it works!.(Keep in mind i was using the 5.7 version)
Just turn off the firewall and remove the instance configuration. Add a new instance for the server.![Disable Firewall][1]
Give he port number correctly as 3306 as default
Solution 1:
For 32bit:
Run "mysql.exe" from: C:\Program Files\MySQL\MySQL Server 5.6\bin
For 64bit:
Run "MySQLInstanceConfig.exe" from: C:\Program Files\MySQL\MySQL Server 5.6\bin
Solution 2:
The error (2002) Can't connect to ... normally means that there is no
MySQL server running on the system or that you are using an incorrect
Unix socket file name or TCP/IP port number when trying to connect to
the server. You should also check that the TCP/IP port you are using
has not been blocked by a firewall or port blocking service.
The error (2003) Can't connect to MySQL server on 'server' (10061)
indicates that the network connection has been refused. You should
check that there is a MySQL server running, that it has network
connections enabled, and that the network port you specified is the
one configured on the server.
Source: http://dev.mysql.com/doc/refman/5.6/en/starting-server.html
Visit it for more information.
For anyone who have the same problem of "Can't connect to MySQL server on 'localhost' (10061) " or "Can't connect to MySQL server on '127.0.0.1' (10061) ".
You can install "MySQL Installer" and this is the link http://dev.mysql.com/downloads/windows/installer/5.6.html
and this is a tutoriel for more help https://www.youtube.com/watch?v=AqQc3YqfelE
it works for me and i wish to work for you too.
I had the same error. I resolved in this way
Go to start- MySQL Installer-community and run again the installer as a re-configuration(you will be asked so).
Once asked if you want make MySQL instance to run as a Windows service, check the box.
In case would do not work, try unistalling and installing again, and check the box to run MySQL as Windows service.
From what I've gathered this means the mysql service (mysqld) isn't running.
First make sure it is installed as a windows service : Run
"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld" --install
from the command line.
Next, start it up :
services.msc > MySQL > start
If it fails to restart, then you can follow these steps :
open the command line as an administrator :
cmd.exe > open as administrator
run "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld" --verbose
it should fail and put the error log in a directory named data under C:\Program Files\MySQL\MysSQL Server 5.7\ . If it fails to create data for some reason, do it manually under that directory and try again. If you can figure out what's missing from what's in that log, then good, you're done.
If you've still got no luck, this is how I did it :
goto C:\ProgramData\MySQL and copy the file named my.ini to C:\Windows\
try to start the service again from the command line :
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld" --verbose
If it doesn't display any error, than the service startup was successfull. If it's still not working, than delete that my.ini you just copied from C:\Windows and start the service from the command line once again.
it should work now
if it is showing error 2003 (HY000): Can't connect to MySQL server on localhost (10061) than
Search services.msc in run
goto mysql properties
copy the mysql service name
start cmd as administrator
write: net start mysqlservicename .i.e mysql57 or etc it will show mysql is starting.
For me, three steps solved this problem on windows 10:
I downloaded MySQL server community edition zip and extracted it in the D drive. After that I went to bin folder and did cmd on that folder. I followed the below steps and all works:
D:\tools\mysql-8.0.17-winx64\bin>mysqld -install
Service successfully installed.
D:\tools\mysql-8.0.17-winx64\bin>mysqld --initialize
D:\tools\mysql-8.0.17-winx64\bin>net start mysql
The MySQL service is starting...
The MySQL service was started successfully.
I too had this problem, its easy to solve:
Go to Control panel - System and maintenance - System - Advanced system settings - Environment variables - System variables - path - click edit - add
"c:\xampp\mysql\bin" - it should look like this :
\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\QuickTime Alternative\QTSystem;c:\xampp\mysql\bin
And don't forget to start MySQL from control panel of Xampp.
I found the same error re occurring even after I tried all the above solutions given above. I had even tried version 5.7 and few more. Guys don't waste your time trying to fix it. Rather install version 5.5. It's working perfectly fine without any unnecessary error.
Well in my case I just opened services.msc using run and restarted 2 of the services related to mysql and it worked!
In case of Xampp Installation.
Go to your xampp installation and mysql folder, for my case: C:\xampp\mysql
Run the file "resetroot.bat" from cmd or explorer.
My installation started working!!!
The solution that fixed the issue was using the following steps:
In Start Menu, search for "mysql". Among the results, you should see the "MySQL Installer - Community". Run it.
MySQL Installer window will show up as shown below. Find "MySQL Server" under Product and click on "Reconfigure" link.
MySQL Installer Community
The MySQL Installer will show up (same one you used for the first MySQL Server installation). Go through all the steps.
After the MySQL Installer was finished, I started the MySQL service again.
Don't do useless stuff like reconfigure, stop MySQL and start MySQL in service.
Just reinstall the MYSQL server and again install it in your system.
Remember only uninstall MySQL server and nothing else.
All the problem will be solve automatically
The main reason for this kind of error is you might have uninstalled Mysql server application. Install it and then give it a go.
for who person that want use mysql or mariadb with out any error i suggest use version 5.5
just download a zip file mariadb-5.5.65-winx64.zip from https://downloads.mariadb.org/mariadb/5.5.65/ and to install follow this tutorial setp by step https://www.youtube.com/watch?v=uEPs6JsTZFc (this tutorial works well for version 5.5 too )
I had the same issue and basically resolved it by pointing to a specific port number that my MySQL server was running on. Below is the command. Please edit the code to fit your case i.e your port number,your mysql server username,your password.
mysql -u root -pYourMysqlRootPassword -P3307
Create the temp folder c:/mysqltmp
In my.ini file under [mysqld] add the line
tmpdir=c:/mysqltmp
Add full privileges to user NETWORK SERVICE for "C:\ProgramData\MySQL\MySQL Server X.Y\Data\ibdata1" file
Start service
These are steps for the same problem with MySQL5.7 and MySQL8.0 on Windows 10