CentOS 7.4下使用yum安裝MySQL5.7.20 最簡單的 (引用)

來源:互聯網
上載者:User

標籤:重設密碼   預設   pool   img   解決   mariadb   https   ram   oar   

引用 78906598

CentOS7預設資料庫是mariadb, 但是 好多用的都是mysql ,但是CentOS7的yum源中預設好像是沒有mysql的。

上一篇安裝的是5.6的但是我想安裝5.7的  yum安裝是最簡單的 嘗試過編譯安裝各種問題,最後就決定用yum。

1.卸載  先停掉mysql進程   沒有安裝過的可以直接跳過

        pkill -9 mysqld

        

       rpm -qa|grep -i mysql

             

      用命令 yum -y remove

      yum -y remove mysql-community-client-5.6.38-2.el7.x86_64

      卸載不掉的用 rpm -ev 

      依次卸載 直到沒有

      

2.下載mysql的repo源 這個安裝的mysql5.7.20

   [[email protected] ~]# cd /usr/local/src/
   [[email protected] src]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 

   [[email protected] src]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm 

   [[email protected] src]#  yum -y install mysql-server 

(也可以指定安裝目錄     yum --installroot=/usr/local/mysql --releasever=/ -y install mysql-server  )我沒試,這樣裝環境變數配置都不用你管,裝上直接啟動就行。安裝路徑是預設的。

     

   一路 y 

根據步驟安裝就可以了,

預設設定檔路徑: 
設定檔:/etc/my.cnf 
記錄檔:/var/log/var/log/mysqld.log 
服務啟動指令碼:/usr/lib/systemd/system/mysqld.service 
socket檔案:/var/run/mysqld/mysqld.pid

 

  配置  my.cnf        vim /etc/my.cnf

[sql] view plain copy 
  1. [mysqld]  
  2. #  
  3. # Remove leading # and set to the amount of RAM for the most important data  
  4. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.  
  5. # innodb_buffer_pool_size = 128M  
  6. #  
  7. # Remove leading # to turn on a very important data integrity option: logging  
  8. # changes to the binary log between backups.  
  9. # log_bin  
  10. #  
  11. # Remove leading # to set options mainly useful for reporting servers.  
  12. # The server defaults are faster for transactions and fast SELECTs.  
  13. # Adjust sizes as needed, experiment to find the optimal values.  
  14. # join_buffer_size = 128M  
  15. # sort_buffer_size = 2M  
  16. # read_rnd_buffer_size = 2M  
  17. datadir=/var/lib/mysql  
  18. socket=/var/lib/mysql/mysql.sock  
  19. server_id = 1  
  20. expire_logs_days = 3  
  21.   
  22. # Disabling symbolic-links is recommended to prevent assorted security risks  
  23. symbolic-links=0  
  24.   
  25. log-error=/var/log/mysqld.log  
  26. pid-file=/var/run/mysqld/mysqld.pid  

 

不過安裝完成後,密碼為隨機密碼,需要重設密碼。

 

4.  啟動mysql服務

service mysqld restart

 重設密碼

    [[email protected] ~]# grep "password" /var/log/mysqld.log    

    

    可以看到  輸入 mysql -u root -p   密碼 進入      第一次登陸 ,需要重設密碼 要不什麼也不能操作 

        

       接下來重設密碼:5.7.20 為了安全密碼           必須包含 數字字母符號

      踩過的坑啊,設定了好幾次。還有這ip不能是% 不知道為什麼  反正第一次設定成%沒成功  登上去之後再改就可以改了。

       把密碼改簡單的方法 http://blog.csdn.net/z13615480737/article/details/78907697

      alter user ‘root‘@‘localhost‘ identified by ‘Root!!2018‘;  

     最後記得重新整理許可權;

     flush privileges 

    也可以 直接再添加新使用者     

    CREATE USER ‘root‘@‘%‘ IDENTIFIED BY ‘您的密碼‘;

    grant all on *.* to ‘root001‘@‘%‘ identified by ‘[email protected]@‘  with grant option;

   增加root使用者指定可以任意IP登入,如果想限制只能讓指定IP登入請把%替換成IP地址

 

   問題:如果發現找不到密碼!!!!!

   解決:只能通過忘記密碼的方式修改密碼!!! 在安裝的過程中發現找不到密碼???折騰了好長時間 通過修改密碼找回之後發現、原來之前安裝的資料庫在了,就沒有生產新的資料庫!!用的還是之前的配置。

2.看mysql啟動了沒?初始化資料庫了沒?  一般直接啟動 資料庫 就可以 用grep "password" /var/log/mysqld.log    看到隨機密碼了

 

修改MySQL的登入設定: #vi /etc/my.cnf在[mysqld]的段中加上一句:skip-grant-tables 儲存並且退出vi。重新啟動mysqld
重新啟動mysqld
#/etc/init.d/mysqld restart ( service mysqld restart )
use mysql 
update user set password=password("12345") where user="root";
mysql 5.7的資料庫沒有了password欄位 用的是authentication_string欄位
mysql> update mysql.user set authentication_string=password(‘root‘) where user=‘root‘ ;
flush privileges;
修改密碼之後在改回來

 

CentOS 7.4下使用yum安裝MySQL5.7.20 最簡單的 (引用)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.