CentOS6.5 - yum对Mysql的安装与配置

时间:2021-01-07 13:20:53

一.mysql的安装

  1.查看是否安装mysql

  [root@localhost ~]# rpm -qa | grep mysql

  CentOS6.5 - yum对Mysql的安装与配置

  如果有进行卸载(以下三种方式选一种即可):

  1)rpm -e mysql-libs-5.1.-.el6.x86_64   //普通删除模式
  )rpm -e --nodeps mysql-libs-5.1.-.el6.x86_64 // 强力删除模式,如果使用上面命令1)删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除(推荐)
  )yum remove mysql-libs-5.1.-.el6.x86_64 //yum卸载

  我选择的第二种命令卸载

  CentOS6.5 - yum对Mysql的安装与配置

  2.进行安装 : yum -y install mysql-server

  [root@localhost database]# yum -y install mysql-server

  CentOS6.5 - yum对Mysql的安装与配置

  CentOS6.5 - yum对Mysql的安装与配置

二.mysql数据库的初始化及相关配置

  1.启动mysql服务:service mysqld start

  [root@localhost database]# service mysqld start

  CentOS6.5 - yum对Mysql的安装与配置

  2.尝试连接mysql:mysql

  [root@localhost database]# mysql

 CentOS6.5 - yum对Mysql的安装与配置

  3.停止:、\q

  CentOS6.5 - yum对Mysql的安装与配置

  4.设置mysql开机启动:chkconfig mysqld on

  [root@localhost database]# chkconfig mysqld on

  5.开启3306端口并保存

  /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT    /etc/rc.d/init.d/iptables save

  [root@localhost database]# /sbin/iptables -I INPUT -p tcp --dport  -j ACCEPT
  [root@localhost database]# /etc/rc.d/init.d/iptables save

  CentOS6.5 - yum对Mysql的安装与配置

   查看mysql是否是3306端口:netstat -anp

  [root@localhost database]# netstat -anp

  CentOS6.5 - yum对Mysql的安装与配置

  6.设置MySQL的root用户、密码

  [root@localhost database]# use mysql;
  mysql> set password for root@localhost=password('root');
  或者:
  /usr/bin/mysqladmin -u root password 'new-password'  // 为root账号设置密码

  CentOS6.5 - yum对Mysql的安装与配置

  7.设置Mysql远程访问 grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;

  mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
  mysql> FLUSH PRIVILEGES;

  CentOS6.5 - yum对Mysql的安装与配置

  安装完成喽!!!