1,备份 /etc/mysql/my.cnf
sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf.bak
2.编辑my.cnf
sudo vi /etc/mysql/my.cnf
大约47行
#bind-address = 127.0.0.1
加#注释掉 否则不能远程登录
[mysqld]里添加一行
character_set-server=utf8 (这里特别注意,老版本的是设置 default-character-set=utf8 然后服务无法启动)
设置mysql默认编码方式,默认的latin1不支持中文
这两项改完后 sudo /etc/init.d/mysql restart 重启服务,登录mysql 通过 status查看编码是否修改成功。
3.取消开机启动
由于不是每次开机都需要用到mysql,服务自启动浪费资源,改为手动管理mysql服务。
zhh@itant:/etc/init.d$ sudo service mysql stop
mysql stop/waiting
zhh@itant:/etc/init.d$ sudo update-rc.d -f mysql remove
Removing any system startup links for /etc/init.d/mysql ...
zhh@itant:/etc/init.d$ sudo service mysql start
mysql start/running, process 5186
zhh@itant:/etc/init.d$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands endwith ; or \g.
Your MySQL connection id is 36
Server version: 5.5.29-0ubuntu0.12.04.2 (Ubuntu)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or'\h'for help. Type '\c'to clear the current input statement.
mysql> exit
Bye
zhh@itant:/etc/init.d$
4.安装python-mysql
下载mysql-python 进入mysql-python目录,python install.py install 安装
提示 mysql_config not found,执行 sudo apt-get install libmysqld-dev 然后 sudo find / -name mysql_config 将查到的路径 编辑到 site.cfg中。
提示 _mysql.c:29:20: 致命错误: Python.h:没有那个文件或目录 ,执行 sudo apt-get install python-dev
最后执行安装命令
sudo python setup.py build
sudo python setup.py install
测试: python->import MySQLdb