启动MySQL折腾近一下午
1、开始
[root@letfly ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Job failed. See system logs and 'systemctl status' for details.
[root@letfly ~]# cd /var/log/
[root@letfly log]# more mysqld.log
140812 16:11:56 mysqld_safe Starting mysqld daemon with databases from /var/li
b/mysql
140812 16:11:56 [Note] Plugin 'FEDERATED' is disabled.
140812 16:11:56 InnoDB: The InnoDB memory heap is disabled
140812 16:11:56 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140812 16:11:56 InnoDB: Compressed tables use zlib 1.2.5
140812 16:11:56 InnoDB: Using Linux native AIO
140812 16:11:56 InnoDB: Initializing buffer pool, size = 128.0M
140812 16:11:56 InnoDB: Completed initialization of buffer pool
140812 16:11:56 InnoDB: highest supported file format is Barracuda.
140812 16:11:56 InnoDB: Waiting for the background threads to start
140812 16:11:57 [ERROR] Do you already have another mysqld server running on port: 3306 ?
查看3306端口
[root@letfly ~]# netstat -tunlp | grep :3306
没结果
折腾了一段时间,果断yum remove mysql
2、接着
[root@letfly ~]# yum install mysql
[root@letfly ~]# yum install mysql-devel
[root@letfly ~]# yum install mysql-server
接着启动MySQL:
[root@letfly ~]# clear
[root@letfly ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Job failed. See system logs and 'systemctl status' for details.
仍不行,查看日志,如下:
[root@letfly ~]# cd /var/log/
[root@letfly log]# more mysqld.log
140812 16:11:56 mysqld_safe Starting mysqld daemon with databases from /var/li
b/mysql
140812 16:11:56 [Note] Plugin 'FEDERATED' is disabled.
140812 16:11:56 InnoDB: The InnoDB memory heap is disabled
140812 16:11:56 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140812 16:11:56 InnoDB: Compressed tables use zlib 1.2.5
140812 16:11:56 InnoDB: Using Linux native AIO
140812 16:11:56 InnoDB: Initializing buffer pool, size = 128.0M
140812 16:11:56 InnoDB: Completed initialization of buffer pool
140812 16:11:56 InnoDB: highest supported file format is Barracuda.
140812 16:11:56 InnoDB: Waiting for the background threads to start
140812 16:11:57 InnoDB: 1.1.8 started; log sequence number 1595675
140812 16:11:57 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
140812 16:11:57 [Note] - '0.0.0.0' resolves to '0.0.0.0';
140812 16:11:57 [Note] Server socket created on IP: '0.0.0.0'.
140812 16:11:57 [ERROR] Can't start server : Bind on unix socket: No such file
or directory
140812 16:11:57 [ERROR] Do you already have another mysqld server running on s
ocket: /opt/lampp/var/mysql/mysql.sock ?
原来是socket问题
[root@letfly mysql]# find / -name 'my.cnf'
/etc/my.cnf
修改my.cnf里的
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock(你先有的mysql位置)
[root@letfly mysql]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
OK!!欧耶!!
mysql-python是一个用来在python中访问mysql数据库的类库,django中默认也是用这个类库来访问mysql。
一.下载
wget http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.4b4/MySQL-python-1.2.4b4.tar.gz?use_mirror=ncu
二.修改site.cfg文件
修改site.cfg文件夹主要是告诉myslq-python的模块,mysql_config文件的路径,注意不是my.cnf文件。
将文件中下面这行配置的注释去掉,将“/usr/local/bin/mysql_config”改为你系统中mysql_conf文件所在路径。
#mysql_config = /usr/local/bin/mysql_config
三.安装
tar zxvf MySQL-python-1.2.4b4.tar.gz cd MySQL-python-1.2.4b4 python setup.py install
四.连接mysql
如没安装mysql
yum install mysql
测试非常简单,检查MySQLdb 模块是否可以正常导入。
[root@letfly opt]# ipython
Python 2.7.3 (default, Jul 24 2012, 11:41:34)
Type "copyright", "credits" or "license" for more information.
IPython 0.12 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import MySQLdb
常见问题:
1.Python版本不对
如果系统中有多个版本的python话,建议将django和mysql-python安装到高版本的python中。方法是安装时将python换为pythonxx,比如python2.7.3,安装命令就是:
python27 setup.py install
2.找不到libmysqlclient
开始使用mysql-python可能都会遇到错误提示如下
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
解决方法是:将“mysql安装目录/lib/mysql”目录下的libmysqlclient_r.so.16拷贝一份到“/usr/lib”目录。
1)问题:ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
原因是python无法找到mysql目录下的libmysqlclient_r.so.16动态库,其实MySQLdb是调用mysql的c函数库.所以本机上首先得安装了mysql
然后: export LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql:$LD_LIBRARY_PATH
并且将/usr/local/mysql5.1/lib/mysql 放入/etc/ld.so.conf中
/etc/ld.so.conf改后内容为:
include ld.so.conf.d/*.conf
/usr/local/mysql5.1/lib/mysql
3._mysql.c:29:20: 致命错误:Python.h:没有那个文件或目录
yum install python-devel mysql-devel
最后重新再测试一下,就不会有上面的问题了