MySQL 安裝過(guò)程中踩過(guò)的坑
1、用 grep 'temporary password' /var/log/mysqld.log 生成的初始密碼老提示密碼錯(cuò)誤,只能直接發(fā)大招:
A、vi /etc/my.cnf 在文件的 [mysqld] 內(nèi)增加一行 skip_table_grant_tables
B、 重啟mysql: systemctl restart mysqld.service
C、無(wú)密碼登錄mysql: mysql -uroot
D、執(zhí)行: flush privileges; (注:如未執(zhí)行,后續(xù)的 alter user 更新密碼會(huì)報(bào):The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement)
E、更新用戶密碼: alter user 'root'@'localhost' identified by '123456'; (注:此處密碼是123456)
(MySQL的默認(rèn)密碼規(guī)則比較復(fù)雜,可執(zhí)行:set global validate_password.length=6 等操作修改設(shè)置值,以降低復(fù)雜度)
F、執(zhí)行: flush privileges; 并退出 mysql
G、vi /etc/my.cnf 在文件的 [mysqld] 內(nèi)取消 skip_table_grant_tables
H、重啟mysql: systemctl restart mysqld.service
2、Linux系統(tǒng)上的MySQL默認(rèn)表名、列名大小敏感,不能按網(wǎng)上說(shuō)的直接在 /etc/my.cnf 內(nèi)設(shè)置 lower_case_table_names=1, 會(huì)導(dǎo)致MySQL無(wú)法啟動(dòng)。
3、安裝后無(wú)法遠(yuǎn)程連接。一般是以下兩個(gè)原因?qū)е?
A、mysql的登錄用戶主機(jī)是本地,可通過(guò) update user set Host='%' where User = '登錄名', 修改
B、檢查服務(wù)器防火墻的3306端口是否開(kāi)啟,如未開(kāi)啟,則打開(kāi)。對(duì)應(yīng)操作命令如下:
1) 查詢端口狀態(tài): firewall-cmd --query-port=3306/tcp
2) 查詢防火墻狀態(tài): service firewalld status
3) 設(shè)置端口開(kāi)啟: firewall-cmd --permanent --zone=public --add-port=3306/tcp
firewall-cmd --reload
C、reboot 重啟服務(wù)器
浙公網(wǎng)安備 33010602011771號(hào)