红联Linux门户
Linux帮助

centos,linux下django链接mysql提示mysql.sock无法打开问题

发布时间:2017-05-18 16:05:46来源:linux网站作者:avi9111
首先,如果你不是一个架构师,那么你得知道什么是才能往下看。
 
环境:
centos
mysqld
django
MySQL-Python
 
提示: can't open .... /var/lib/mysql/mysql.sock 
 
然后我会告诉你,我在django的启动setting的Databased项里添加OPTIONS。
(本来是没有option的,同样的一份代码,配置,我用MAC笔记本做服务器也是不需要option的,但是现在部署到Linux上。)
 
改写,添加option项:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'Oracle'.
'NAME': 'star_ums',      # Or path to database file if using sqlite3.
'USER': 'root',       # Not used with sqlite3.
'PASSWORD': '',   # Not used with sqlite3.
'HOST': '',        # Set to empty string for localhost. Not used with sqlite3.
'PORT': '',       # Set to empty string for default. Not used with sqlite3.
'OPTIONS':{
"unix_socket":"/tmp/mysql.sock"
},
}
 
问题解决!
 
不用Ctrl + Alt + F12切命令行了。
直接用centos终端。(突然领悟到所谓的架构师,TMD就是linux系统软件安装师,起码是国内是这样的,名称什么的乱起!)
前阵子比较来比较去,选了CentOS作Linux系统,刚装到虚拟机里面,发现默认的用户无法开启系统权限。终端中输入sudo后提示“XXX is not in the sudoers file. This incident will be reported.” 上网搜搜,找到了解决办法:用sudo时提示"xxx is not in the sudoers file. This incident will be reported.其中XXX是你的用户名,也就是你的用户名没有权限使用sudo,我们只要修改一下/etc/sudoers文件就行了。
下面是修改方法:
1)进入超级用户模式。也就是输入"su -",系统会让你输入超级用户密码,输入密码后就进入了超级用户模式。(当然,你也可以直接用root用) 
(后面就没有后面了,反正你都 su ,还用什么设sudo用户?)
 
最终结果:
centos,linux下django链接mysql提示mysql.sock无法打开问题
 
本文永久更新地址:http://www.linuxdiyf.com/linux/30882.html