Linux環境——MySQL安裝及配置(5.7版本)
數據庫安裝包下載地址:https://dev.mysql.com/downloads/mysql/
我的環境是Linux Red Hat Enterprlse Linux (64位),本次安裝的是Mysql 5.7版本。
說一下安裝中經歷的坎坷,開始虛擬機中有默認版本5.1,版本太老,不適用了,然後從網上看教程,需要刪除已存在的,好吧,刪吧!完事後,正常下載新的版本,當時選擇的是最高版本8.0的,下載、安裝都完成後,懵逼了,以為和windows上一樣,直接在當前文件夾就能找到mysql的安裝後的文件,其實並木有,中間找的過程省略,然後碰到和之前的版本沖突、mysql.sock異常、mysqld文件不存在等問題,重新卸載安裝,還會出現部分文件(mysql-community-server-8··)刪除不了、mysql_install_db文件不存在各種各種,這中間的百度、必應的找方法解決也是很揪心,說了這麽多,說一下終極的解決問題之道吧!——卸載幹凈再重新安裝——(是的,我還重啟虛擬機,o(╥﹏╥)o)
你可能會問,之前安裝的8版本為什麽又換到了5.7版本,因為我懷疑最新版本不兼容,然後,其實5.7也是夠用的,還有就是查看部分博客,最新版好像同低版本不連通。總而言之,換成5.7版本成功了!
查看原有版本:rpm -qa|grep mysql
[[email protected] mysql]# rpm -qa|grep mysql mysql-community-common-5.7.25-1.el6.x86_64 mysql-community-client-5.7.25-1.el6.x86_64 mysql-community-libs-compat-5.7.25-1.el6.x86_64 mysql-community-server-5.7.25-1.el6.x86_64 mysql-community-libs-5.7.25-1.el6.x86_64 [[email protected] mysql]#
這裏可以看到存在mysql,版本是5.7的。看到這裏,你決定是否刪除原有版本,如果不刪除,就跳過;刪除的會繼續~~
- 刪除/卸載原有版本:
1、rpm 卸載操作
rpm -ev mysql-community-server-5.7.25-1.el6.x86_64 #rpm -e 後面接卸載的包名,rpm -ev 能看到卸載的詳情rpm -ev --nodeps mysql-community-server-5.7.25-1.el6.x86_64 #可忽略依賴關系進行卸載
這裏補充一點,如果部分文件無法刪除, 又找不到解決方法,可以試試先把文件重新安裝一次,再進行卸載,親試可用!
2、刪除其他相關文件
whereis mysql #查找相關的文件及路徑 find / -name mysql #查找相關的文件及路徑 rm -rf /usr/local/mysql #rm -rf 後接要刪除的文件路徑
- 下載安裝新版本:
1、新建mysql文件:
mkdir /usr/local/mysql/ #在/usr/local 路徑下新建mysql文件夾
2、下載 【 mysql-5.7.25-1.el6.x86_64.rpm-bundle.tar 】到mysql文件夾中,然後進行解壓操作,能得到rpm安裝包。
解壓命令:
tar -xvf XXX.tar
[[email protected] mysql]# ls mysql-5.7.25-1.el6.x86_64.rpm-bundle.tar mysql-community-client-5.7.25-1.el6.x86_64.rpm mysql-community-common-5.7.25-1.el6.x86_64.rpm mysql-community-devel-5.7.25-1.el6.x86_64.rpm mysql-community-embedded-5.7.25-1.el6.x86_64.rpm mysql-community-embedded-devel-5.7.25-1.el6.x86_64.rpm mysql-community-libs-5.7.25-1.el6.x86_64.rpm mysql-community-libs-compat-5.7.25-1.el6.x86_64.rpm mysql-community-server-5.7.25-1.el6.x86_64.rpm mysql-community-test-5.7.25-1.el6.x86_64.rpm [[email protected] mysql]#
3、安裝rpm文件
rpm -ivh XXX.rpm #安裝文件
這裏特別註意的是,安裝順序,common——>libs——>libs-compat——>client——>server,其他的看個人需求,正常安裝這幾個就夠了。
4、啟動mysql服務
/etc/init.d/mysqld status #查看mysql啟動狀態 或者使用 service mysqld status /etc/init.d/mysqld start #啟動mysql服務 或者使用 service mysqld start
註意:用法:/etc/init.d/mysqld {start|stop|status|restart|condrestart|try-restart|reload|force-reload},service mysqld 同理。
[[email protected] ~]# /etc/init.d/mysqld start 初始化 MySQL 數據庫: [確定] 正在啟動 mysqld: [確定]
mysql 文件默認會安裝到【/var/lib/mysql】中,如下
[[email protected] mysql]# ls auto.cnf ca-key.pem client-key.pem ib_logfile0 #innodb_temp mysql.sock private_key.pem server-key.pem undo_002 binlog.000001 ca.pem ib_buffer_pool ib_logfile1 mysql mysql.sock.lock public_key.pem sys binlog.index client-cert.pem ibdata1 ibtmp1 mysql.ibd performance_schema server-cert.pem undo_001 [[email protected] mysql]#
5、訪問
默認密碼可以在文件 【/var/log/mysqld.log】 中獲取,命令:
tail -100f /var/log/mysqld.log
使用默認密碼進行登錄即可。安裝完成!!
[[email protected] ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.25 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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. mysql>
異常:
1、ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
由於是默認密碼登錄的,操作會提示需要先重置默認密碼後才能操作,可以先修改一個復雜的密碼過度,如:A1test!123
重置密碼命令:
alter user [email protected]‘localhost‘ identified by ‘新密碼‘;
生效密碼及退出:
flush privileges; #修改生效 exit; #退出
2、ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
不符合密碼規範,修改密碼規範,命令:
set global validate_password_policy=0; #設置全部參數validate_password_policy ,一般默認值是MEDIUM,需要滿足密碼規範,設置為0後就不需要了。 set global validate_password_length=4; #設置全局參數validate_password_length,一般默認值是8,即最少的密碼長度是8,設置為4,即最少的密碼長度為4.
Linux環境——MySQL安裝及配置(5.7版本)