CentOS 7 下使用yum安裝MySQL5.7.20

CentOS7默認數據庫是mariadb, 可是 好多用的都是mysql ,可是CentOS7的yum源中默認好像是沒有mysql的。java

1.卸載  先停掉mysql進程   沒有安裝過的能夠直接跳過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  /**糾正一下,這源下載的是最新的版本  ****/sql

   [root@localhost ~]# cd /usr/local/src/
   [root@localhost src]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 數據庫

   [root@localhost src]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm vim

   [root@localhost src]#  yum -y install mysql-server 安全

(也能夠指定安裝目錄     yum --installroot=/usr/local/mysql --releasever=/ -y install mysql-server  )我沒試,這樣裝環境變量配置都不用你管,裝上直接啓動就行。安裝路徑是默認的。socket

    

   一路 y tcp

 

根據步驟安裝就能夠了,ide

默認配置文件路徑: 
配置文件:/etc/my.cnf 
日誌文件:/var/log/var/log/mysqld.log 
服務啓動腳本:/usr/lib/systemd/system/mysqld.service 
socket文件:/var/run/mysqld/mysqld.pid.net

 

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

  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

 重置密碼

    [root@localhost ~]# 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 

    也能夠 直接再添加新用戶     

   

 

 

1. iptables放開3306端口

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

/etc/rc.d/init.d/iptables save

2.本地登陸mysql,在'mysql'這個數據庫裏執行GRANT ALL ON *.* to user@'IP' IDENTIFIED BY 'password';  其中,user表示用戶,對我來講就是root,IP表示登陸機器的ip,因爲個人電腦是DHCP,就直接寫了個通配符%. password該用戶對應的密碼. 

因此個人命令就是grant all privileges on *.* to 'root'@'%' identified by '*****' with grant option;

增長root用戶指定能夠任意IP登陸,若是想限制只能讓指定IP登陸請把%替換成IP地址

 

3.執行如下這個,FLUSH PRIVILEGES; 否則可能會有問題. 

4.重啓mysql, service mysqld restart. 

 

 

   

 

   問題:若是發現找不到密碼!!!!!

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

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; 修改密碼以後在改回來

相關文章
相關標籤/搜索