阿里云 Centos7.3安裝mysql5.7.18 rpm安裝教程
卸載MariaDB
CentOS7默認(rèn)安裝MariaDB而不是MySQL,而且yum服務(wù)器上也移除了MySQL相關(guān)的軟件包。因?yàn)镸ariaDB和MySQL可能會(huì)沖突,故先卸載MariaDB。
1、安裝新版mysql之前,我們需要將系統(tǒng)自帶的mariadb-lib卸載
[root@iZwz94qazh62gk5ewl4ei2Z home]# rpm -qa | grep -i mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@iZwz94qazh62gk5ewl4ei2Z home]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
2、到mysql的官網(wǎng)下載最新版mysql的rpm集合包:mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar
3、上傳mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar到linux服務(wù)器,并解壓tar包
[root@iZwz94qazh62gk5ewl4ei2Z home]# mkdir mysql [root@iZwz94qazh62gk5ewl4ei2Z home]# tar -xf mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar -C mysql [root@iZwz94qazh62gk5ewl4ei2Z home]# cd mysql [root@iZwz94qazh62gk5ewl4ei2Z mysql]# ll total 459492 -rw-r--r-- 1 7155 31415 23618836 Mar 20 17:40 mysql-community-client-5.7.18-1.el6.x86_64.rpm -rw-r--r-- 1 7155 31415 335496 Mar 20 17:40 mysql-community-common-5.7.18-1.el6.x86_64.rpm -rw-r--r-- 1 7155 31415 3747352 Mar 20 17:40 mysql-community-devel-5.7.18-1.el6.x86_64.rpm -rw-r--r-- 1 7155 31415 39086508 Mar 20 17:40 mysql-community-embedded-5.7.18-1.el6.x86_64.rpm -rw-r--r-- 1 7155 31415 135869292 Mar 20 17:40 mysql-community-embedded-devel-5.7.18-1.el6.x86_64.rpm -rw-r--r-- 1 7155 31415 2177064 Mar 20 17:40 mysql-community-libs-5.7.18-1.el6.x86_64.rpm -rw-r--r-- 1 7155 31415 1723180 Mar 20 17:40 mysql-community-libs-compat-5.7.18-1.el6.x86_64.rpm -rw-r--r-- 1 7155 31415 159060212 Mar 20 17:41 mysql-community-server-5.7.18-1.el6.x86_64.rpm -rw-r--r-- 1 7155 31415 104881084 Mar 20 17:41 mysql-community-test-5.7.18-1.el6.x86_64.rpm
4、使用rpm -ivh命令進(jìn)行安裝
[root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-common-5.7.18-1.el6.x86_64.rpm warning: mysql-community-common-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-common-5.7.18-1.e################################# [100%] [root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-libs-5.7.18-1.el6.x86_64.rpm warning: mysql-community-libs-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-libs-5.7.18-1.el6################################# [100%] [root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-client-5.7.18-1.el6.x86_64.rpm warning: mysql-community-client-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-client-5.7.18-1.e################################# [100%] [root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-server-5.7.18-1.el6.x86_64.rpm warning: mysql-community-server-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-server-5.7.18-1.e################################# [100%] [root@iZwz94qazh62gk5ewl4ei2Z mysql]#
上面幾個(gè)包有依賴(lài)關(guān)系,執(zhí)行有先后。
使用rpm安裝方式安裝mysql,安裝的路徑如下:
a 數(shù)據(jù)庫(kù)目錄 /var/lib/mysql/ b 配置文件 /usr/share/mysql(mysql.server命令及配置文件) c 相關(guān)命令 /usr/bin(mysqladmin mysqldump等命令) d 啟動(dòng)腳本 /etc/rc.d/init.d/(啟動(dòng)腳本文件mysql的目錄) e /etc/my.conf
5、 數(shù)據(jù)庫(kù)初始化
為了保證數(shù)據(jù)庫(kù)目錄為與文件的所有者為 mysql 登陸用戶(hù),如果你的linux系統(tǒng)是以 root 身份運(yùn)行 mysql 服務(wù),需要執(zhí)行下面的命令初始化
[root@iZwz94qazh62gk5ewl4ei2Z mysql]# mysqld --initialize --user=mysql
如果是以 mysql 身份登錄運(yùn)行,則可以去掉 --user 選項(xiàng)。
另外 --initialize 選項(xiàng)默認(rèn)以“安全”模式來(lái)初始化,則會(huì)為 root 用戶(hù)生成一個(gè)密碼并將該密碼標(biāo)記為過(guò)期,登陸后你需要設(shè)置一個(gè)新的密碼,
而使用 --initialize-insecure 命令則不使用安全模式,則不會(huì)為 root 用戶(hù)生成一個(gè)密碼。
這里演示使用的 --initialize 初始化的,會(huì)生成一個(gè) root 賬戶(hù)密碼,密碼在log文件里,紅色區(qū)域的就是自動(dòng)生成的密碼
[root@iZwz94qazh62gk5ewl4ei2Z mysql]# cat /var/log/mysqld.log 2017-06-05T14:30:52.709474Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-06-05T14:30:55.590590Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-06-05T14:30:56.000269Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-06-05T14:30:56.109868Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 960c533e-49fb-11e7-91f2-00163e089fd2. 2017-06-05T14:30:56.116186Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2017-06-05T14:30:56.116777Z 1 [Note] A temporary password is generated for root@localhost: :Wu?2QQutQwj
現(xiàn)在啟動(dòng)mysql數(shù)據(jù)庫(kù)systemctl start mysqld.service(Centos7特有的啟動(dòng)方式)
[root@iZwz94qazh62gk5ewl4ei2Z mysql]# systemctl start mysqld.service
可以使用下面兩個(gè)命令對(duì)mysql進(jìn)行停止,啟動(dòng)和重啟:
啟動(dòng):
使用 service 啟動(dòng):service mysqld start
使用 mysqld 腳本啟動(dòng):/etc/inint.d/mysqld start
使用 safe_mysqld 啟動(dòng):safe_mysqld&
停止:
使用 service 啟動(dòng):service mysqld stop
使用 mysqld 腳本啟動(dòng):/etc/inint.d/mysqld stop
mysqladmin shutdown
重啟:
使用 service 啟動(dòng):service mysqld restart
使用 mysqld 腳本啟動(dòng):/etc/inint.d/mysqld restart
連接數(shù)據(jù)庫(kù)
[root@iZwz94qazh62gk5ewl4ei2Z mysql]# mysql -u root -p
Enter password:
密碼輸入: :Wu?2QQutQwj
修改密碼:
set password = password('你的密碼');
設(shè)置遠(yuǎn)程訪問(wèn)
grant all privileges on *.* to 'root' @'%' identified by '123456'; flush privileges;
設(shè)置mysql開(kāi)機(jī)啟動(dòng)
加入到系統(tǒng)服務(wù):
chkconfig --add mysql
自動(dòng)啟動(dòng):
chkconfig mysql on
查詢(xún)列表:
chkconfig
說(shuō)明:都沒(méi)關(guān)閉(off)時(shí)是沒(méi)有自動(dòng)啟動(dòng)。
以上所述是小編給大家介紹的阿里云 Centos7.3安裝mysql5.7.18 rpm安裝教程,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
MySql的樂(lè)觀鎖和冪等性問(wèn)題解決方案及場(chǎng)景示例
在分布式系統(tǒng)中,樂(lè)觀鎖、冪等性設(shè)計(jì)和數(shù)據(jù)插入失敗處理是保障數(shù)據(jù)一致性和系統(tǒng)可靠性的三大核心機(jī)制,它們共同協(xié)作以解決并發(fā)沖突、重復(fù)請(qǐng)求和網(wǎng)絡(luò)異常等問(wèn)題,這篇文章主要介紹了MySql的樂(lè)觀鎖和冪等性問(wèn)題解決方案及場(chǎng)景示例,需要的朋友可以參考下2025-05-05
從基礎(chǔ)語(yǔ)法到最佳實(shí)踐詳解SQL分頁(yè)查詢(xún)完整指南
在數(shù)據(jù)庫(kù)查詢(xún)中,分頁(yè)(Pagination) 是一項(xiàng)基本且關(guān)鍵的技術(shù),本文將從 SQL分頁(yè)的基礎(chǔ)語(yǔ)法 講起,逐步深入探討 不同數(shù)據(jù)庫(kù)的分頁(yè)實(shí)現(xiàn)方式,有需要的小伙伴可以了解下2025-07-07
借助PHP的mysql_query()函數(shù)來(lái)創(chuàng)建MySQL數(shù)據(jù)庫(kù)的教程
這篇文章主要介紹了借助PHP的mysql_query()函數(shù)來(lái)創(chuàng)建MySQL數(shù)據(jù)庫(kù)的教程,將函數(shù)配合CREATE DATABASE語(yǔ)句使用,需要的朋友可以參考下2015-12-12
MySQL開(kāi)啟遠(yuǎn)程訪問(wèn)權(quán)限的完整步驟記錄
MySQL是常用的關(guān)系型數(shù)據(jù)庫(kù),默認(rèn)僅支持本地訪問(wèn),若需更靈活管理,可通過(guò)遠(yuǎn)程連接突破限制,實(shí)現(xiàn)跨主機(jī)操作,這篇文章主要介紹了MySQL開(kāi)啟遠(yuǎn)程訪問(wèn)權(quán)限的完整步驟,需要的朋友可以參考下2025-06-06
CentOS系統(tǒng)中安裝MySQL和開(kāi)啟MySQL遠(yuǎn)程訪問(wèn)的方法
這篇文章主要介紹了CentOS系統(tǒng)中安裝MySQL和開(kāi)啟MySQL遠(yuǎn)程訪問(wèn)的方法,包括MySQL的隨機(jī)啟動(dòng)等操作的介紹,需要的朋友可以參考下2016-02-02

