安装前准备:
1.查看Linux自带的mysql版本:
[root@javaweb1 ~]# rpm -aq | grep mysql
mysql-libs-5.1.73-3.el6_5.x86_64
2.卸载Linux自带的mysql版本:
[root@javaweb1 ~]# rpm -e --nodeps mysql-libs-5.1.73-3.el6_5.x86_64
1.本文是安装的mysql5.5版本,下载地址如下:http://dev.mysql.com/downloads/mysql/5.5.html#downloads
通过命令查看Linux是32位还是64位:
uname -a
如上系统为64位,下载对应的mysql版本 选择最下面的选项
2.解压下载的文件包:
[root@javaweb1 soft]# tar -xvf MySQL-5.6.36-1.linux_glibc2.5.x86_64.rpm-bundle.tar -C /usr/local/mysql/
MySQL-devel-5.6.36-1.linux_glibc2.5.x86_64.rpm
MySQL-server-5.6.36-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-5.6.36-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-compat-5.6.36-1.linux_glibc2.5.x86_64.rpm
MySQL-client-5.6.36-1.linux_glibc2.5.x86_64.rpm
MySQL-test-5.6.36-1.linux_glibc2.5.x86_64.rpm
MySQL-embedded-5.6.36-1.linux_glibc2.5.x86_64.rpm
3.安装MySQL-server-5.6.36-1.linux_glibc2.5.x86_64.rpm和MySQL-client-5.6.36-1.linux_glibc2.5.x86_64.rpm
[root@javaweb1 mysql]# rpm -ivh MySQL-server-5.6.36-1.linux_glibc2.5.x86_64.rpm
[root@javaweb1 mysql]# rpm -ivh MySQL-client-5.6.36-1.linux_glibc2.5.x86_64.rpm
4.启动mysql
[root@javaweb1 mysql]# service mysql start
Starting MySQL.Logging to '/var/lib/mysql/javaweb1.err'.
5.加入系统服务,设置自启动
[root@javaweb1 mysql]# chkconfig --add mysql
[root@javaweb1 mysql]# chkconfig mysql on
6.首次登录的时候需要从root目录下的.mysql_secret文件中读取root的密码
[root@javaweb1 ~]# ls -a
. anaconda-ks.cfg .bash_profile .cshrc install.log.syslog .tcshrc
.. .bash_logout .bashrc install.log .mysql_secret
[root@javaweb1 ~]# cat .mysql_secret
# The random password set for the root user at Sun Apr 30 06:09:22 2017 (local time): hW6zM96CR9umdg3t
7.重新设置mysql的root密码
mysql> set password = password('root');
8.设置mysql可以被远程访问,并且刷新
mysql> grant all privileges on *.* to 'root' @'%' identified by 'root';
Query OK, 0 rows affected (0.38 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
9.设置mysql的端口可以被外界访问
[root@javaweb1 ~]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
[root@javaweb1 ~]# /etc/rc.d/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]