CentOS下以RPM方式安裝MySQL 5.5

來源:互聯網
上載者:User

首先去http://dev.mysql.com/downloads/mysql/5.5.html#downloads網站下載:

分別下載以下三個檔案(由於我的機器是32位,下面是32位版本的包,如果你的機器是64位的請下載64位版本):

MySQL-server-5.5.16-1.rhel5.i386.rpm

MySQL-client-5.5.16-1.rhel4.i386.rpm

MySQL-devel-5.5.16-1.rhel4.i386.rpm

使用wget命令使用斷點傳輸的方式將這三個檔案下載

wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-server-5.5.16-1.rhel4.i386.rpm/from/http://mysql.spd.co.il/

wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-client-5.5.16-1.rhel4.i386.rpm/from/http://mysql.spd.co.il/

wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-devel-5.5.16-1.rhel4.i386.rpm/from/http://mysql.spd.co.il/

下載完成後開始安裝:

rpm -ivh MySQL-server-5.5.16-1.rhel4.i386.rpm MySQL-client-5.5.16-1.rhel4.i386.rpm MySQL-devel-5.5.16-1.rhel4.i386.rpm

 

提示安裝完成後,輸入mysql 看是否安裝成功

mysql 

如果出現如下錯誤資訊:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

說明mysql服務還沒有啟動,輸入service mysql start啟動mysql服務

service mysql start

 

然後再輸入mysql,若出現以下提示資訊,說明成功。

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

首次安裝時,預設密碼為空白,可以使用如下命令修改root密碼,

mysqladmin -u root  password mypassword

mypassword 為你設定的新密碼

然後再次登入

mysql -u root –p

 

rpm包安裝的MySQL是不會安裝/etc/my.cnf檔案的,解決方案,只需要複製/usr/share/mysql目錄下的my-huge.cnf 檔案到/etc目錄,並改名為my.cnf即可

cp /usr/share/mysql/my-huge.cnf /etc/my.cnf

 

配置遠端存取

處於安全考慮,Mysql預設是不允許遠端存取的,可以使用下面開啟遠端存取

//賦予任何主機訪問資料的許可權
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION

//使修改生效
mysql>FLUSH PRIVILEGES

如果依然不能遠端存取的話,那就很可能防火牆的原因了,可以在防火牆中開啟3306連接埠或者乾脆關掉防火牆。


/etc/init.d/iptables status

會得到一系列資訊,說明防火牆開著。

/etc/init.d/iptables stop

永久關閉:

chkconfig --level 35 iptables off

以上是對自己首次在CentOS上安裝mysql的一個總結,希望對大家有協助。

相關文章

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.