溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

CentOS6.4系統(tǒng)中Mysql數(shù)據(jù)庫(kù)的卸載、安裝與配置教程

發(fā)布時(shí)間:2021-08-31 17:04:26 來(lái)源:億速云 閱讀:128 作者:chen 欄目:系統(tǒng)運(yùn)維

本篇內(nèi)容介紹了“CentOS6.4系統(tǒng)中Mysql數(shù)據(jù)庫(kù)的卸載、安裝與配置教程”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

一、mysql簡(jiǎn)介

MySQL是一個(gè)關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),由瑞典MySQL AB公司開(kāi)發(fā),目前屬于Oracle公司。MySQL是一種關(guān)聯(lián)數(shù)據(jù)庫(kù)管理系統(tǒng),關(guān)聯(lián)數(shù)據(jù)庫(kù)將數(shù)據(jù)保存在不同的表中,而不是將所有數(shù)據(jù)放在一個(gè)大倉(cāng)庫(kù)內(nèi),這樣就增加了速度并提高了靈活性。MySQL的SQL語(yǔ)言是用于訪問(wèn)數(shù)據(jù)庫(kù)的最常用標(biāo)準(zhǔn)化語(yǔ)言。MySQL軟件采用了雙授權(quán)政策(本詞條“授權(quán)政策”),它分為社區(qū)版和商業(yè)版,由于其體積小、速度快、總體擁有成本低,尤其是開(kāi)放源碼這一特點(diǎn),一般中小型網(wǎng)站的開(kāi)發(fā)都選擇MySQL作為網(wǎng)站數(shù)據(jù)庫(kù)。由于其社區(qū)版的性能卓越,搭配PHP和Apache可組成良好的開(kāi)發(fā)環(huán)境。
在Linux上安裝mysql數(shù)據(jù)庫(kù),我們可以去其官網(wǎng)上下載mysql數(shù)據(jù)庫(kù)的rpm包,http://dev.mysql.com/downloads/mysql/5.6.html#downloads,大家可以根據(jù)自己的操作系統(tǒng)去下載對(duì)應(yīng)的數(shù)據(jù)庫(kù)文件,目前最新的版本是5.6.10了。

在這里我是通過(guò)yum來(lái)進(jìn)行mysql數(shù)據(jù)庫(kù)的安裝的,通過(guò)這種方式進(jìn)行安裝,可以將跟mysql相關(guān)的一些服務(wù)、jar包都給我們安裝好,所以省去了很多不必要的麻煩?。。?/p>

二、卸載掉原有mysql

因?yàn)閙ysql數(shù)據(jù)庫(kù)在Linux上實(shí)在是太流行了,所以目前下載的主流Linux系統(tǒng)版本基本上都集成了mysql數(shù)據(jù)庫(kù)在里面,我們可以通過(guò)如下命令來(lái)查看我們的操作系統(tǒng)上是否已經(jīng)安裝了mysql數(shù)據(jù)庫(kù)
[root@xiaoluo ~]# rpm -qa | grep mysql  // 這個(gè)命令就會(huì)查看該操作系統(tǒng)上是否已經(jīng)安裝了mysql數(shù)據(jù)庫(kù)
有的話,我們就通過(guò) rpm -e 命令 或者 rpm -e --nodeps 命令來(lái)卸載掉

[root@xiaoluo ~]# rpm -e mysql  // 普通刪除模式
[root@xiaoluo ~]# rpm -e --nodeps mysql  // 強(qiáng)力刪除模式,如果使用上面命令刪除時(shí),提示有依賴的其它文件,則用該命令可以對(duì)其進(jìn)行強(qiáng)力刪除

在刪除完以后我們可以通過(guò) rpm -qa | grep mysql 命令來(lái)查看mysql是否已經(jīng)卸載成功?。?/p>

三、通過(guò)yum來(lái)進(jìn)行mysql的安裝

我是通過(guò)yum的方式來(lái)進(jìn)行mysql的數(shù)據(jù)庫(kù)安裝,首先我們可以輸入 yum list | grep mysql 命令來(lái)查看yum上提供的mysql數(shù)據(jù)庫(kù)可下載的版本:

[root@xiaoluo ~]# yum list | grep mysql

就可以得到y(tǒng)um服務(wù)器上mysql數(shù)據(jù)庫(kù)的可下載版本信息:

CentOS6.4系統(tǒng)中Mysql數(shù)據(jù)庫(kù)的卸載、安裝與配置教程



然后我們可以通過(guò)輸入 yum install -y mysql-server mysql mysql-devel 命令將mysql mysql-server mysql-devel都安裝好(注意:安裝mysql時(shí)我們并不是安裝了mysql客戶端就相當(dāng)于安裝好了mysql數(shù)據(jù)庫(kù)了,我們還需要安裝mysql-server服務(wù)端才行)

[root@xiaoluo ~]# yum install -y mysql-server mysql mysql-deve

在等待了一番時(shí)間后,yum會(huì)幫我們選擇好安裝mysql數(shù)據(jù)庫(kù)所需要的軟件以及其它附屬的一些軟件

