CentOS7.4安裝MySQL踩坑記錄

來源:互聯網
上載者:User

標籤:python   blog   啟動mysql   查看   x86_64   清除   rm -rf   tar   cat   

CentOS7.4安裝MySQL踩坑記錄

time: 2018.3.19

CentOS7.4安裝MySQL時網上的文檔雖然多但是不靠譜的也多, 可能因為版本與時間的問題, 所以記錄下自己踩坑的過程, 如果你發現進坑了, 歡迎參考本篇文章:)

  • 第一次嘗試遇到的問題:

    Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)
嘗試卸載重新安裝, 參考, 步驟:

1.查看yum是否安裝過mysql
yum list installed mysql*
yum list installed | grep mysql*
沒有顯示結果, 說明yum中沒有安裝mysql(對yum與rpm並不是很瞭解, 如有錯誤歡迎指出)
2.刪除設定檔與檔案夾
rm -rf /var/lib/mysql
rm /etc/my.cnf
3.查看rpm中的安裝並卸載
rpm -qa | grep -i mysql
以下根據上面命令顯示的列表修改

rpm -e mysql-community-server-5.7.21-1.el7.x86_64 mysql-community-common-5.7.21-1.el7.x86_64 mysql-community-libs-5.7.21-1.el7.x86_64 mysql57-community-release-el7-11.noarch mysql-community-client-5.7.21-1.el7.x86_64  mysql-community-libs-compat-5.7.21-1.el7.x86_64 --nodeps

3.清除餘項
whereis mysql
刪除上面命令顯示的路徑
rm -rf /usr/share/mysql/
4.刪除配置
rm -rf /usr/my.cnf
rm -rf /root/.mysql*# 無結果

# 筆者機器上無結果chkconfig --list | grep -i mysqlchkconfig --del mysqldsystemctl list-dependencies | grep -i mysql
5.重新安裝

下載mysql源並安裝到rpm:

wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpmrpm -ivh mysql57-community-release-el7-11.noarch.rpm

更新yum並安裝mysql(時間較長):

# 更新yum軟體包yum check-update# 更新系統yum update# 安裝mysqlyum install mysql mysql-server

注意事項
更新yum後可能需要重新編輯/usr/bin/yum檔案頭(因為筆者將預設的python更改為python3), 編輯後再次安裝即可, 出現的錯誤如下:

[[email protected] ~]# yum install mysql mysql-server  File "/usr/bin/yum", line 30    except KeyboardInterrupt, e:                            ^SyntaxError: invalid syntax
安裝完成後配置

未跳過grant-tables授權表時啟動MySQL會出現:
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

這裡需要修改root的密碼, 這條命令是給mysql加上一個啟動參數--skip-grant-tables, 顧名思義,就是在啟動mysql時不啟動grant-tables授權表, 用於忘記管理員密碼後的修改
/usr/local/mysql/bin/mysqld_safe --skip-grant-tables --user=mysql &
但是, MySQL 5.7.6 版本開始預設是不安裝mysqld_safe了, 以下為新方法:
1.停止 mysql 服務
service mysqld stop
2.設定 mysqld 選項 --skip-grant-tables參數:
systemctl set-environment MYSQLD_OPTS=‘--skip-grant-tables‘
3.重新啟動mysql
systemctl start mysqld
4.執行 mysql -u root 登入mysql並更改密碼

[[email protected] ~]# mysql -urootWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.21 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> UPDATE mysql.user    -> SET authentication_string = PASSWORD(‘toor‘), password_expired = ‘N‘    -> WHERE User = ‘root‘ AND Host = ‘localhost‘;Query OK, 1 row affected, 1 warning (0.65 sec)Rows matched: 1  Changed: 1  Warnings: 1mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> 

password_expired = ‘N‘到期狀態設定為No, flush privileges; 重新整理許可權記錄, 詳見

5.設定完密碼後去掉--skip-grant-tables參數, 重啟mysql即可用設定的密碼登入root使用者
systemctl unset-environment MYSQLD_OPTS
systemctl restart mysqld
mysql -uroot -p

由於筆者代碼運行在伺服器系統上, 故不此設定mysql遠端存取

CentOS7.4安裝MySQL踩坑記錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.