報錯 [ERROR] --initialize specified but the data directory has files in it. Aborting. 解決方案:密碼初始化不成功 修改初始化密碼 方法一: # /etc/init.d/mysqld stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking & # mysql -u root mysql # mysql -u root mysql mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’; mysql> FLUSH PRIVILEGES; mysql> quit # /etc/init.d/mysqld restart # mysql -uroot -p Enter password: <輸入新設的密碼newpassword> mysql> 注意 【’newpassword’ ’root’ 】 ERROR 1054 (42S22): Unknown column '’root’' in 'where clause' 將單引號更新為雙引號
注意 【Password】 ERROR 1054 (42S22): Unknown column 'password' in 'field list' mysql> ERROR 1054 (42S22): Unknown column 'password' in 'field list' 錯誤原因:mysql數據庫下已經沒有password這個字段了,password字段改成了authentication_string。 update mysql.user set authentication_string=PASSWORD('password') where User='root';
3、啟動數據庫服務 MySQL Daemon failed to start. 服務啟動失敗 3.1、查看mysqld的log文件 # less /var/log/mysqld.log /usr/libexec/mysqld: Can't change dir to ‘XXX' (Errcode: 13) 3.2、首先是查看數據庫日志 mysqld started [Warning] Can't create test file xxx.lower-test [Warning] Can't create test file xxx.lower-test /usr/libexec/mysqld: Can't change dir to '/xxx' (Errcode: 13) [ERROR] Aborting 首先檢查數據目錄和日志目錄的權限和所屬用戶,權限和所屬用戶都沒問題,那應該是SELINUX的權限限制了。 3.3、先查看當前配置信息. # getenforce Enforcing 就表明SELinux已經啟用.只需要關閉即可。 關閉方法: #setenforce 0 (0|1 開|關) 或者 setsebool ftpd_disable_trans 1 命令也可以. 3.4、查查數據庫日志會出現 mysqld started 2018-04-17T03:48:30.343457Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root! 2018-04-17T03:48:30.345407Z 0 [ERROR] Aborting 錯誤:Please read "Security" section of the manual to find out how to run mysqld as root! 根據提示,查了 /opt/redmine-1.2.1-1/mysql/docs/mysql.info的Security部分,發現是因為MySQL為了安全,不希望root用戶直接啟動mysql。 解決方案 1、root用戶進行強制啟動;在啟動過程中,加入參數:--user=root 【service mysqld start --user=root】 2、修改 /etc/init.d/mysqld 137 $exec $MYSQLD_OPTS --datadir="$datadir" --socket="$socketfile" / --pid-file="$mypidfile" / --basedir=/usr --user=mysql $extra_opts >/dev/null & safe_pid=$! 將mysql 更新為 root
4、登錄數據庫報錯ERROR 1820 (HY000): You must reset your password using ALTER USER statement befo re executing this statement.直接執行: set password=password('密碼');
5、遠程登錄報錯 Host is not allowed to connect to this MySQL server先說說這個錯誤,其實就是我們的MySQL不允許遠程登錄,所以遠程登錄失敗了, 解決方法如下: 1. 在裝有MySQL的機器上登錄MySQL mysql -u root -p密碼 2. 執行use mysql; 3. 執行update user set host = '%' where user = 'root';這一句執行完可能會報錯,不用管它。 4. 執行FLUSH PRIVILEGES; 經過上面4步,就可以解決這個問題了。