今天忽然心血來潮,想把博客轉移到到本身的雲服務器上,嗯,想法不錯,正好能練練手(後來找到了別的解決方案Hexo,才發現本身有多幼稚,果真是腦子一熱,啥事想得出來,可是在這個過程當中也學到了一些東西)。CentOS上安裝MySQL數據庫,linux配mysql,哎喲,不錯哦。(→_→在找到別的解決方案後,立刻就被我給卸了)。node
二話不說上yum安裝大法mysql
[root@VM_235_40_centos ~]# yum install mysql Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package mariadb.x86_64 1:5.5.52-1.el7 will be installed --> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.52-1.el7 for package: 1: mariadb-5.5.52-1.el7.x86_64 --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.35-3.el7 will be updated ---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mariadb x86_64 1:5.5.52-1.el7 os 8.7 M Updating for dependencies: mariadb-libs x86_64 1:5.5.52-1.el7 os 761 k Transaction Summary ================================================================================ Install 1 Package Upgrade ( 1 Dependent package) Total download size: 9.5 M Is this ok [y/d/N]: y Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. (1/2): mariadb-libs-5.5.52-1.el7.x86_64.rpm | 761 kB 00:00 (2/2): mariadb-5.5.52-1.el7.x86_64.rpm | 8.7 MB 00:00 -------------------------------------------------------------------------------- Total 16 MB/s | 9.5 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : 1:mariadb-libs-5.5.52-1.el7.x86_64 1/3 Installing : 1:mariadb-5.5.52-1.el7.x86_64 2/3 Cleanup : 1:mariadb-libs-5.5.35-3.el7.x86_64 3/3 Verifying : 1:mariadb-5.5.52-1.el7.x86_64 1/3 Verifying : 1:mariadb-libs-5.5.52-1.el7.x86_64 2/3 Verifying : 1:mariadb-libs-5.5.35-3.el7.x86_64 3/3 Installed: mariadb.x86_64 1:5.5.52-1.el7 Dependency Updated: mariadb-libs.x86_64 1:5.5.52-1.el7 Complete!
不知道是否是當時太興奮,也沒看安裝提示直接就填了yes,等安裝完傻眼了,MariaDB是什麼鬼。孤陋寡聞的我,趕緊去問度娘,原來是mysql的一個分支。
我想要個「正房」,你卻給我安了個「小三」;想養個海豚,你TM給我個海豹。
臥槽,我說這好歹也是IT三巨頭之一啊,yum庫居然連個mysql都沒有。linux
果斷把「小三」給刪了sql
[root@VM_235_40_centos ~]# yum erase mysql Loaded plugins: fastestmirror, langpacks Resolving Dependencies --> Running transaction check ---> Package mariadb.x86_64 1:5.5.52-1.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: mariadb x86_64 1:5.5.52-1.el7 @os 48 M Transaction Summary ================================================================================ Remove 1 Package Installed size: 48 M Is this ok [y/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : 1:mariadb-5.5.52-1.el7.x86_64 1/1 Verifying : 1:mariadb-5.5.52-1.el7.x86_64 1/1 Removed: mariadb.x86_64 1:5.5.52-1.el7 Complete!
唉,本身動手豐衣足食,上官網逛逛去。
國外的東西就是好,東西給你了,連教程都準備好了,惋惜了我這連四級都沒過的英語水平啊,沒辦法硬着頭皮也要看哪。shell
uname
命令看看本身的平臺版本wget
命令把相應的rpm包下下來,這個包很小隻有幾k[root@VM_235_40_centos ~]# wget https://repo.mysql.com//mysql57-community-release-el7-9.ch.rpm --2017-04-05 16:32:26-- https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm Resolving repo.mysql.com (repo.mysql.com)... 23.50.25.213 Connecting to repo.mysql.com (repo.mysql.com)|23.50.25.213|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 9224 (9.0K) [application/x-redhat-package-manager] Saving to: 'mysql57-community-release-el7-9.noarch.rpm' 100%[============================================================>] 9,224 --.-K/s in 0s 2017-04-05 16:32:28 (75.1 MB/s) - 'mysql57-community-release-el7-9.noarch.rpm' saved [9224/9224]
[root@VM_235_40_centos ~]# rpm -Uvh mysql57-community-release-el7-9.noarch.rpm warning: mysql57-community-release-el7-9.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5KEY Preparing... ################################# [100%] Updating / installing... 1:mysql57-community-release-el7-9 ################################# [100%] [root@VM_235_40_centos ~]cd /etc/yum.repos.d #安裝完成後會發現/etc/yum.repos.d會多了兩個mysql的repo文件 [root@VM_235_40_centos yum.repos.d]# ls CentOS-Base.repo mysql-community-source.repo CentOS-Epel.repo mysql-community.repo
[root@VM_235_40_centos yum.repos.d]# more mysql-community.repo [mysql-connectors-community] name=MySQL Connectors Community baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-tools-community] name=MySQL Tools Community baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Enable to use MySQL 5.5 [mysql55-community] name=MySQL 5.5 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Enable to use MySQL 5.6 [mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql80-community] name=MySQL 8.0 Community Server baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-tools-preview] name=MySQL Tools Preview baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
按照官網的說法,在這個文件中你能夠配置你想要安裝的mysql版本,若是須要安裝這個版本就設置enabled=1
,不須要的版本就把它設置爲0。這裏我安裝5.7的版本數據庫
[root@VM_235_40_centos yum.repos.d]# yum install mysql-community-server Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package mysql-community-server.x86_64 0:5.7.17-1.el6 will be installed --> Processing Dependency: mysql-community-common(x86-64) = 5.7.17-1.el6 for package: mysql-communserver-5.7.17-1.el6.x86_64 ...... ---> Package mysql-community-libs.x86_64 0:5.7.17-1.el6 will be obsoleting --> Finished Dependency Resolution Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda) Requires: libmysqlclient.so.18()(64bit) Removing: 1:mariadb-libs-5.5.52-1.el7.x86_64 (@os) libmysqlclient.so.18()(64bit) Obsoleted By: mysql-community-libs-5.7.17-1.el6.x86_64 (mysql57-community) ~libmysqlclient.so.20()(64bit) Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda) Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit) Removing: 1:mariadb-libs-5.5.52-1.el7.x86_64 (@os) libmysqlclient.so.18(libmysqlclient_18)(64bit) Obsoleted By: mysql-community-libs-5.7.17-1.el6.x86_64 (mysql57-community) Not found You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest
納尼,居然安裝出錯,出什麼鬼了。原來是mariadb沒有刪除乾淨,個人天,本身挖坑本身跳。centos
[root@VM_235_40_centos yum.repos.d]# rpm -qa|grep mariadb mariadb-libs-5.5.52-1.el7.x86_64 [root@VM_235_40_centos yum.repos.d]# rpm -ev mariadb-libs-5.5.52-1.el7.x86_64 --nodeps Preparing packages... mariadb-libs-1:5.5.52-1.el7.x86_64
再來一遍緩存
[root@VM_235_40_centos yum.repos.d]# yum install mysql-community-server Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package mysql-community-server.x86_64 0:5.7.17-1.el6 will be installed ...... ---> Package mysql-community-libs.x86_64 0:5.7.17-1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================== Package Arch Version Repository Size ================================================================================================== Installing: mysql-community-server x86_64 5.7.17-1.el6 mysql57-community 151 M Installing for dependencies: mysql-community-client x86_64 5.7.17-1.el6 mysql57-community 23 M mysql-community-common x86_64 5.7.17-1.el6 mysql57-community 328 k mysql-community-libs x86_64 5.7.17-1.el6 mysql57-community 2.1 M numactl-libs x86_64 2.0.9-6.el7_2 os 29 k Transaction Summary ================================================================================================== Install 1 Package (+4 Dependent packages) Total download size: 177 M Installed size: 879 M Is this ok [y/d/N]: y Downloading packages: mysql-community-common-5.7.17- FAILED http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.17-1.el6.x86_64.rpm: [Errno 14] HTTP Error 404 - Not Found Trying other mirror. mysql-community-client-5.7.17- FAILED http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.17-1.el6.x86_64.rpm: [Errno 14] HTTP Error 404 - Not Found Trying other mirror. ...... Error downloading packages: mysql-community-server-5.7.17-1.el6.x86_64: [Errno 256] No more mirrors to try. mysql-community-common-5.7.17-1.el6.x86_64: [Errno 256] No more mirrors to try. mysql-community-libs-5.7.17-1.el6.x86_64: [Errno 256] No more mirrors to try. mysql-community-client-5.7.17-1.el6.x86_64: [Errno 256] No more mirrors to try.
尼瑪,又出錯了,Linux上裝軟件就是蛋疼,404錯誤請求失敗,這又是什麼鬼,我前先後後有把安裝過程捋了一遍,仍是出錯,不行,默默地問度娘去。
這裏有篇博客,裏面說是yum緩存的問題,好吧清楚緩存。服務器
[root@VM_235_40_centos yum.repos.d]# cd /var/cache [root@VM_235_40_centos cache]# ls httpd ldconfig man yum [root@VM_235_40_centos cache]# cd yum [root@VM_235_40_centos yum]# ls x86_64 [root@VM_235_40_centos yum]# rm -drf x86_64 [root@VM_235_40_centos yum]# ls
從新再來網絡
[root@VM_235_40_centos yum]# yum install mysql-community-server Loaded plugins: fastestmirror, langpacks epel | 4.3 kB 00:00:00 extras | 3.4 kB 00:00:00 mysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql57-community | 2.5 kB 00:00:00 os | 3.6 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/10): epel/7/x86_64/group_gz | 170 kB 00:00:00 (2/10): epel/7/x86_64/updateinfo | 762 kB 00:00:00 (3/10): epel/7/x86_64/primary_db | 4.6 MB 00:00:00 (4/10): extras/7/x86_64/primary_db | 139 kB 00:00:00 (5/10): os/7/x86_64/group_gz | 155 kB 00:00:00 (6/10): updates/7/x86_64/primary_db | 3.8 MB 00:00:00 (7/10): os/7/x86_64/primary_db | 5.6 MB 00:00:00 (8/10): mysql-connectors-community/x86_64/primary_db | 13 kB 00:00:00 (9/10): mysql-tools-community/x86_64/primary_db | 32 kB 00:00:00 (10/10): mysql57-community/x86_64/primary_db | 96 kB 00:00:01 Determining fastest mirrors Resolving Dependencies --> Running transaction check ---> Package mysql-community-server.x86_64 0:5.7.17-1.el7 will be installed ...... --> Finished Dependency Resolution Dependencies Resolved ================================================================================================== Package Arch Version Repository Size ================================================================================================== Installing: mysql-community-server x86_64 5.7.17-1.el7 mysql57-community 162 M Installing for dependencies: mysql-community-client x86_64 5.7.17-1.el7 mysql57-community 24 M mysql-community-common x86_64 5.7.17-1.el7 mysql57-community 271 k mysql-community-libs x86_64 5.7.17-1.el7 mysql57-community 2.1 M numactl-libs x86_64 2.0.9-6.el7_2 os 29 k Transaction Summary ================================================================================================== Install 1 Package (+4 Dependent packages) Total download size: 188 M Installed size: 847 M Is this ok [y/d/N]: y Downloading packages: warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Public key for mysql-community-common-5.7.17-1.el7.x86_64.rpm is not installed (1/5): mysql-community-common-5.7.17-1.el7.x86_64.rpm | 271 kB 00:00:03 (2/5): mysql-community-libs-5.7.17-1.el7.x86_64.rpm | 2.1 MB 00:00:52 (3/5): numactl-libs-2.0.9-6.el7_2.x86_64.rpm | 29 kB 00:00:00 (4/5): mysql-community-client-5.7. 6% [=- ] 101 kB/s | 12 MB 00:29:51 ETA
沒問題了,只是我這服務器帶寬不行,默默地等吧。
Installed: mysql-community-server.x86_64 0:5.7.17-1.el7 Dependency Installed: mysql-community-client.x86_64 0:5.7.17-1.el7 mysql-community-common.x86_64 0:5.7.17-1.el7 mysql-community-libs.x86_64 0:5.7.17-1.el7 numactl-libs.x86_64 0:2.0.9-6.el7_2 Complete!
此處應有掌聲
官網的安裝指南使用service mysqld start
,CentOS7改用systemctl命令啓動服務了,使用service命令會默認轉向調用systemctl命令的。
MySQL5.7以前的版本若是按照這種方式安裝後,默認是沒有密碼的。對於MySQL5.7 有點特殊,下面是官網描述MySQL5.7的安裝過程:
- 服務初始化
- 在data文件夾生成SSL證書和密鑰
- 安裝validate_password 插件並生效
- 建立數據庫超級管理員’root@localhost’,併爲他生成密碼
也就是說MySQL5.7後生成了爲root超級管理員生成了一個密碼,這個密碼在/var/log/mysqld.log
文件中
shell> sudo grep 'temporary password' /var/log/mysqld.log
上面紅圈部分就是生成的隨即密碼,而後進入mysql修改密碼,固然修改密碼的方式有不少種,這個能夠自行百度。
修改端口
mysql的配置文件在/etc/my.cnf
修改端口只須要添加一行port=[修改的端口號]
,記得重啓服務
搞了兩節課終於TM折騰完了
yum: Yellow dog Updater, Modified, 解決rpm包依賴的軟件安裝工具,能夠在/etc/yum.config文件中進行yum的配置,yum數據源默認放在/etc/yum.repos.d/文件夾下。能夠認爲是rpm的增強版。
rpm: RedHat Package Manager,軟件安裝包的管理器,能夠用來安裝或刪除軟件。
wget: World Wide Web Get,wget是一個從網絡上自動下載文件的自由工具,支持HTTP、HTTPS、FTP常見協議。
uname: Unix Name,顯示主機操做系統名稱。
備註:centos 6.8和7下面注意包名的,要否則安裝不上去的。