MySQL问题总结


  1. mysql 1267错误
ERROR:Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like'
最后的like是出错的语法,
1)检查:数据库的编码集,
show variables like "%character%"; show variables like "%collation%";
--
collation_server            latin1_swedish_ci
collation_database      utf8_general_ci
collation_connection   utf8_general_ci
执行后看看三种mysql的编码集
2)针对查询结果比较,server的编码集可以忽略,后两种需要保持一致,我使用的是utf-8所以目前是正确的SET collation_connection=utf8_general_ci
3)如果还不行,那就是个别表或个别表的字段编码集错误,修改就可以
4)在my.ini中可以改变server的编码集,但一般不用。
  1. ERROR 1419
ERROR 1419 - you do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
log_bin_trust_function_creators错误
现象:当有mysql本地或远程建立function或procedure时报上面的错误经试验是log_bin_trust_function_creators值为off导致
设置:
set global log_bin_trust_function_creators=1;但重启后失效
永久windows下my.ini[mysqld]區段加上log_bin_trust_function_creators=1
linux下/etc/my.cnf下my.ini[mysqld]區段加上log_bin_trust_function_creators=1
  1. mysql终端窗口function与procedure的建立
通常见到“;”系统会认为sql命令行结束,此时语法是
delimiter //   --》注意//前有空格 把分隔符改成双杠,这样到中间 FROM T的时候mysql不会认为SQL命令已经结束了;
CREATE PROCEDURE p()
BEGIN
  SELECT * FROM T;
END;//

delimiter ;--》把分隔符再改回来
  1. MYSQL的root账户被删掉了处理
停止mysql
# /etc/init.d/mysqld stop
安全模式进入mysql
# /usr/sbin//mysqld_safe  --skip-grant-tables &
完成以后就可以不用密码进入MySQL了
# mysql -u root 

建立 root 用户:
> insert into mysql.user (host, user, password) values ('localhost', 'root', password('密码'));
> flush privileges;
> grant all on *.* to 'root'@'localhost' WITH GRANT OPTION
更新root密码:
#mysql5.5
> update MySQL.user set password=PASSWORD('新密码') where User='root';
#mysql5.7

vim /etc/my.cnf
在[mysqld]中添加
skip-grant-tables

> use mysql;
> update user set authentication_string=PASSWORD('newpassword') where User='root';
  1. mysql CPU占用过高
检查慢查询日志 看看是否有sql执行时间过长或者没有索引
在mysql命令行下执行show processlist;来查看是否有长时间执行的sql,如果经常出现copying to tmp table on disk
修改/etc/my.inf
tmp_table_size=512M
max_heap_table_size=512M
  1. [Err] 1055 ORDER BY clause is not in GROUP BY clause
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION