我正在使用mysqldb(python MySQL)模块.. 但每次我试着跑。它给了我这个错误。
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
我认为问题是安装了多个mysql ..但我不是mysql专家..实际上除了python之外......假设我对操作系统的知识很少.. mysql.or任何其他的东西,:)
我还在ubuntu上安装了XAMPP ..每次启动xampp模块 但在我启动xampp服务器之前.. 我总是这样做..
sudo /etc/init.d/mysql stop (this is my clue that there is another mysql installed :D )
要启动XAMPP本地主机,请执行以下操作
sudo /opt/lampp/lampp start
错误说
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
我正在详细阐述上述所有内容,只是为了证明解决这个问题的相关途径在哪里。 你能帮帮我吗? 感谢。
修改
ps -ax
rreturns follwoing:
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
PID TTY STAT TIME COMMAND
1 ? Ss 0:01 /sbin/init
2 ? S 0:00 [kthreadd]
3 ? S 1:45 [ksoftirqd/0]
6 ? S 0:00 [migration/0]
17 ? S< 0:00 [cpuset]
18 ? S< 0:00 [khelper]
19 ? S< 0:00 [netns]
21 ? S 0:00 [sync_supers]
22 ? S 0:00 [bdi-default]
23 ? S< 0:00 [kintegrityd]
24 ? S< 0:00 [kblockd]
25 ? S< 0:00 [kacpid]
26 ? S< 0:00 [kacpi_notify]
27 ? S< 0:00 [kacpi_hotplug]
28 ? S< 0:00 [ata_sff]
29 ? S 0:00 [khubd]
30 ? S< 0:00 [md]
34 ? S 0:00 [khungtaskd]
35 ? S 0:01 [kswapd0]
36 ? SN 0:00 [ksmd]
37 ? S 0:00 [fsnotify_mark]
38 ? S< 0:00 [aio]
39 ? S 0:00 [ecryptfs-kthrea]
40 ? S< 0:00 [crypto]
44 ? S< 0:00 [kthrotld]
46 ? S 0:00 [scsi_eh_0]
47 ? S 0:05 [scsi_eh_1]
48 ? S< 0:00 [kmpathd]
49 ? S< 0:00 [kmpath_handlerd]
50 ? S< 0:00 [kondemand]
51 ? S< 0:00 [kconservative]
219 ? S 0:00 [scsi_eh_2]
220 ? S 0:48 [usb-storage]
253 ? S 0:12 [jbd2/sda6-8]
254 ? S< 0:00 [ext4-dio-unwrit]
307 ? S 0:00 upstart-udev-bridge --daemon
313 ? S<s 0:00 udevd --daemon
549 ? S 0:00 upstart-socket-bridge --daemon
678 ? S< 0:00 [hci0]
698 ? S< 0:00 [hd-audio0]
`727 ? S< 0:00 [hd-audio1]
729 ? S< 0:00 [applesmc-led]
775 ? Ss 0:00 smbd -F
778 ? Ss 0:00 /usr/sbin/sshd -D
784 ? Sl 0:00 rsyslogd -c4
792 ? S 0:00 smbd -F
796 ? Ss 0:20 dbus-daemon --system --fork --activation=upstart
807 ? Ssl 0:16 NetworkManager
814 ? S 0:00 /usr/sbin/modem-manager
817 ? Sl 0:03 /usr/lib/policykit-1/polkitd
854 ? S 0:03 /sbin/wpa_supplicant -u -s
873 tty4 Ss+ 0:00 /sbin/getty -8 38400 tty4
877 tty5 Ss+ 0:00 /sbin/getty -8 38400 tty5
883 tty2 Ss+ 0:00 /sbin/getty -8 38400 tty2
884 tty3 Ss+ 0:00 /sbin/getty -8 38400 tty3
888 tty6 Ss+ 0:00 /sbin/getty -8 38400 tty6
900 ? Ss 0:00 acpid -c /etc/acpi/events -s /var/run/acpid.socket
914 ? Ss 0:13 /usr/sbin/irqbalance
928 ? Ss 0:00 cron
929 ? Ss 0:00 atd
931 ? Ss 0:00 /usr/sbin/bluetoothd --udev
946 ? S< 0:00 [l2cap]
978 ? Ssl 0:00 gdm-binary
982 ? Sl 0:01 /usr/sbin/console-kit-daemon --no-daemon
1079 ? Sl 0:00 /usr/lib/gdm/gdm-simple-slave --display-id /org/gnome/DisplayManager/Display1
1087 ? S< 0:00 [krfcommd]
1088 ? Ss 0:00 /usr/sbin/cupsd -F
1164 tty7 Ss+ 42:06 /usr/bin/X :0 -nr -verbose -auth /var/run/gdm/auth-for-gdm-pkvNFp/database -nolisten tcp vt
1200 ? S 0:11 [flush-8:0]
1314 ? Sl 0:00 /usr/lib/gdm/gdm-session-worker
1320 ? Sl 0:22 /usr/lib/upower/upowerd
1324 ? SNl 0:00 /usr/lib/rtkit/rtkit-daemon
1431 ? Ss 0:08 nmbd -D
1490 tty1 Ss+ 0:00 /sbin/getty -8 38400 tty1
1496 ? Sl 0:00 /usr/bin/gnome-keyring-daemon --daemonize --login
1515 ? Ssl 0:00 gnome-session --session=ubuntu
1548 ? Ss 0:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session gnome-session --session=ubuntu
1551 ? S 0:00 /usr/bin/dbus-launch --exit-with-session gnome-session --session=ubuntu
1552 ? Ss 1:00 //bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
1557 ? S 0:33 /usr/lib/libgconf2-4/gconfd-2
1566 ? Ssl 0:35 /usr/lib/gnome-settings-daemon/gnome-settings-daemon
1572 ? S 0:00 /usr/lib/gvfs/gvfsd
1575 ? Sl 36:41 compiz
1579 ? Ssl 0:00 /usr/lib/gvfs//gvfs-fuse-daemon /home/mohit/.gvfs
1584 ? Ssl 5:19 /usr/bin/pulseaudio --start --log-target=syslog
1586 ? Sl 3:04 nautilus
1587 ? Sl 0:02 /usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1
1589 ? SLl 0:19 nm-applet --sm-disable
1590 ? Sl 0:02 zeitgeist-datahub
1591 ? Sl 0:00 /usr/lib/evolution/2.32/evolution-alarm-notify
1597 ? Sl 0:17 gnome-power-manager
1598 ? Sl 0:00 bluetooth-applet
1601 ? Sl 0:03 /usr/bin/python /usr/bin/zeitgeist-daemon
1619 ? S 0:00 /bin/cat
1621 ? Sl 0:20 /usr/lib/notify-osd/notify-osd
1627 ? Sl 0:03 /usr/lib/evolution/e-calendar-factory
1629 ? S 0:00 /usr/lib/gvfs/gvfsd-trash --spawner :1.11 /org/gtk/gvfs/exec_spaw/0
1637 ? Z 0:00 [zeitgeist-datah] <defunct>
1649 ? Sl 0:00 /usr/lib/pulseaudio/pulse/gconf-helper
1653 ? S 0:00 /usr/lib/gvfs/gvfs-gdu-volume-monitor
1656 ? Sl 0:01 /usr/lib/udisks/udisks-daemon
1657 ? S 0:14 udisks-daemon: polling /dev/sr0 /dev/sdb
1661 ? S 0:31 syndaemon -i 0.5 -k -R
1665 ? Sl 0:00 /usr/lib/gvfs/gvfs-afc-volume-monitor
1668 ? S 0:00 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
1673 ? Sl 0:00 /usr/lib/d-conf/dconf-service
1683 ? Ss 0:00 /bin/sh -c /usr/bin/compiz-decorator
1684 ? Sl 0:35 /usr/bin/unity-window-decorator
1687 ? Sl 4:22 /usr/lib/unity/unity-panel-service
1698 ? S 0:00 /usr/lib/gvfs/gvfsd-metadata
1700 ? S 0:25 /usr/lib/bamf/bamfdaemon
1704 ? Sl 0:00 /usr/lib/indicator-session/indicator-session-service
1709 ? Sl 0:00 /usr/lib/indicator-messages/indicator-messages-service
1719 ? Sl 0:00 /usr/lib/indicator-sound/indicator-sound-service
1720 ? Sl 0:04 /usr/lib/indicator-application/indicator-application-service
1721 ? Sl 0:05 /usr/lib/indicator-datetime/indicator-datetime-service
1722 ? Sl 0:00 /usr/lib/indicator-me/indicator-me-service
1746 ? Sl 0:01 /usr/lib/geoclue/geoclue-master
1752 ? S 0:00 /usr/lib/gvfs/gvfsd-burn --spawner :1.11 /org/gtk/gvfs/exec_spaw/1
1825 ? Sl 0:07 /usr/bin/gnome-screensaver --no-daemon
1834 ? S 0:00 /usr/lib/gnome-disk-utility/gdu-notification-daemon
1876 ? S 0:09 /usr/bin/python /usr/share/system-config-printer/applet.py
1883 ? Sl 0:06 update-notifier
1917 ? Sl 0:02 /usr/lib/unity-place-applications/unity-applications-daemon
1919 ? Sl 0:00 /usr/lib/unity-place-files/unity-files-daemon
1944 ? SLl 7:08 /usr/lib/chromium-browser/chromium-browser
1946 ? S 0:09 /usr/lib/chromium-browser/chromium-browser
1948 ? S 0:00 /usr/lib/chromium-browser/chromium-browser --type=zygote
1975 ? Sl 8:46 /usr/lib/chromium-browser/chromium-browser --type=renderer --lang=en-US --force-fieldtest=C
1998 ? Sl 17:59 /usr/lib/chromium-browser/chromium-browser --type=plugin --plugin-path=/usr/lib/flashplugin
2243 ? S 0:00 /usr/bin/python /usr/lib/system-service/system-service-d
10495 ? S< 0:00 [xfs_mru_cache]
10497 ? S< 0:00 [xfslogd]
10498 ? S< 0:00 [xfsdatad]
10499 ? S< 0:00 [xfsconvertd]
10505 ? S 0:00 [jfsIO]
10506 ? S 0:00 [jfsCommit]
10507 ? S 0:00 [jfsCommit]
10508 ? S 0:00 [jfsCommit]
10509 ? S 0:00 [jfsCommit]
10510 ? S 0:00 [jfsSync]
12826 ? Sl 1:35 /usr/lib/chromium-browser/chromium-browser --type=renderer --lang=en-US --force-fieldtest=C
13020 ? S 0:00 /usr/lib/gvfs/gvfsd-http --spawner :1.11 /org/gtk/gvfs/exec_spaw/2
20440 ? S 0:05 avahi-daemon: running [mohit-MacBookPro.local]
20441 ? S 0:00 avahi-daemon: chroot helper
24799 ? Sl 1:14 /usr/lib/libreoffice/program/soffice.bin -calc /home/mohit/Documents/vmf/VMF Test Reports/p
24900 ? Sl 0:00 /usr/lib/gvfs/gvfsd-network --spawner :1.11 /org/gtk/gvfs/exec_spaw/5
24904 ? Sl 0:00 /usr/lib/gvfs/gvfsd-smb-browse --spawner :1.11 /org/gtk/gvfs/exec_spaw/6
24910 ? S 0:00 /usr/lib/gvfs/gvfsd-dnssd --spawner :1.11 /org/gtk/gvfs/exec_spaw/7
25340 ? SNl 0:09 /usr/lib/chromium-browser/chromium-browser --type=renderer --lang=en-US --force-fieldtest=C
25357 ? SNl 0:04 /usr/lib/chromium-browser/chromium-browser --type=renderer --lang=en-US --force-fieldtest=C
25772 ? S 0:00 /usr/lib/postgresql/8.4/bin/postgres -D /var/lib/postgresql/8.4/main -c config_file=/etc/po
25774 ? Ss 0:07 postgres: writer process
25775 ? Ss 0:05 postgres: wal writer process
25776 ? Ss 0:01 postgres: autovacuum launcher process
25777 ? Ss 0:01 postgres: stats collector process
25863 ? Sl 0:14 gnome-terminal
25868 ? S 0:00 gnome-pty-helper
25869 pts/0 Ss+ 0:00 bash
25928 ? Sl 16:19 /usr/lib/firefox-8.0/firefox
25966 ? Sl 2:47 /usr/lib/firefox-8.0/plugin-container /usr/lib/flashplugin-installer/libflashplayer.so -gre
26057 pts/1 Ss 0:00 bash
26190 pts/2 Ss+ 0:00 bash
26606 ? S 0:00 /usr/lib/gvfs/gvfsd-computer --spawner :1.11 /org/gtk/gvfs/exec_spaw/8
27198 ? S 0:00 [migration/1]
27200 ? S 0:07 [ksoftirqd/1]
27201 ? S 0:00 [migration/2]
27203 ? S 0:00 [ksoftirqd/2]
27204 ? S 0:00 [migration/3]
27206 ? S 0:00 [ksoftirqd/3]
27225 ? S 0:00 [kworker/u:44]
27226 ? S 0:00 [kworker/u:45]
27251 ? S 0:01 [kworker/2:0]
27252 ? S 0:00 [kworker/3:1]
27317 ? Sl 1:42 /usr/lib/chromium-browser/chromium-browser --type=renderer --lang=en-US --force-fieldtest=C
27429 ? SNl 0:05 /usr/lib/chromium-browser/chromium-browser --type=renderer --lang=en-US --force-fieldtest=C
27466 ? SNl 0:05 /usr/lib/chromium-browser/chromium-browser --type=renderer --lang=en-US --force-fieldtest=C
27560 ? SNl 0:21 /usr/lib/chromium-browser/chromium-browser --type=renderer --lang=en-US --force-fieldtest=C
27607 ? SNl 0:07 /usr/lib/chromium-browser/chromium-browser --type=renderer --lang=en-US --force-fieldtest=C
27657 ? S 0:00 /sbin/dhclient -d -4 -sf /usr/lib/NetworkManager/nm-dhcp-client.action -pf /var/run/dhclien
27681 ? Sl 0:00 /usr/lib/evolution/e-addressbook-factory
27686 ? S 0:00 /usr/lib/telepathy/mission-control-5
27688 ? Sl 0:00 /usr/lib/telepathy/telepathy-logger
28186 ? S 0:00 /usr/sbin/usbmuxd -u -U usbmux
28187 ? S< 0:00 udevd --daemon
28188 ? S< 0:00 udevd --daemon
28196 ? Sl 0:00 /usr/lib/gvfs/gvfsd-afc --spawner :1.11 /org/gtk/gvfs/exec_spaw/9
28200 ? Sl 0:00 /usr/lib/gvfs/gvfsd-afc --spawner :1.11 /org/gtk/gvfs/exec_spaw/10
28212 ? S 0:02 [kworker/1:0]
28864 pts/3 Ss 0:00 bash
28923 pts/3 T 0:00 sudo easy_install Flasj
28927 pts/3 T 0:00 /usr/bin/python /usr/bin/easy_install Flasj
28992 ? Sl 0:02 file-roller /home/mohit/Downloads/Archive.zip
29044 pts/5 Ss+ 0:00 bash
29142 ? Sl 0:00 file-roller /home/mohit/Downloads/Archive (1).zip
29152 ? Sl 0:02 file-roller /home/mohit/Downloads/Archive (1).zip
29185 ? S 0:01 [kworker/0:3]
29243 ? S 0:00 [kworker/0:1]
29251 pts/2 T 0:00 python
29271 pts/1 Sl+ 0:09 ./sublime_text
29507 pts/5 T 0:00 sudo /etc/init.d/mysql start
29509 pts/5 T 0:00 /bin/sh -e /etc/init.d/mysql start
29513 pts/5 T 0:00 start mysql
29562 ? SNl 0:09 /usr/lib/chromium-browser/chromium-browser --type=renderer --lang=en-US --force-fieldtest=C
29632 ? S 0:00 [kworker/2:2]
29633 ? S 0:00 [kworker/3:0]
30030 pts/0 T 0:00 sudo chown mysql:root /var/run/mysqld
30148 ? S 0:00 [kworker/1:3]
30997 ? S 0:00 [kworker/1:1]
31015 ? S 0:00 [kworker/0:2]
31812 ? S 0:00 [kworker/1:2]
31853 ? S 0:00 [kworker/0:0]
32315 pts/5 T 0:00 sudo /etc/init.d/mysql start
32316 pts/5 T 0:00 /bin/sh -e /etc/init.d/mysql start
32320 pts/5 T 0:00 start mysql
32356 pts/3 R+ 0:00 ps -ax
答案 0 :(得分:3)
Aaghh愚蠢地忽略了我的事实...... 在问题中我说过我在启动xampp mysql之前停止了默认的mysql .. 但忘了重新开始.. 不幸的是
/etc/init.d/mysql start
不会工作 你必须这样做
/etc/init.d/mysql restart
答案 1 :(得分:2)
显然XAMPP的套接字在不同的地方,所以你需要明确说明套接字在哪里,因为它不在/var/run/mysqld/mysqld.sock。这将是:
kwargs2['unix_socket'] = '/some/other/path/mysqld.sock'
super(Connection, self).__init__(*args, **kwargs2)
您可以使用以下命令找到套接字:
find /opt/lampp -name "*.sock"