首先去http://dev.mysql.com/downloads/mysql/5.5.html#downloads站點下載:html
分別下載如下三個文件:node
MySQL-server-5.5.16-1.rhel5.i386.rpmmysql
MySQL-client-5.5.16-1.rhel4.i386.rpmlinux
MySQL-devel-5.5.16-1.rhel4.i386.rpmsql
使用wget命令使用斷點傳輸的方式將這三個文件下載 安全
[root@localhost ~]# 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/ [root@localhost ~]# 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/ [root@localhost ~]# 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/
注:有可能還須要如下幾個文件根據狀況下載就能夠了。ruby
MySQL-embedded-5.5.16-1.linux2.6.x86_64.rpm socket
MySQL-shared-5.5.16-1.linux2.6.x86_64.rpm tcp
MySQL-shared-compat-5.5.16-1.linux2.6.x86_64.rpm spa
MySQL-test-5.5.16-1.linux2.6.x86_64.rpm
[root@localhost ~]# 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 看是否安裝成功
[root@localhost ~]#mysql
若是出現以下錯誤信息:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
說明mysql服務尚未啓動,輸入service mysql start啓動mysql服務
[root@localhost ~]# 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.
rpm包安裝的MySQL是不會安裝/etc/my.cnf文件的,解決方法,只須要複製/usr/share/mysql目錄下的my-default.cnf 文件到/etc目錄,並更名爲my.cnf便可
[root@localhost ~]#cp /usr/share/mysql/my-default.cnf /etc/my.cnf
[root@localhost ~]#mysqladmin -u root password newpassword
newpassword 爲你設定的新密碼
而後再次登陸
[root@localhost ~]#mysql -u root –p Enter password:
注 5.6 之後默認密碼是隨機的,寫在/root/.mysql_secret這個文件裏,先用這個文件裏的密碼登陸後,而後再執行
mysql> set password =password('123456'); mysql> flush privileges;
處於安全考慮,Mysql默認是不容許遠程訪問的,可使用下面開啓遠程訪問
賦予任何主機訪問數據的權限
[root@localhost ~]#mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
使修改生效
[root@localhost ~]#mysql>FLUSH PRIVILEGES
若是依然不能遠程訪問的話,那就極可能防火牆的緣由了,能夠在防火牆中開啓3306端口或者乾脆關掉防火牆。
查看開機啓動設置是否成功
[root@localhost ~]#chkconfig --list | grep mysql*
若是看到mysql的服務,而且3,4,5都是on的話則成功,若是是off,則鍵入
[root@localhost ~]#chkconfig --level 345 mysql on
[root@localhost ~]#vi /etc/sysconfig/iptables [root@localhost ~]#-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT [root@localhost ~]#service iptables restart
[root@localhost ~]#service mysqld start [root@localhost ~]#service mysqld stop
rpm -qa|grep -i mysql #查看已經安裝的mysql相關包
rpm -ev package_name #package_name包名 好比:mysql-server-5.0.51b-1.el5
卸載後/var/lib/mysql中的/etc/my.cnf會重命名爲my.cnf.rpmsave,/var/log/mysqld.log 會重命名爲/var/log/mysqld.log.rpmsave,若是肯定沒用後就手工刪除
若是出現有依賴的狀況就使用
有依賴包能夠參數--nodeps或使用yum卸載,如 rpm -e xxx.rpm --nodeps或 yum remove xxx rpm -e --nodeps mysql-libs-5.1.61-4.el6.x86_64