CentOS安装Mysql8各种坑。。。
一、下載MySQL安裝包
1、打開MySQL官網https://www.mysql.com/downloads/
2、選擇MySQL Community (GPL) Downloads ?
3、選擇MySQL Yum Repository
4、選擇Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package,點擊DownLoad
5、跳轉到登錄頁面,點擊下方No thanks, just start my download.
二、安裝
1、查詢是否安裝了mysql
2、 卸載mysql (下面是卸載mysql的庫,防止產生沖突,mysql也是類似卸載方式)
rpm -e --nodeps mysql-libs-5.1.*卸載之后,記得:
find / -name mysql刪除查詢出來的所有東西
3、將下載好的rpm文件上傳到CentOS服務器上
4、輸入以下命令開始安裝
yum localinstall mysql80-community-release-el7-3.noarch.rpm完畢后繼續執行以下命令
yum install mysql-community-server這里有一個坑:Error: Unable to find a match: mysql-community-server
解決:
方法鏈接
5、安裝完畢,啟動mysql服務
service mysqld start6、查看mysql服務是否啟動成功
ps -ef|grep mysql7、這里有第二個坑,因為不想以3306端口運行Mysql,所以改了默認端口,改完啟動Mysql時遇到了
130823 17:21:14 [ERROR] Can't start server: Bind on TCP/IP port: Permission denied 130823 17:21:14 [ERROR] Do you already have another mysqld server running on port: 806最終我通過這命令解決:
setenforce 0其他解決方法鏈接
我在這里才明白有SELinux這玩意,孤陋寡聞,以后補上
三、修改密碼
1、查詢MySQL的臨時密碼
grep ‘temporary password’ /var/log/mysqld.log
2、復制臨時密碼,然后登錄MySQL
mysql -uroot -p
輸入臨時密碼
3、修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';然后刷新權限
flush privileges;4、使用新密碼重新登錄
四、創建新用戶
create user '你的用戶名'@'%' identified with mysql_native_password by '你的密碼';刷新權限
grant all on *.* to '你的用戶名'@'%';這里需要特別注意:mysql8跟之前就版本的新增用戶方式和授權方式已經改變
創建用戶的操作已經不支持grant的同時創建用戶的方式,需先創建用戶再進行授權
mysql> grant all on *.* to 'admin'@'%' identified by 'admin123'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'admin123'' at line 1 mysql> create user 'admin'@'%' identified by 'admin123'; Query OK, 0 rows affected (0.06 sec)mysql> grant all on *.* to 'admin'@'%' ; Query OK, 0 rows affected (0.04 sec)mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)當用戶密碼含有字母或數字外的特殊符號登錄時,原先使用雙引號或單引號都可以登錄,但在mysql8.0登錄時遇到問題,如下
[root@gjc18 lib]# /usr/local/mysql8.0/bin/mysql -uroot -p"root!@#123" --socket=/data/mysql/mysql3310/tmp/mysql3310.sock -bash: !@#123": event not found [root@gjc18 lib]# /usr/local/mysql8.0/bin/mysql -uroot -p'root!@#123' --socket=/data/mysql/mysql3310/tmp/mysql3310.sock mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 22 Server version: 8.0.12 MySQL Community Server - GPL3.低版本客戶端登錄異常
錯誤號碼 2058:Plugin caching_sha2_password could not be loaded
出現這個原因是mysql8.0 之前的版本中加密規則是mysql_native_password,而在mysql8之后,加密規則是caching_sha2_password, 解決此問題方法有兩種,一種是升級客戶端驅動,一種是把mysql用戶登錄密碼加密規則還原成mysql_native_password。
如果修改用戶密碼加密規則可使用如下方式:
1). 修改加密方式:
-- 修改密碼為用不過期 mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.02 sec)-- 修改密碼并指定加密規則為mysql_native_password mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; Query OK, 0 rows affected (0.01 sec)-- 刷新權限 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)mysql>修改完畢后再次登錄即可成功
2).使用高版本客戶端
linux低版本客戶端登錄時也會出現此情況,因此需使用高版本的客戶端
[root@gjc18 lib]# mysql -uroot -p'123456' --socket=/data/mysql/mysql3310/tmp/mysql3310.sock mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/local/mysql/lib/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory [root@gjc18 lib]# /usr/local/mysql8.0/bin/mysql -uroot -p'123456' --socket=/data/mysql/mysql3310/tmp/mysql3310.sock mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 26 Server version: 8.0.12 MySQL Community Server - GPLCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.除了密碼插件調整外,MySQL8.0其他幾個主要的新密碼策略有:
- 支持密碼過期策略,需要周期性修改密碼
- 增加歷史密碼校驗機制,防止近幾次的密碼相同(次數可以配置)
- 修改密碼是需要驗證舊密碼,防止被篡改風險
- 支持雙密碼機制,即新密碼與修改前的舊密碼同時可以使用,且可以選擇采用主密碼還是第二個密碼
- 增加密碼強度約束,避免使用弱密碼
1、vim /etc/my.cnf,添加 skip-grant-tables(跳過權限驗證)
2、重啟 mysql 服務
3、mysql 登錄:mysql -uroot -p(無需密碼)
4、將root密碼置空
5、flush privileges;
6、修改root密碼(8.0之后和之前的方式不一樣,一下為8.0)
7、vim /etc/my.cnf,刪除 skip-grant-tables
8、再次重啟 mysql 服務
9、使用新密碼登錄 mysql
轉自
本文轉自
總結
以上是生活随笔為你收集整理的CentOS安装Mysql8各种坑。。。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 再好的产品经理跑不过一半的A/B测试
- 下一篇: 中国无线经济白皮书