CentOS6.4系統(tǒng)中Mysql數(shù)據(jù)庫(kù)的卸載、安裝與配置教程

我們發(fā)現(xiàn),通過(guò)yum方式安裝mysql數(shù)據(jù)庫(kù)省去了很多沒(méi)必要的麻煩,當(dāng)出現(xiàn)下面的結(jié)果時(shí),就代表mysql數(shù)據(jù)庫(kù)安裝成功了

CentOS6.4系統(tǒng)中Mysql數(shù)據(jù)庫(kù)的卸載、安裝與配置教程


此時(shí)我們可以通過(guò)如下命令,查看剛安裝好的mysql-server的版本

[root@xiaoluo ~]# rpm -qi mysql-server
我們安裝的mysql-server并不是最新版本,如果你想嘗試最新版本,那就去mysql官網(wǎng)下載rpm包安裝就行了,至此我們的mysql數(shù)據(jù)庫(kù)已經(jīng)安裝完成了。

四、mysql數(shù)據(jù)庫(kù)的初始化及相關(guān)配置

我們?cè)诎惭b完mysql數(shù)據(jù)庫(kù)以后,會(huì)發(fā)現(xiàn)會(huì)多出一個(gè)mysqld的服務(wù),這個(gè)就是咱們的數(shù)據(jù)庫(kù)服務(wù),我們通過(guò)輸入 service mysqld start 命令就可以啟動(dòng)我們的mysql服務(wù)。

注意:如果我們是第一次啟動(dòng)mysql服務(wù),mysql服務(wù)器首先會(huì)進(jìn)行初始化的配置,如:

[root@xiaoluo ~]# service mysqld start

初始化 MySQL 數(shù)據(jù)庫(kù): WARNING: The host 'xiaoluo' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h xiaoluo password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

[確定]
正在啟動(dòng) mysqld: [確定]

這時(shí)我們會(huì)看到第一次啟動(dòng)mysql服務(wù)器以后會(huì)提示非常多的信息,目的就是對(duì)mysql數(shù)據(jù)庫(kù)進(jìn)行初始化操作,當(dāng)我們?cè)俅沃匦聠?dòng)mysql服務(wù)時(shí),就不會(huì)提示這么多信息了,如:
[root@xiaoluo ~]# service mysqld restart
停止 mysqld: [確定]
正在啟動(dòng) mysqld: [確定]
我們?cè)谑褂胢ysql數(shù)據(jù)庫(kù)時(shí),都得首先啟動(dòng)mysqld服務(wù),我們可以 通過(guò) chkconfig --list | grep mysqld 命令來(lái)查看mysql服務(wù)是不是開(kāi)機(jī)自動(dòng)啟動(dòng),如:

[root@xiaoluo ~]# chkconfig --list | grep mysqld

mysqld 0:關(guān)閉 1:關(guān)閉 2:關(guān)閉 3:關(guān)閉 4:關(guān)閉 5:關(guān)閉 6:關(guān)閉
我們發(fā)現(xiàn)mysqld服務(wù)并沒(méi)有開(kāi)機(jī)自動(dòng)啟動(dòng),我們當(dāng)然可以通過(guò) chkconfig mysqld on 命令來(lái)將其設(shè)置成開(kāi)機(jī)啟動(dòng),這樣就不用每次都去手動(dòng)啟動(dòng)了

[root@xiaoluo ~]# chkconfig mysqld on
[root@xiaoluo ~]# chkconfig --list | grep mysql

mysqld 0:關(guān)閉 1:關(guān)閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關(guān)閉
mysql數(shù)據(jù)庫(kù)安裝完以后只會(huì)有一個(gè)root管理員賬號(hào),但是此時(shí)的root賬號(hào)還并沒(méi)有為其設(shè)置密碼,在第一次啟動(dòng)mysql服務(wù)時(shí),會(huì)進(jìn)行數(shù)據(jù)庫(kù)的一些初始化工作,在輸出的一大串信息中,我們看到有這樣一行信息 :

/usr/bin/mysqladmin -u root password 'new-password'  // 為root賬號(hào)設(shè)置密碼

所以我們可以通過(guò) 該命令來(lái)給我們的root賬號(hào)設(shè)置密碼(注意:這個(gè)root賬號(hào)是mysql的root賬號(hào),非Linux的root賬號(hào))

[root@xiaoluo ~]# mysqladmin -u root password 'root'  // 通過(guò)該命令給root賬號(hào)設(shè)置密碼為 root

此時(shí)我們就可以通過(guò) mysql -u root -p 命令來(lái)登錄我們的mysql數(shù)據(jù)庫(kù)了

CentOS6.4系統(tǒng)中Mysql數(shù)據(jù)庫(kù)的卸載、安裝與配置教程



五、mysql數(shù)據(jù)庫(kù)的主要配置文件

1./etc/my.cnf 這是mysql的主配置文件
我們可以查看一下這個(gè)文件的一些信息
[root@xiaoluo etc]# ls my.cnf
my.cnf

