首先去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'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION
//使修改生效
mysql>FLUSH PRIVILEGES
如果依然不能遠程訪問的話,那就很可能防火牆的原因了,可以在防火牆中開啟3306端口或者干脆關掉防火牆。