您好,登錄后才能下訂單哦!
這篇文章主要講解了“Linux下安裝MySQL5.7的步驟”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Linux下安裝MySQL5.7的步驟”吧!
本次將在Linux下通過yum安裝MySQL,安裝的版本為MySQL 5.7,官網中是最新版本8.0,在網上查了下,發現最新版本的yum源也包含了舊版本,而我們,只需要在安裝時啟用 5.7 的安裝即可。
本人環境:CentOS 7.3 64位
1.檢查CentOS是否有系統自帶的mysql
yum list installed | grep mysql
如果存在系統自帶的mysql及依賴,則通過 yum remove
將其卸載
2.在官網中獲取yum源
這里獲取到的是最新版本的下載地址: https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
3.CentOS中下載rpm包,并安裝本地mysql源
下載rpm包:wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm --no-check-certificate
安裝mysql源:yum localinstall mysql80-community-release-el7-3.noarch.rpm
通過 yum localinstall
安裝mysql源,可以幫助我們解決本地rpm包的依賴問題。
最后,驗證是否安裝成功:yum repolist all | grep mysql
4.修改默認安裝版本為5.7
從上面的圖片,我們可以看到,默認是MySQL 8.0可用,我們若想安裝MySQL 5.7,則需啟用5.7。接下來通過直接修改配置文件來設置啟用。
vim /etc/yum.repos.d/mysql-community.repo
輸入上面的命令,在編輯界面,先輸入 i
進入編輯模式,將8.0的 enabled 設置為0,將5.7的 enabled 設置為1,如下:
接著按 Esc
退出編輯模式,最后輸入 :wq
保存并退出。
再次輸入命令:yum repolist all | grep mysql
,可以看到8.0已被禁用,而5.7是啟用的。
5.安裝MySQL
yum install mysql-community-server
輸入上面命令,進行安裝即可。
點我復制[root@wintest mysql]# yum install mysql-community-server Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies--> Running transaction check---> Package mysql-community-server.x86_64 0:5.7.27-1.el7 will be installed--> Processing Dependency: mysql-community-common(x86-64) = 5.7.27-1.el7 for package: mysql-community-server-5.7.27-1.el7.x86_64--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.27-1.el7.x86_64--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: mysql-community-server-5.7.27-1.el7.x86_64--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: mysql-community-server-5.7.27-1.el7.x86_64--> Processing Dependency: libaio.so.1()(64bit) for package: mysql-community-server-5.7.27-1.el7.x86_64--> Running transaction check---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed---> Package mysql-community-client.x86_64 0:5.7.27-1.el7 will be installed--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.27-1.el7.x86_64---> Package mysql-community-common.x86_64 0:5.7.27-1.el7 will be installed--> Running transaction check---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be obsoleted--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64---> Package mysql-community-libs.x86_64 0:5.7.27-1.el7 will be obsoleting--> Running transaction check---> Package mysql-community-libs-compat.x86_64 0:5.7.27-1.el7 will be obsoleting---> Package postfix.x86_64 2:2.10.1-6.el7 will be updated---> Package postfix.x86_64 2:2.10.1-7.el7 will be an update--> Finished Dependency ResolutionDependencies Resolved ==================================================================================== Package Arch Version Repository Size ==================================================================================== Installing: mysql-community-libs x86_64 5.7.27-1.el7 mysql57-community 2.2 M replacing mariadb-libs.x86_64 1:5.5.52-1.el7 mysql-community-libs-compat x86_64 5.7.27-1.el7 mysql57-community 2.0 M replacing mariadb-libs.x86_64 1:5.5.52-1.el7 mysql-community-server x86_64 5.7.27-1.el7 mysql57-community 165 M Installing for dependencies: libaio x86_64 0.3.109-13.el7 base 24 k mysql-community-client x86_64 5.7.27-1.el7 mysql57-community 24 M mysql-community-common x86_64 5.7.27-1.el7 mysql57-community 275 k Updating for dependencies: postfix x86_64 2:2.10.1-7.el7 base 2.4 M Transaction Summary ==================================================================================== Install 3 Packages (+3 Dependent packages) Upgrade ( 1 Dependent package) Total download size: 197 MIs this ok [y/d/N]: y Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. (1/7): libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00:00 warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.27-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Public key for mysql-community-common-5.7.27-1.el7.x86_64.rpm is not installed (2/7): mysql-community-common-5.7.27-1.el7.x86_64.rpm | 275 kB 00:00:01 (3/7): mysql-community-libs-5.7.27-1.el7.x86_64.rpm | 2.2 MB 00:00:01 (4/7): mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm | 2.0 MB 00:00:01 (5/7): postfix-2.10.1-7.el7.x86_64.rpm | 2.4 MB 00:00:00 (6/7): mysql-community-client-5.7.27-1.el7.x86_64.rpm | 24 MB 00:00:34 (7/7): mysql-community-server-5.7.27-1.el7.x86_64.rpm | 165 MB 00:00:52 ------------------------------------------------------------------------------------Total 3.5 MB/s | 197 MB 00:56 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Importing GPG key 0x5072E1F5: Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5 Package : mysql80-community-release-el7-3.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlIs this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mysql-community-common-5.7.27-1.el7.x86_64 1/9 Installing : mysql-community-libs-5.7.27-1.el7.x86_64 2/9 Installing : mysql-community-libs-compat-5.7.27-1.el7.x86_64 3/9 Installing : mysql-community-client-5.7.27-1.el7.x86_64 4/9 Installing : libaio-0.3.109-13.el7.x86_64 5/9 Installing : mysql-community-server-5.7.27-1.el7.x86_64 6/9 Updating : 2:postfix-2.10.1-7.el7.x86_64 7/9 Cleanup : 2:postfix-2.10.1-6.el7.x86_64 8/9 Erasing : 1:mariadb-libs-5.5.52-1.el7.x86_64 9/9 Verifying : mysql-community-libs-compat-5.7.27-1.el7.x86_64 1/9 Verifying : mysql-community-common-5.7.27-1.el7.x86_64 2/9 Verifying : mysql-community-libs-5.7.27-1.el7.x86_64 3/9 Verifying : 2:postfix-2.10.1-7.el7.x86_64 4/9 Verifying : mysql-community-server-5.7.27-1.el7.x86_64 5/9 Verifying : mysql-community-client-5.7.27-1.el7.x86_64 6/9 Verifying : libaio-0.3.109-13.el7.x86_64 7/9 Verifying : 1:mariadb-libs-5.5.52-1.el7.x86_64 8/9 Verifying : 2:postfix-2.10.1-6.el7.x86_64 9/9 Installed: mysql-community-libs.x86_64 0:5.7.27-1.el7 mysql-community-libs-compat.x86_64 0:5.7.27-1.el7 mysql-community-server.x86_64 0:5.7.27-1.el7 Dependency Installed: libaio.x86_64 0:0.3.109-13.el7 mysql-community-client.x86_64 0:5.7.27-1.el7 mysql-community-common.x86_64 0:5.7.27-1.el7 Dependency Updated: postfix.x86_64 2:2.10.1-7.el7 Replaced: mariadb-libs.x86_64 1:5.5.52-1.el7 Complete!
6.啟用MySQL
在CentOS 6中,我們一般通過 service mysqld start 來啟動mysql,在CentOS 7中,如果直接輸入 service mysqld start ,則會出現以下信息:
這是因為 CentOS 7 下重啟服務不再通過 service
操作,而是通過 systemctl
操作,因此我們可以輸入命令:
啟動mysql:systemctl start mysqld.service
查看mysql狀態:systemctl status mysqld.service
7.登錄mysql
mysql -u root -p
在要求輸入密碼時,因為mysql 5.7的初始密碼不是空,直接按回車鍵不能成功登錄,因此需先找到初始密碼,才能登錄。
grep 'temporary password' /var/log/mysqld.log
如上,最后的內容就是初始密碼。
再次登錄,輸入初始密碼,即可成功登錄。
第一次登錄成功后,發現不能執行操作,同時提示讓修改密碼。
8.修改登錄密碼
alter user root@localhost identified by '新密碼'
這里,我想設置新密碼為 123456,但出現了報錯,這里的報錯是mysql的密碼策略問題,輸入命令:show variables like 'validate_password%'
,查看 mysql 初始的密碼策略,發現密碼的最小長度為8,密碼的驗證強度等級為MEDIUM,可以修改一下密碼策略:
設置密碼的驗證強度等級:set global validate_password_policy=LOW
設置密碼的最小長度:set global validate_password_length=6
好了,這時我們再次執行修改密碼的sql,便不會報錯了。
最后通過 flush privileges
刷新權限,使當前操作立即生效,就大功告成了。
注意:最后這里,也可以不修改密碼策略,只要自己設置的密碼滿足MySQL的原密碼策略即可。
第一種:mysql 5.0(兩種方式)
一、
在命令窗口輸入,mysql -u root -p 回車,并輸入密碼
執行 use mysql
執行下面句子,查看權限,root默認權限為localhost
select user,host from user;
更改root權限為%
update user set host = '%' where user = 'root';
刷新
flush privileges;
二、
在命令窗口輸入,mysql -u root -p 回車,并輸入密碼
執行 use mysql
設置test為賬戶,密碼為:ceshipwd,權限為%,所有人
grant all on *.* to 'test'@'%' identified by 'ceshipwd';
如果權限不設置為所有人,可設定固定訪問IP如下:
grant all on *.* to 'test'@'111.111.111.111' identified by 'ceshipwd';
最后,刷新
flush privileges;
第一種:mysql 8.0以上(兩種方式)
一、
在命令窗口輸入,mysql -u root -p 回車,并輸入密碼
執行 use mysql
執行下面句子,查看權限,root默認權限為localhost
select user,host from user;
更改root權限為%
update user set host = '%' where user = 'root';
刷新
flush privileges;
二、
在命令窗口輸入,mysql -u root -p 回車,并輸入密碼
執行 use mysql
設置test為賬戶,密碼為:ceshipwd,權限為%,所有人
先建立賬號:
create user 'test'@'%' identified with mysql_native_password by 'ceshipwd';
再添加賬號權限
grant all on *.* to 'test'@'%';
如果權限不設置為所有人,可設定固定訪問IP如下:
grant all on *.* to 'test'@'111.111.111.111';
最后,刷新
flush privileges;
三、
各版本修改密碼的格式:
mysql5.0格式如下:
本地可以訪問
alter user 'ceshi'@'localhost' identified by 'ceshipw';
所有都可以訪問
alter user 'ceshi'@'%' identified by 'ceshipw';
mysql8.0以上格式如下:
本地可以訪問
alter user 'ceshi'@'localhost' identified with mysql_native_password by 'ceshipw';
所有都可以訪問
alter user 'ceshi'@'%' identified with mysql_native_password by 'ceshipw';
*使用navicat連接mysql8.0數據庫時,提示1251-client does not support authentication protocol requested by server;consider upgrading mysql client 解決辦法:
進入數據庫,更新一下認證格式 user mysql; #下面方式是修改密碼的格式,即可正常訪問 alter user 'ceshi'@'%' identified with mysql_native_password by 'ceshipw'; flush privileges;
感謝各位的閱讀,以上就是“Linux下安裝MySQL5.7的步驟”的內容了,經過本文的學習后,相信大家對Linux下安裝MySQL5.7的步驟這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。