CentOS6.4下Mysql數(shù)據(jù)庫(kù)怎么安裝與配置

這篇文章主要介紹“CentOS6.4下MySQL數(shù)據(jù)庫(kù)怎么安裝與配置”,在日常操作中,相信很多人在CentOS6.4下Mysql數(shù)據(jù)庫(kù)怎么安裝與配置問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”CentOS6.4下Mysql數(shù)據(jù)庫(kù)怎么安裝與配置”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!

成都創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括大足網(wǎng)站建設(shè)、大足網(wǎng)站制作、大足網(wǎng)頁(yè)制作以及大足網(wǎng)絡(luò)營(yíng)銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,大足網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到大足省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

一、mysql簡(jiǎn)介

說到數(shù)據(jù)庫(kù),我們大多想到的是關(guān)系型數(shù)據(jù)庫(kù),比如mysql、oracle、sqlserver等等,這些數(shù)據(jù)庫(kù)軟件在windows上安裝都非常的方便,在linux上如果要安裝數(shù)據(jù)庫(kù),咱不得不首先推薦的是mysql數(shù)據(jù)庫(kù)了,而且mysql數(shù)據(jù)庫(kù)的第一個(gè)版本就是發(fā)行在linux系統(tǒng)上的。

mysql是一個(gè)關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),由瑞典mysql ab公司開發(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語言是用于訪問數(shù)據(jù)庫(kù)的最常用標(biāo)準(zhǔn)化語言。mysql軟件采用了雙授權(quán)政策(本詞條“授權(quán)政策”),它分為社區(qū)版和商業(yè)版,由于其體積小、速度快、總體擁有成本低,尤其是開放源碼這一特點(diǎn),一般中小型網(wǎng)站的開發(fā)都選擇mysql作為網(wǎng)站數(shù)據(jù)庫(kù)。由于其社區(qū)版的性能卓越,搭配php和apache可組成良好的開發(fā)環(huán)境。

在linux上安裝mysql數(shù)據(jù)庫(kù),大家可以根據(jù)自己的操作系統(tǒng)去下載對(duì)應(yīng)的數(shù)據(jù)庫(kù)文件。

mysql5.0版本下載地址集合:

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

二、卸載掉原有mysql

因?yàn)閙ysql數(shù)據(jù)庫(kù)在linux上實(shí)在是太流行了,所以目前下載的主流linux系統(tǒng)版本基本上都集成了mysql數(shù)據(jù)庫(kù)在里面,我們可以通過如下命令來查看我們的操作系統(tǒng)上是否已經(jīng)安裝了mysql數(shù)據(jù)庫(kù)

[root@xiaoluo ~]# rpm -qa | grep mysql  // 這個(gè)命令就會(huì)查看該操作系統(tǒng)上是否已經(jīng)安裝了mysql數(shù)據(jù)庫(kù)

有的話,我們就通過 rpm -e 命令 或者 rpm -e --nodeps 命令來卸載掉

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

在刪除完以后我們可以通過 rpm -qa | grep mysql 命令來查看mysql是否已經(jīng)卸載成功??!

三、通過yum來進(jìn)行mysql的安裝

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

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

就可以得到y(tǒng)um服務(wù)器上mysql數(shù)據(jù)庫(kù)的可下載版本信息:CentOS6.4下Mysql數(shù)據(jù)庫(kù)怎么安裝與配置

然后我們可以通過輸入 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下Mysql數(shù)據(jù)庫(kù)怎么安裝與配置

 我們發(fā)現(xiàn),通過yum方式安裝mysql數(shù)據(jù)庫(kù)省去了很多沒必要的麻煩,當(dāng)出現(xiàn)下面的結(jié)果時(shí),就代表mysql數(shù)據(jù)庫(kù)安裝成功了CentOS6.4下Mysql數(shù)據(jù)庫(kù)怎么安裝與配置
 此時(shí)我們可以通過如下命令,查看剛安裝好的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ù),我們通過輸入 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ù),我們可以 通過  chkconfig --list | grep mysqld 命令來查看mysql服務(wù)是不是開機(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ù)并沒有開機(jī)自動(dòng)啟動(dòng),我們當(dāng)然可以通過 chkconfig mysqld on 命令來將其設(shè)置成開機(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)還并沒有為其設(shè)置密碼,在第一次啟動(dòng)mysql服務(wù)時(shí),會(huì)進(jìn)行數(shù)據(jù)庫(kù)的一些初始化工作,在輸出的一大串信息中,我們看到有這樣一行信息 :

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

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

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

此時(shí)我們就可以通過 mysql -u root -p 命令來登錄我們的mysql數(shù)據(jù)庫(kù)了CentOS6.4下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./var/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ù),來驗(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)生的一些日志信息,通過查看該日志文件,我們可以從中獲得很多信息

 因?yàn)槲覀兊膍ysql數(shù)據(jù)庫(kù)是可以通過網(wǎng)絡(luò)訪問的,并不是一個(gè)單機(jī)版數(shù)據(jù)庫(kù),其中使用的協(xié)議是 tcp/ip 協(xié)議,我們都知道m(xù)ysql數(shù)據(jù)庫(kù)綁定的端口號(hào)是 3306 ,所以我們可以通過 netstat -anp 命令來查看一下,linux系統(tǒng)是否在監(jiān)聽 3306 這個(gè)端口號(hào):CentOS6.4下Mysql數(shù)據(jù)庫(kù)怎么安裝與配置

到此,關(guān)于“CentOS6.4下Mysql數(shù)據(jù)庫(kù)怎么安裝與配置”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

文章題目:CentOS6.4下Mysql數(shù)據(jù)庫(kù)怎么安裝與配置
瀏覽地址:http://www.muchs.cn/article48/iidhep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃自適應(yīng)網(wǎng)站、品牌網(wǎng)站建設(shè)用戶體驗(yàn)網(wǎng)站設(shè)計(jì)、品牌網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司