在RHEL6中安裝mysql資料庫

來源:互聯網
上載者:User

標籤:資料庫   rhel6   mysql   

    今天要給大家示範的是在RHEL6系統中安裝mysql資料庫,本次實驗是在VMware虛擬機器中實現。

系統版本:2.6.32-71.el6.i686

[[email protected] ~]# uname -a

Linux wuli.redhat.com 2.6.32-71.el6.i686 #1SMP Wed Sep 1 01:26:34 EDT 2010 i686 i686 i386 GNU/Linux

   資料庫版本:5.6.20

[[email protected] Downloads]# ls

MySQL-client-5.6.20-1.el6.i686.rpm  MySQL-shared-compat-5.6.20-1.el6.i686.rpm

MySQL-server-5.6.20-1.el6.i686.rpm

   接下來開始安裝資料庫,如果是下載的捆綁式的rpm軟體包,在解壓後會發現有好多個軟體包,在此我只安裝server和client兩個包。在此需要注意的是,在安裝之前需要安裝一個RHEL相容包,即shared-compat包。

[[email protected] Downloads]# rpm -ivhMySQL-shared-compat-5.6.20-1.el6.i686.rpm

Preparing...               ########################################### [100%]

  1:MySQL-shared-compat   ########################################### [100%]

預設系統裡面給安裝了mysql-libs-5.1.47-4.el6.i686軟體包,直接卸載會提示有包依賴,在安裝完shared-compat之後就可以把它卸載掉,否則會影響安裝。

[[email protected] Downloads]# rpm -e mysql-libs

   建立MySQL系統管理使用者:

[[email protected] Downloads]# groupadd mysql

[[email protected] Downloads]# useradd -g mysqlmysql

[[email protected] Downloads]# passwd mysql

Changing password for user mysql.

New password:mysql(這裡密碼設定為mysql)

BAD PASSWORD: it is too short

BAD PASSWORD: is too simple

Retype new password:mysql

passwd: all authentication tokens updatedsuccessfully.

[[email protected] Downloads]#

接下來安裝MySQL-client-5.6.20-1.el6.i686.rpm和MySQL-server-5.6.20-1.el6.i686.rpm兩個軟體包。

[[email protected] Downloads]# rpm -ivhMySQL-server-5.6.20-1.el6.i686.rpm

Preparing...               ########################################### [100%]

  1:MySQL-server          ########################################### [100%]

[[email protected] Downloads]# rpm -ivhMySQL-client-5.6.20-1.el6.i686.rpm

Preparing...                ###########################################[100%]

  1:MySQL-client          ########################################### [100%]

   啟用MySQL服務:

[[email protected] Downloads]# service mysql start

Starting MySQL................                             [  OK  ]

[[email protected] Downloads]#

    首先需要擷取登入的隨機密碼,方法如下:

[[email protected] Downloads]# more/root/.mysql_secret

# The random password set for the root userat Fri Aug  8 05:18:49 2014 (local t

ime): qC1eXKeP3JTEgxzL

 

[[email protected] Downloads]#

    使用首次擷取隨機密碼登入MySQL資料庫,然後修改登入密碼,方法如下:

[[email protected] Downloads]# mysql -uroot -pqC1eXKeP3JTEgxzL

Warning: Using a password on the commandline interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.20

 

Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

 

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ toclear the current input statement.

 

mysql>

   設定登入密碼為mysql(這裡設定為mysql)

mysql> set password=password(‘mysql‘);

Query OK, 0 rows affected (0.07 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql>

   修改安裝目錄許可權:

[[email protected] Downloads]# chown -R mysql:mysql/usr/share/mysql

[[email protected] Downloads]# chown -R mysql:mysql/var/lib/mysql

   為mysql添加環境變數:

[[email protected] ~]# vim .bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

       . ~/.bashrc

fi

# User specific environment and startupprograms

PATH=$PATH:$HOME/bin

 

export PATH

export

exportDATADIR=/var/lib/mysql

exportMYSQL_HOME=/usr/share/mysql

    停止啟動mysql:

[[email protected] ~]# mysqladmin -uroot -pshutdown

Enter password:mysql

[[email protected] ~]#

[[email protected] ~]#/usr/share/mysql/mysql.server start --user=mysql

Starting MySQL.                                            [ OK  ]

    到這裡整個安裝步驟已經完成了,但是我們經常來配置或登入mysql資料庫的時候,不可能每次都在伺服器上來配置,很多情況會通過終端來登入伺服器,預設mysql伺服器禁止從其他終端來登入它。

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/45/0C/wKiom1PjjbqCSNrPAACaEaFshZ8817.jpg" title="1.jpg" alt="wKiom1PjjbqCSNrPAACaEaFshZ8817.jpg" />

 

    解決方案如下:

    首先登入到資料庫

[[email protected] ~]#mysql –uroot –p

Enter password:mysql

mysql> use mysql

Reading table information for completion oftable and column names

You can turn off this feature to get aquicker startup with -A

Database changed

mysql> update user set host=‘%‘ wherehost=‘localhost‘;

Query OK, 1 row affected (0.06 sec)

Rows matched: 1  Changed: 1 Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.06 sec)

         接下來我們再來通過用戶端來登入伺服器:

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/45/0D/wKioL1PjjwSA8PFuAAJZJJIitgs438.jpg" title="2.jpg" alt="wKioL1PjjwSA8PFuAAJZJJIitgs438.jpg" />

成功登入。

    如果遇到下面提示符,原因是由於伺服器開啟了防火牆導致的,解決方案:關閉防火牆即可。

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/45/0D/wKioL1PjjyKRvyxIAAEytusaswE857.jpg" title="3.jpg" alt="wKioL1PjjyKRvyxIAAEytusaswE857.jpg" />

    我們可以查看安裝的資料庫版本:

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/45/0C/wKiom1PjjinBaY7QAAB5DI8ECqY934.jpg" title="4.jpg" alt="wKiom1PjjinBaY7QAAB5DI8ECqY934.jpg" />

    到此,整個實驗就完成了,歡迎來到MySQL的世界^_^!


本文出自 “wuli鈥檚 blog” 部落格,請務必保留此出處http://wuli03960405.blog.51cto.com/1470785/1537201

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.