centos7 安裝mysql數據庫 及常見問題解決辦法

一、配置YUM源html

下載mysql源安裝包

shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpmmysql

安裝mysql源

shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm 

檢查MySQL源是否安裝成功 

shell> yum repolist enabled | grep 「mysql.-community.」 sql

二、安裝MySQL 

shell> yum install mysql-community-server 

三、啓動MySQL服務 

shell> systemctl start mysqld 

查看MySQL的啓動狀態 

shell> systemctl status mysqldshell

四、開機啓動 

shell> systemctl enable mysqld 

shell> systemctl daemon-reload數據庫

五、修改root本地登陸密碼 

grep ‘temporary password’ /var/log/mysqld.log 

mysql -uroot –p+生產注意:mysql5.7默認安裝了密碼安全檢查插件(validate_password),默認密碼檢查策略要求密碼必須包含:大小寫字母、數字和特殊符號,而且長度不能少於8位。不然會提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements錯誤,以下圖所示:centos

第一次經過命令行窗口登陸MySQL5.7時出現ERROR 1045 (28000): Access denied for user 'root'@'localhost'
  1. 打開etc/my.cnf文件,在文件的最後添加一行「skip-grant-tables」,保存並關閉文件。(Win10默認安裝,my.ini在C:\ProgramData\MySQL\MySQL Server 5.7)
  2. 重啓MySQL57和MySQL Router服務。
  3. 經過命令行窗口進入MySQL的bin目錄,輸入「mysql -u root -p」(不輸入密碼),回車便可進入數據庫。(Win10默認安裝,bin目錄爲:C:\Program Files\MySQL\MySQL Server 5.7\bin)
  4. 執行「use mysql」,使用MySQL數據庫。
  5. 執行「 update user set authentication_string=PASSWORD("此處請輸入您要設定的密碼") where user='root';」                            注意密碼格式:至少包含一個大寫字母、一個小寫字母、一個特殊符號、一個數字,密碼長度至少爲8個字符。
  6. 打開MySQL目錄下的my.ini文件,刪除最後一行的「skip-grant-tables」,保存並關閉文件。
  7. 重啓MySQL57和MySQL Router服務。
  8. 在命令行中輸入「mysql -u root -p」,回車,而後輸入您設置的密碼便可成功鏈接數據庫。

 


六、添加遠程登陸用戶 

默認只容許root賬戶在本地登陸,若是要在其它機器上鍊接mysql,必須修改root容許遠程鏈接,或者添加一個容許遠程鏈接的賬戶, 

mysql> GRANT ALL PRIVILEGES ON . TO ‘*’@’ localhost’ IDENTIFIED BY ’ MyNewPass4!’ WITH GRANT OPTION;安全

GRANT ALL PRIVILEGES ON . TO ‘*’@’ Spark’ IDENTIFIED BY ’ MyNewPass4!’ WITH GRANT OPTION;socket

七、配置默認編碼爲utf8ide

修改/etc/my.cnf配置文件,在[mysqld]下添加編碼配置,以下所示: 

[mysqld] 

character_set_server=utf8 

init_connect=’SET NAMES utf8’post

常見問題:

1.ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this ..

解決:首先修改用戶的密碼。(下面兩個命令一個意思,任選其一便可)

     alter user 'root'@'localhost' identified by 'youpassword';  
      
     set password=password("youpassword");

    而後在刷新權限。

     flush privileges;

2.MySQ修改密碼報錯ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

解決:

  1. set global validate_password_policy=0;
  2. set global validate_password_mixed_case_count=0;
  3. set global validate_password_number_count=3;
  4. set global validate_password_special_char_count=0;
  5. set global validate_password_length=3;
  6. 解決 ok;

默認配置文件路徑:  

配置文件:/etc/my.cnf  

日誌文件:/var/log//var/log/mysqld.log  

服務啓動腳本:/usr/lib/systemd/system/mysqld.service  

socket文件:/var/run/mysqld/mysqld.pid

轉發自:https://www.centoschina.cn/server/sql/mysql/8661.html

相關文章
相關標籤/搜索