1、彻底删除mysql
防止原有数据影响后续的安装和调试1 sudo apt-get autoremove --purge mysql-server-5.02 sudo apt-get remove mysql-server3 sudo apt-get autoremove mysql-server4 sudo apt-get remove mysql-common (非常重要)上面的其实有一些是多余的,建议还是按照顺序执行一遍清理残留数据 dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P 2, 安装 mysqlsudo apt-get install mysql-server root密码 kunth123 mysql -uroot -pKunth123登录mysql serverpython操作mysql: sudo apt-get install python-mysqldb在python解释器中检查安装是否成功>>> import MySQLdb>>> conn = MySQLdb.connect(host='127.0.0.1', user='root',passwd='kunth123') 3、mysql用户管理安装后以root登录查看用户表信息mysql> select user from user;存在用户名为空的用户,不安全。删除:delete from user where user = '';Query OK, 2 rows affected (0.00 sec)创建pbook用户,允许增删改查pbook相关的表暂时赋值为所有表的权限。grant create, alter, select,insert,update,delete on *.* to "pbook"@"%" Identified by "kunth123";问题:添加后本机无法访问。推测为%没有做匹配。grant create, alter, select,insert,update,delete on *.* to "pbook"@"localhost" Identified by "kunth123"; 用于本机访问。4、mysql 字符编码设置修改配置文件sudo vim /etc/mysql/my.cnf添加或者修改以下字段:[client]default-character-set = utf8[mysqld]character-set-server = utf8collation-server = utf8_general_ci重启 mysqlsudo service mysql restart登录mysql查看字符编码修改结果show variables like 'character_set_%';show variables like 'collation_%';查看database的字符编码mysql> status--------------mysql Ver 14.14 Distrib 5.5.24, for debian-linux-gnu (x86_64) using readline 6.2 Connection id: 38 Current database: Current user: pbook@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /var/run/mysqld/mysqld.sock Uptime: 10 min 18 sec Threads: 1 Questions: 154 Slow queries: 0 Opens: 197 Flush tables: 1 Open tables: 43 Queries per second avg: 0.249 -------------- 单独设置某个数据库: alter database testdb character set utf8; 查看mysql支持的编码: show character set;
这里 还有个链接也听不错: