一:mysql忘記密碼:
killall -TERM mysqld
mysqld_safe --user=root --skip-grant-tables &
mysql -u root
use mysql
update user set password=password("new_pass") where user="root";
MySQL5.7修改方法: update mysql.user set authentication_string=password('new_pass') where user='root' ;
flush privileges;
二、ERROR 2002 (HY000): Can't connect to local MySQL server through socket'/tmp/mysql.sock' (111)
1、[root@localhost ~]# find /-name mysql.sock
/var/lib/mysql/mysql.sock
創建符號連接:
ln -s/var/lib/mysql/mysql.sock /tmp/mysql.sock
2、vi /etc/my.conf
檢查下行內容是否存在:
[client]
socket=/tmp/mysql.sock
三、mysql找不到mysql.sock或文件爲空,查看日誌如下:
[ERROR] Can't start server: Bind on TCP/IP port:Cannot assign requested address
[ERROR] Do you already have another mysqld server running on port: 3306 ?
[ERROR] Aborting
提示是端口可能被佔用,於是執行:
greatmoo:~# netstat -anp |grep "3306"
vi /etc/my.cnf,把port改成3307:
greatmoo:~# vi/etc/mysql/my.cnf
[client]
port = 3307
# …
[mysqld]
port = 3307
# …
準備保存後啓動mysql,再啓動 mysql 就成功了
四、ERROR 1045 (28000): Access denied for user ’root’@’localhost’ (usingpassword: NO)
方法一:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD(’newpassword’) whereUSER=’root’;
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <輸入新設的密碼newpassword>
mysql>
方法二:
直接使用/etc/mysql/debian.cnf文件中[client]節提供的用戶名和密碼:
# mysql -udebian-sys-maint -p
Enter password: <輸入[client]節的密碼>
mysql> UPDATE user SET Password=PASSWORD(’newpassword’) whereUSER=’root’;
mysql> FLUSH PRIVILEGES;
mysql> quit
# mysql -uroot -p
Enter password: <輸入新設的密碼newpassword>
mysql>
方法三:
這種方法我沒有進行過測試,因爲我的root用戶默認密碼已經被我修改過了,那位有空測試一下,把結果告訴我,謝謝!
# mysql -uroot -p
Enter password: <輸入/etc/mysql/debian.cnf文件中[client]節提供的密碼>
最後注意:別忘了關閉防火牆,免得外網無法訪問該主機的數據庫端口。
五、啓動報錯:File './mysql-bin.index'not found (Errcode: 13)
1、errcode13,一般就是權限問題,mysql用戶是否對數據庫目錄內的所有文件具有寫的權限,查看一下權限
2、chown mysql.mysql -R < mysql-bin.index所在的目錄>
六、mysql主從庫同步錯誤:1062 Error'Duplicate entry '1438019' for key 'PRIMARY'' on query
1、解決的辦法是在從庫上執行:
mysql> slave stop;
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
mysql> slave start;
2、修改mysql的配置文件,讓從庫的同步線程忽略這個錯誤,方法:
修改mysql配置文件 /etc/my.cnf 在 [mysqld]下加一行 slave_skip_errors = 1062 ,保存.重啓mysql. mysql slave可以正常同步了.
七、mysql主從庫同步錯誤:Got fatalerror 1236 from master when reading data from binary log
在source(主)那邊,執行:
flush logs;
show master status;
記下File, Position。
在target(從)端,執行:
CHANGE MASTER TOMASTER_LOG_FILE='testdbbinlog.000008',MASTER_LOG_POS=107;
slave start;
show slave status \G
一切正常。