MySQL笔记

#忘记原始密码
1、修改 /etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1
2、重启mysql:service restart stop
3、刷新权限:flush privileges;
4、修改密码:alter user root@localhost identified by 'Kgj@2019';
若报错:ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
改为:alter user 'root'@'%' identified by 'Kgj@2019';

mysql清除日志信息
删除日志:输入mysql -u root -p然后输入密码
mysql> reset master;
关闭日志功能:(需先在命令行删除日志)找到配置文件my.cnf,对于linux,一般默认在/etc目录下,打开此文件,使用井号(#)注释掉如下两个配置项目即可。
log-bin=mysql-bin
binlog_format=mixed
修改前需要先关闭数据库:service mysqld stop
修改后需要重启:service mysql start /restart

mysql后台启动,守护线程自动检测:/usr/bin/mysqld_safe &
mysql关闭:mysqladmin -uroot -pkgj123 shutdown

Mysql异常

一、Mysql : ERROR 1030 (HY000): Got error 134 from storage engine
① 内存满,清理内存空间
② REPAIR TABLE member;

/etc/init.d/mysql.server stop
1.[root@localhost XsocketFEP_V2]# mysql -uroot -pkgj123
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
无法重启
解决办法: /usr/bin/mysqld_safe &
重启正常
解决办法: 创建一个空的/var/lib/mysql/mysql.sock文件(或删除这个文件)
且权限设为777
2.Caused by: java.sql.SQLException: Table '表名' is marked as crashed and should be repaired
解决办法:
./myisamchk -c -r 数据库表MYI文件的路径(例如:/home/mysql/var/crawlerfeedsky/aaaa.MYI)
如果还不行,就-f 强制修复

mysql> delete from V_BaseSchedule where F_Guid='111703';
ERROR 126 (HY000): Incorrect key file for table './db_kgj/V_BaseSchedule.MYI'; try to repair it
或:java.sql.SQLException: Got error 134 from storage engine
解决办法:
可以先运行 CHECK TABLE 表名 检查下是否存在错误。
然后运行 REPAIR TABLE 表名 进行修复。

3.mysql乱码
解决办法:
vim my.cnf
在[client]和[mysqld]下面都添加上
default-character-set=utf8
4.mysql禁止日志
mysql -uroot -pkgj123
> reset master;
vim /etc/my.cnf把里面的
#log-bin=mysql-bin
#binlog_format=mixed
注释掉
4.java.sql.SQLException: Table 'V_Schedule' is marked as crashed and should be repaired
解决办法:
/usr/bin/myisamchk -c -r /var/lib/mysql/db_kgj/V_Schedule.MYI

5.mysql修改root密码mysqladmin -uroot -p'1234567' password '123456'

你可能感兴趣的:(MySQL笔记)