在CentOS release 6.4 下mysql的rpm方式的安装

时间:2021-01-01 10:19:07

1、linux的环境为CentOS release 6.4,Mysql为MySQL-5.7.3-m13-1.linux_glibc2.5.i386.rpm-bundle.tar

2、安装前先查看linux上有没有 以rpm的方式安装mysql      

[root@localhost hadoop]#  rpm -qa | grep -i mysql
mysql-libs-5.1.66-2.el6_3.i686
[root@localhost hadoop]# rpm --nodeps -e mysql-libs<strong>
</strong>

    如果电脑上,不存在安装好的mysql,则不需要卸载.

3、Mysql的安装

3.1 将MySQL-5.7.3-m13-1.linux_glibc2.5.i386.rpm-bundle.tar上传到linux上

[root@localhost hadoop]# ll
-rw-rw-r--. 1 hadoop hadoop 339107840 Apr  4 04:58 MySQL-5.7.3-m13-1.linux_glibc2.5.i386.rpm-bundle.tar<strong>

</strong>
    

3.2 进行解压

[root@localhost hadoop]# tar -xvf MySQL-5.7.3-m13-1.linux_glibc2.5.i386.rpm-bundle.tar 
MySQL-server-5.7.3_m13-1.linux_glibc2.5.i386.rpm
MySQL-client-5.7.3_m13-1.linux_glibc2.5.i386.rpm
MySQL-shared-5.7.3_m13-1.linux_glibc2.5.i386.rpm
MySQL-embedded-5.7.3_m13-1.linux_glibc2.5.i386.rpm
MySQL-test-5.7.3_m13-1.linux_glibc2.5.i386.rpm
MySQL-devel-5.7.3_m13-1.linux_glibc2.5.i386.rpm
MySQL-shared-compat-5.7.3_m13-1.linux_glibc2.5.i386.rpm
   

3.3进行安装(注意安装的顺序,只需要安装3个就可以了)

[root@localhost hadoop]# rpm -ivh MySQL-server-5.7.3_m13-1.linux_glibc2.5.i386.rpm 
[root@localhost hadoop]# rpm -ivh MySQL-devel-5.7.3_m13-1.linux_glibc2.5.i386.rpm
[root@localhost hadoop]# rpm -ivh MySQL-client-5.7.3_m13-1.linux_glibc2.5.i386.rpm 

4、修改配置文件的位置

[root@localhost hadoop]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
<pre name="code" class="sql">

 

5、Mysql的初始化设置和Mysql的密码设置

[root@localhost hadoop]# service mysql start
[root@localhost hadoop]#  cat /root/.mysql_secret  #查看root账号密码
# The random password set for the root user at Mon Apr  4 05:19:34 2016 (local time): HxPAzXlI
[root@localhost hadoop]# mysql -u root -pHxPAzXlI
[root@localhost hadoop]# cp /usr/share/mysql/my-default.cnf /etc/my.cn
mysql> SET PASSWORD = PASSWORD('1234');    #设置密码为1234
mysql> quit
[root@localhost hadoop]# mysql -u root -p1234

6、允许远程连接Mysql

mysql> use mysql;
select host,user,password from user;
+-----------------------+------+-------------------------------------------+
| host                  | user | password                                  |
+-----------------------+------+-------------------------------------------+
| localhost             | root | *A4B6157319038724E3560894F7F932C8886EBFCF |
| localhost.localdomain | root | *E0FE93587BC753CDAE14ABE76FD3197B5B92EE43 |
| 127.0.0.1             | root | *E0FE93587BC753CDAE14ABE76FD3197B5B92EE43 |
| ::1                   | root | *E0FE93587BC753CDAE14ABE76FD3197B5B92EE43 |
+-----------------------+------+-------------------------------------------+
mysql> update user
    -> set password='1234'
    -> where user='root';
mysql> select host,user,password from user;
+-----------------------+------+----------+
| host            | user | password |
+-----------------------+------+----------+
| localhost         | root | 1234    |
| localhost.localdomain | root | 1234    |
| 127.0.0.1         | root | 1234    |
| ::1             | root | 1234    |
+-----------------------+------+----------+
mysql> grant all privileges on *.* to root@'%' identified by "1234";  #配置mysql允许远程登录
mysql> flush privileges;


7、关闭防火墙,不然可能远程连接会失败

     1)重启后生效 

开启: chkconfig iptables on
关闭: chkconfig iptables off

     2)立即生效

开启: service iptables start
关闭: service iptables stop

8、设置开机自动启动Mysql数据库

[root@localhost hadoop]# chkconfig mysql on;
[root@localhost hadoop]# chkconfig --list | grep -i mysql

9、Mysql的默认安装目录

/var/lib/mysql/               #数据库目录
/usr/share/mysql              #配置文件目录
/usr/bin                     #相关命令目录
/etc/init.d/mysql              #启动脚本