[root@xiaoluo etc]# cat my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
2./ver/lib/mysql   mysql數(shù)據(jù)庫(kù)的數(shù)據(jù)庫(kù)文件存放位置
我們的mysql數(shù)據(jù)庫(kù)的數(shù)據(jù)庫(kù)文件通常是存放在了/ver/lib/mysql這個(gè)目錄下
[root@xiaoluo ~]# cd /var/lib/mysql/
[root@xiaoluo mysql]# ls -l
總用量 20488
-rw-rw----. 1 mysql mysql 10485760 4月   6 22:01 ibdata1
-rw-rw----. 1 mysql mysql  5242880 4月   6 22:01 ib_logfile0
-rw-rw----. 1 mysql mysql  5242880 4月   6 21:59 ib_logfile1
drwx------. 2 mysql mysql     4096 4月   6 21:59 mysql  // 這兩個(gè)是mysql數(shù)據(jù)庫(kù)安裝時(shí)默認(rèn)的兩個(gè)數(shù)據(jù)庫(kù)文件
srwxrwxrwx. 1 mysql mysql        0 4月   6 22:01 mysql.sock
drwx------. 2 mysql mysql     4096 4月   6 21:59 test  // 這兩個(gè)是mysql數(shù)據(jù)庫(kù)安裝時(shí)默認(rèn)的兩個(gè)數(shù)據(jù)庫(kù)文件
我們可以自己創(chuàng)建一個(gè)數(shù)據(jù)庫(kù),來(lái)驗(yàn)證一下該數(shù)據(jù)庫(kù)文件的存放位置
創(chuàng)建一個(gè)我們自己的數(shù)據(jù)庫(kù):
mysql> create database xiaoluo;
Query OK, 1 row affected (0.00 sec)

[root@xiaoluo mysql]# ls -l
總用量 20492
-rw-rw----. 1 mysql mysql 10485760 4月   6 22:01 ibdata1
-rw-rw----. 1 mysql mysql  5242880 4月   6 22:01 ib_logfile0
-rw-rw----. 1 mysql mysql  5242880 4月   6 21:59 ib_logfile1
drwx------. 2 mysql mysql     4096 4月   6 21:59 mysql
srwxrwxrwx. 1 mysql mysql        0 4月   6 22:01 mysql.sock
drwx------. 2 mysql mysql     4096 4月   6 21:59 test
drwx------. 2 mysql mysql     4096 4月   6 22:15 xiaoluo  // 這個(gè)就是我們剛自己創(chuàng)建的xiaoluo數(shù)據(jù)庫(kù)
[root@xiaoluo mysql]# cd xiaoluo/
[root@xiaoluo xiaoluo]# ls
db.opt
3./var/log mysql數(shù)據(jù)庫(kù)的日志輸出存放位置
我們的mysql數(shù)據(jù)庫(kù)的一些日志輸出存放位置都是在/var/log這個(gè)目錄下
[root@xiaoluo xiaoluo]# cd
[root@xiaoluo ~]# cd /var/log
[root@xiaoluo log]# ls
amanda                cron           maillog-20130331   spice-vdagent.log
anaconda.ifcfg.log    cron-20130331  mcelog             spooler
anaconda.log          cups           messages           spooler-20130331
anaconda.program.log  dirsrv         messages-20130331  sssd
anaconda.storage.log  dmesg          mysqld.log         tallylog
anaconda.syslog       dmesg.old      ntpstats           tomcat6
anaconda.xlog         dracut.log     piranha            wpa_supplicant.log
anaconda.yum.log      gdm            pm-powersave.log   wtmp
audit                 httpd          ppp                Xorg.0.log
boot.log              ibacm.log      prelink            Xorg.0.log.old
btmp                  lastlog        sa                 Xorg.1.log
btmp-20130401         libvirt        samba              Xorg.2.log
cluster               luci           secure             Xorg.9.log
ConsoleKit            maillog        secure-20130331    yum.log

其中mysqld.log 這個(gè)文件就是我們存放我們跟mysql數(shù)據(jù)庫(kù)進(jìn)行操作而產(chǎn)生的一些日志信息,通過(guò)查看該日志文件,我們可以從中獲得很多信息
因?yàn)槲覀兊膍ysql數(shù)據(jù)庫(kù)是可以通過(guò)網(wǎng)絡(luò)訪問(wèn)的,并不是一個(gè)單機(jī)版數(shù)據(jù)庫(kù),其中使用的協(xié)議是 tcp/ip 協(xié)議,我們都知道m(xù)ysql數(shù)據(jù)庫(kù)綁定的端口號(hào)是 3306 ,所以我們可以通過(guò) netstat -anp 命令來(lái)查看一下,Linux系統(tǒng)是否在監(jiān)聽(tīng) 3306 這個(gè)端口號(hào):

CentOS6.4系統(tǒng)中Mysql數(shù)據(jù)庫(kù)的卸載、安裝與配置教程

結(jié)果如上所示,Linux系統(tǒng)監(jiān)聽(tīng)的3306端口號(hào)就是我們的mysql數(shù)據(jù)庫(kù)?。。?!

“CentOS6.4系統(tǒng)中Mysql數(shù)據(jù)庫(kù)的卸載、安裝與配置教程”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI